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

module fifo_demo_chips
(
    input  logic       clk,
    input  logic       rst,
    input  logic       push,
    input  logic       pop,
    input  logic [2:0] data,
    output logic [2:0] head,
    output logic       dor,
    output logic       dir
);

    // Connections between the chips that are not ports

    wire si;
    wire so;

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

    wire gnd = 1'b0;

    // Outputs that go nowhere

    wire unused_u2_q3;
    wire unused_u1_q1_n;
    wire unused_u1_q2;

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

    // U2: CD74HC40105 FIFO of sixteen 4-bit words, pin 1 in column 7

    cd40105 i_u2
    (
        .oe  ( gnd          ),  // Pin 1 <- GND
        .dir ( dir          ),  // Pin 2 -> DIR
        .si  ( si           ),  // Pin 3 <- U1 pin 1 (Q1)
        .d0  ( data [0]     ),  // Pin 4 <- button D0
        .d1  ( data [1]     ),  // Pin 5 <- button D1
        .d2  ( data [2]     ),  // Pin 6 <- button D2
        .d3  ( gnd          ),  // Pin 7 <- GND
        .mr  ( rst          ),  // Pin 9 <- button RESET
        .q3  ( unused_u2_q3 ),  // Pin 10, unused output
        .q2  ( head [2]     ),  // Pin 11 -> Q2
        .q1  ( head [1]     ),  // Pin 12 -> Q1
        .q0  ( head [0]     ),  // Pin 13 -> Q0
        .dor ( dor          ),  // Pin 14 -> DOR
        .so  ( so           )   // Pin 15 <- U1 pin 12 (~Q2)
    );

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

    // U1: CD4013 dual D flip-flop with set and reset, pin 1 in column 17

    cd4013 i_u1
    (
        .q1     ( si             ),  // Pin 1 -> SI
        .q1_n   ( unused_u1_q1_n ),  // Pin 2, unused output
        .clock1 ( clk            ),  // Pin 3 <- 555 clock module
        .reset1 ( rst            ),  // Pin 4 <- button RESET
        .d1     ( push           ),  // Pin 5 <- button PUSH
        .set1   ( gnd            ),  // Pin 6 <- GND
        .set2   ( gnd            ),  // Pin 8 <- GND
        .d2     ( pop            ),  // Pin 9 <- button POP
        .reset2 ( rst            ),  // Pin 10 <- button RESET
        .clock2 ( clk            ),  // Pin 11 <- 555 clock module
        .q2_n   ( so             ),  // Pin 12 -> SO
        .q2     ( unused_u1_q2   )   // Pin 13, unused output
    );

endmodule
