// Exercise M11d, 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 counter_reset;

    // 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         ( counter_reset       )   // Pin 15 <- U2 pin 9 (J)
    );

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

    // U2: CD4075 triple 3-input OR, pin 1 in column 17

    cd4075 i_u2
    (
        .c ( gnd           ),  // Pin 1 <- GND
        .b ( q7            ),  // Pin 2 <- U1 pin 6 (Q7)
        .f ( q [2]         ),  // Pin 3 <- U1 pin 4 (Q2)
        .e ( q [0]         ),  // Pin 4 <- U1 pin 3 (Q0)
        .d ( q [1]         ),  // Pin 5 <- U1 pin 2 (Q1)
        .k ( green         ),  // Pin 6 -> GREEN
        .a ( rst           ),  // Pin 8 <- reset button
        .j ( counter_reset ),  // Pin 9 -> RESET
        .l ( red           ),  // Pin 10 -> RED
        .i ( q [5]         ),  // Pin 11 <- U1 pin 1 (Q5)
        .h ( q [6]         ),  // Pin 12 <- U1 pin 5 (Q6)
        .g ( q [4]         )   // Pin 13 <- U1 pin 10 (Q4)
    );

endmodule
