// Exercise M10, chip-level version: the chips and wires of schematic 2 and
// of the breadboard.  Same ports as johnson_counter.sv.
//
// Generated by tools/bb_lib.py from the checked breadboard wire list;
// change the layout in tools/bb_m10.py, not this file.  Synthesizable.

module johnson_counter_chips
(
    input  logic       clk,
    input  logic       rst,
    output logic [4:0] q
);

    // Connections between the chips that are not ports

    wire fb;

    // The power rails of the breadboard, for tied-off inputs

    wire gnd = 1'b0;
    wire vdd = 1'b1;

    // Outputs that go nowhere

    wire unused_u1_q4b;
    wire unused_u1_q3b;
    wire unused_u1_q2b;
    wire unused_u2_h;
    wire unused_u2_i;
    wire unused_u2_j;
    wire unused_u2_k;
    wire unused_u2_l;

    //------------------------------------------------------------------------

    // U1: CD4015 dual 4-stage shift register, serial in, parallel out, pin 1 in column 7

    cd4015 i_u1
    (
        .clock_b ( clk           ),  // Pin 1 <- 555 clock module
        .q4b     ( unused_u1_q4b ),  // Pin 2, unused output
        .q3a     ( q [2]         ),  // Pin 3 -> Q3
        .q2a     ( q [1]         ),  // Pin 4 -> Q2
        .q1a     ( q [0]         ),  // Pin 5 -> Q1
        .reset_a ( rst           ),  // Pin 6 <- button RESET
        .data_a  ( fb            ),  // Pin 7 <- U2 pin 2 (G)
        .clock_a ( clk           ),  // Pin 9 <- 555 clock module
        .q4a     ( q [3]         ),  // Pin 10 -> Q4
        .q3b     ( unused_u1_q3b ),  // Pin 11, unused output
        .q2b     ( unused_u1_q2b ),  // Pin 12, unused output
        .q1b     ( q [4]         ),  // Pin 13 -> Q5
        .reset_b ( rst           ),  // Pin 14 <- button RESET
        .data_b  ( q [3]         )   // Pin 15 <- U1 pin 10 (Q4A)
    );

    //------------------------------------------------------------------------

    // U2: CD4069 hex inverter (six NOT gates), pin 1 in column 17

    cd4069 i_u2
    (
        .a ( q [4]       ),  // Pin 1 <- U1 pin 13 (Q1B)
        .g ( fb          ),  // Pin 2 -> ~Q5
        .b ( gnd         ),  // Pin 3 <- GND, unused input
        .h ( unused_u2_h ),  // Pin 4, unused output
        .c ( gnd         ),  // Pin 5 <- GND, unused input
        .i ( unused_u2_i ),  // Pin 6, unused output
        .j ( unused_u2_j ),  // Pin 8, unused output
        .d ( vdd         ),  // Pin 9 <- +5V, unused input
        .k ( unused_u2_k ),  // Pin 10, unused output
        .e ( vdd         ),  // Pin 11 <- +5V, unused input
        .l ( unused_u2_l ),  // Pin 12, unused output
        .f ( vdd         )   // Pin 13 <- +5V, unused input
    );

endmodule
