// Exercise M11c, 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 [9:0] q,
    output logic       red,
    output logic       yellow,
    output logic       green
);

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

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

    // Outputs that go nowhere

    wire unused_u2_k;

    // Ports that are the same wire as another port

    assign yellow = q [9];

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

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

    cd4017 i_u1
    (
        .q5            ( q [5] ),  // Pin 1 -> Q5
        .q1            ( q [1] ),  // Pin 2, not wired on the breadboard
        .q0            ( q [0] ),  // Pin 3, not wired on the breadboard
        .q2            ( q [2] ),  // Pin 4, not wired on the breadboard
        .q6            ( q [6] ),  // Pin 5 -> Q6
        .q7            ( q [7] ),  // Pin 6 -> Q7
        .q3            ( q [3] ),  // Pin 7, not wired on the breadboard
        .q8            ( q [8] ),  // Pin 9 -> Q8
        .q4            ( q [4] ),  // Pin 10, not wired on the breadboard
        .q9            ( q [9] ),  // Pin 11 -> Q9
        .carry_out     ( red   ),  // Pin 12 -> CO
        .clock_inhibit ( gnd   ),  // Pin 13 <- GND
        .clock         ( clk   ),  // Pin 14 <- 555 clock module
        .reset         ( rst   )   // Pin 15 <- reset button
    );

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

    // U2: CD4072 dual 4-input OR, pin 1 in column 26

    cd4072 i_u2
    (
        .j ( green       ),  // Pin 1 -> GREEN
        .a ( q [5]       ),  // Pin 2 <- U1 pin 1 (Q5)
        .b ( q [6]       ),  // Pin 3 <- U1 pin 5 (Q6)
        .c ( q [7]       ),  // Pin 4 <- U1 pin 6 (Q7)
        .d ( q [8]       ),  // Pin 5 <- U1 pin 9 (Q8)
        .e ( vdd         ),  // Pin 9 <- +5V, unused input
        .f ( vdd         ),  // Pin 10 <- +5V, unused input
        .g ( vdd         ),  // Pin 11 <- +5V, unused input
        .h ( vdd         ),  // Pin 12 <- +5V, unused input
        .k ( unused_u2_k )   // Pin 13, unused output
    );

endmodule
