All courses

Verilog · Lesson 92 of 93

Build and verify a one-entry ready/valid buffer

RTL Integration Lab

Write the transfer contract before the RTL

A transfer occurs only at a rising clock edge where valid and ready are both asserted. A producer must retain valid and data while stalled. A one-entry buffer can store one item, accept a new item when empty, and replace a consumed item on the same edge.

This exercise uses one clock, an active-high synchronous reset, and an 8-bit payload. It is not a clock-domain-crossing FIFO. At a reset edge the valid bit clears; output data is irrelevant while valid is zero. The surrounding system must suppress transfers while reset is asserted.

Start only after the ready/valid and sequential RTL chapters. Use the Verification & Testbenches chapter's checking techniques to automate the cases below.

Implement the buffer

Verilog
module elastic_register (
  input wire clk, rst,
  input wire [7:0] in_data,
  input wire in_valid,
  output wire in_ready,
  output wire [7:0] out_data,
  output wire out_valid,
  input wire out_ready
);
  reg full;
  reg [7:0] data_q;
  assign in_ready = !full || out_ready;
  assign out_valid = full;
  assign out_data = data_q;
  always @(posedge clk) begin
    if (rst) full <= 1'b0;
    else if (in_ready) begin
      full <= in_valid;
      if (in_valid) data_q <= in_data;
    end
  end
endmodule

There is no reset on data_q, so it can be X in simulation until the first accepted payload. Only check out_data when out_valid is asserted. If the register is full and out_ready is low, in_ready is low and neither full nor data_q changes. When the old item is consumed and a new valid item is present, it is replaced without an empty bubble.

This architecture has a combinational ready path. Chaining many stages can create a long timing path; a skid buffer or registered-ready architecture is a separate design with different storage requirements.

Check ordering, stalls, reset, and replacement

Create an expected-item queue in the testbench. At each rising edge, first compare/pop an accepted output, then append an accepted input. The order matters when both transfers occur on one edge. Drive new stimulus away from the sampling edge and account for nonblocking assignment updates.

Required cases:

  • Reset before any transfer; output valid must clear.
  • Accept one item into the empty buffer while the consumer is stalled.
  • Stall for several cycles; data and valid must stay unchanged.
  • Consume and replace on the same edge, then drain the final item.
  • Reset with an item pending; discard the expected item under the same contract.
  • Add a watchdog and deliberately corrupt one payload to prove the checker can fail.

Count accepted inputs and outputs and compare their difference with occupancy, accounting for resets that discard items. End the test only after draining; stopping with a pending item can hide a lost final transaction. Save the pass/fail log and a short waveform that shows at least one stall and one simultaneous transfer.

Further study and tool references

Check the language mode and supported features for your installed simulator.

Verilator language supportIcarus compiler flags