Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Start Here6
    • Who This Course Is For
    • How the Lessons and Examples Work
    • Words You Will Meet
    • The Testbench Picture
    • The PacketFIFO Project
    • What the Open Simulators Run
  • SystemVerilog Language Foundations28
  • Object-Oriented SystemVerilog for Verification30
  • Constraint Randomization — Interview-Critical Deep Dive36
  • SystemVerilog Assertions — Interview-Critical Deep Dive40
  • Functional Coverage in SystemVerilog22
  • Testbench Architecture in SystemVerilog23
  • Advanced Language & Integration25
  • Senior & Interview Preparation21
  • Principal-Level Verification28
Loading lesson

‹Start Here
  1. Topics
  2. SystemVerilog
  3. Start Here
  4. The PacketFIFO Project

Part 0 · Start Here · Beginner

The PacketFIFO Project

The design you verify through the course: a valid/ready FIFO that carries small packets as bytes, its first runnable test, and the steps ahead.

On this page

    Why this matters

    Ideas stick when they are used on one design that grows. PacketFIFO is small enough to understand in a minute and rich enough to need every technique in the course.

    After this lesson you can: describe the PacketFIFO ports and packet format, run version 0, and say what each part of the course adds to it.

    What you will verify

    PacketFIFO is a small first-in first-out buffer with a valid/ready port on each side. A producer pushes bytes in, a consumer pulls them out in the same order, and nothing may be lost, duplicated or reordered.

    The bytes form packets. Each packet is a header byte, then len payload bytes, then a check byte. A ninth bit, last, marks the check byte so the consumer knows where the packet ends.

    The FIFO only moves bytes. Packets are a meaning the testbench gives those bytes, which is why the same FIFO grows into the course capstone.

    Field

    Bits

    Meaning

    kind

    header[7:6]

    0 DATA, 1 CTRL, 2 ERR

    dest

    header[5:4]

    Destination port, 0 to 3

    len

    header[3:0]

    Payload bytes that follow: 1 to 8 are legal; 0 and 9 to 15 are illegal

    check byte

    8 bits

    XOR of the header and every payload byte

    The handshake rule is the one from RTL: a byte moves on a clock edge where valid and ready are both 1. While ready is 0 the producer must hold the same byte.

    Version 0: one packet through

    The first version needs nothing beyond Verilog. The bench sends one packet, fills the 4-entry FIFO exactly, reads the bytes back and checks order, the last bit and the check byte.

    packet_fifo.v
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    // PacketFIFO v0: a valid/ready FIFO of 9-bit entries {last, byte}.
    module packet_fifo #(
      parameter WIDTH = 9,
      parameter DEPTH = 4,
      parameter AW    = 2
    ) (
      input  wire             clk,
      input  wire             rst_n,
      input  wire             in_valid,
      output wire             in_ready,
      input  wire [WIDTH-1:0] in_data,
      output wire             out_valid,
      input  wire             out_ready,
      output wire [WIDTH-1:0] out_data
    );
      reg [WIDTH-1:0] mem [0:DEPTH-1];
      reg [AW-1:0]    wptr, rptr;
      reg [AW:0]      count;
      wire push = in_valid && in_ready;
      wire pop  = out_valid && out_ready;
    
      assign in_ready  = (count != DEPTH);
      assign out_valid = (count != 0);
      assign out_data  = mem[rptr];
    
      always @(posedge clk or negedge rst_n)
        if (!rst_n) begin
          wptr  <= 0;
          rptr  <= 0;
          count <= 0;
        end else begin
          if (push) begin
            mem[wptr] <= in_data;
            wptr <= wptr + 1'b1;
          end
          if (pop) rptr <= rptr + 1'b1;
          case ({push, pop})
            2'b10:   count <= count + 1'b1;
            2'b01:   count <= count - 1'b1;
            default: count <= count;
          endcase
        end
    endmodule
    
    Terminal
    PASS: packet 22 a5 3c bb came out in order, last on the check byte, XOR 00
    Predict first The header is 8'h22, and the payload is A5 and 3C. What is the check byte?

    8'hBB. 22 XOR A5 is 87, and 87 XOR 3C is BB. XOR-ing all four bytes then gives 00, which is what the bench checks at the end.

    Terminal
    PASS: packet 22 a5 3c bb came out in order, last on the check byte, XOR 00

    Version 0 checks one packet, written by hand. The rest of the course replaces each hand-written piece with something that scales.

    The steps ahead

    Part

    What you add to PacketFIFO

    1 · Foundations

    A packed struct and enum for the header, a queue as the expected-byte model, an interface for the two ports

    2 · OOP

    A pkt_txn class with print, compare and copy; a generator and driver that pass packets through a mailbox

    3 · Randomization

    Random legal packets, then deliberately illegal ones (length 0, bad check byte)

    4 · Assertions

    Valid/ready rules on both ports, no overflow, no underflow

    5 · Coverage

    Bins for kind, dest and length, including the illegal lengths

    6 · Advanced

    A bind file that attaches the checkers without editing the RTL

    7 · Testbench

    A complete class testbench with monitors and a scoreboard

    8 · Senior

    The capstone: plan, regression and sign-off, with a planted bug to find

    Each step is a short Project step box at the end of the lesson it belongs to. The steps are optional: every lesson makes sense without them.

    Check yourself Why does the FIFO store a last bit next to each byte instead of storing whole packets?

    It keeps the RTL a plain byte FIFO that knows nothing about packets. The packet format lives in the testbench, so the same FIFO can be checked with any format, and it grows into the course capstone unchanged.

    Check yourself The consumer drops out_ready for three cycles in the middle of a packet. What must the FIFO do?

    Keep out_valid high and keep the same byte on out_data until a cycle where out_ready is 1. Nothing is lost, and the byte is not repeated.

    Remember

    • A byte moves on a clock edge where valid and ready are both 1.

    • A packet is a header (kind, dest, len), len payload bytes and a check byte marked last.

    • The check byte is the XOR of the bytes before it, so a whole packet XORs to 0.

    Rule of thumb: the FIFO moves bytes; the testbench gives them meaning.

    How this was checked

    Run with Icarus Verilog 13 (iverilog -g2012) and Verilator 5.048 (--binary --timing) on 2026-10-18; both printed the PASS line shown, with no warnings.

    Version 0 checks one hand-written packet that exactly fills a depth-4 FIFO. It does not test back-pressure, simultaneous push and pop, reset in the middle of traffic or illegal packets; later parts add those.

    Related topics

    • Next: What the Open Simulators Run

    • Valid/ready in the RTL course

    Previous

    5 / 259

    Next: What the Open Simulators Run

    Up next

    Up nextWhat the Open Simulators Run

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Who This Course Is For
    • How the Lessons and Examples Work
    • Words You Will Meet