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

module traffic_light_chips
(
    input  logic       clk,
    input  logic       rst,
    output logic [6:0] q,
    output logic       red,
    output logic       yellow,
    output logic       green
);

    // Connections between the chips that are not ports

    wire q7;
    wire red45;
    wire green01;

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

    wire gnd = 1'b0;

    // Outputs that go nowhere

    wire unused_u1_q8;
    wire unused_u1_q9;
    wire unused_u1_carry_out;

    // Ports that are the same wire as another port

    assign yellow = q [3];

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

    // U1: CD4017 decade counter with 10 decoded outputs, pin 1 in column 8

    cd4017 i_u1
    (
        .q5            ( q [5]               ),  // Pin 1 -> Q5
        .q1            ( q [1]               ),  // Pin 2 -> Q1
        .q0            ( q [0]               ),  // Pin 3 -> Q0
        .q2            ( q [2]               ),  // Pin 4 -> Q2
        .q6            ( q [6]               ),  // Pin 5 -> Q6
        .q7            ( q7                  ),  // Pin 6 -> Q7
        .q3            ( q [3]               ),  // Pin 7 -> Q3
        .q8            ( unused_u1_q8        ),  // Pin 9, unused output
        .q4            ( q [4]               ),  // Pin 10 -> Q4
        .q9            ( unused_u1_q9        ),  // Pin 11, unused output
        .carry_out     ( unused_u1_carry_out ),  // Pin 12, unused output
        .clock_inhibit ( gnd                 ),  // Pin 13 <- GND
        .clock         ( clk                 ),  // Pin 14 <- 555 clock module
        .reset         ( q7 | rst            )   // Pin 15 <- Q7, pin 6; | rst only here, as a power-on reset
    );

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

    // U2: CD4071 quad 2-input OR, pin 1 in column 17

    cd4071 i_u2
    (
        .a ( q [6]   ),  // Pin 1 <- U1 pin 5 (Q6)
        .b ( red45   ),  // Pin 2 <- U2 pin 4 (K)
        .j ( red     ),  // Pin 3 -> RED
        .k ( red45   ),  // Pin 4 -> Q4|Q5
        .c ( q [4]   ),  // Pin 5 <- U1 pin 10 (Q4)
        .d ( q [5]   ),  // Pin 6 <- U1 pin 1 (Q5)
        .e ( q [0]   ),  // Pin 8 <- U1 pin 3 (Q0)
        .f ( q [1]   ),  // Pin 9 <- U1 pin 2 (Q1)
        .l ( green01 ),  // Pin 10 -> Q0|Q1
        .m ( green   ),  // Pin 11 -> GREEN
        .g ( q [2]   ),  // Pin 12 <- U1 pin 4 (Q2)
        .h ( green01 )   // Pin 13 <- U2 pin 10 (L)
    );

endmodule
