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

module up_down_counter_chips
(
    input  logic       clk,
    input  logic       rst,
    input  logic       up,
    input  logic       binary,
    output logic [3:0] q,
    output logic       carry_out_n
);

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

    wire gnd = 1'b0;

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

    // U1: CD4029 presettable up/down counter, binary or decade, pin 1 in column 18

    cd4029 i_u1
    (
        .preset_enable ( rst         ),  // Pin 1 <- reset button
        .q4            ( q [3]       ),  // Pin 2 -> Q4
        .jam4          ( gnd         ),  // Pin 3 <- GND
        .jam1          ( gnd         ),  // Pin 4 <- GND
        .carry_in_n    ( gnd         ),  // Pin 5 <- GND
        .q1            ( q [0]       ),  // Pin 6 -> Q1
        .carry_out_n   ( carry_out_n ),  // Pin 7 -> ~CO
        .binary_decade ( binary      ),  // Pin 9 <- BIN wire, at GND on the breadboard
        .up_down       ( up          ),  // Pin 10 <- UP wire, at +5V on the breadboard
        .q2            ( q [1]       ),  // Pin 11 -> Q2
        .jam2          ( gnd         ),  // Pin 12 <- GND
        .jam3          ( gnd         ),  // Pin 13 <- GND
        .q3            ( q [2]       ),  // Pin 14 -> Q3
        .clock         ( clk         )   // Pin 15 <- 555 clock module
    );

endmodule
