Single-entry buffer

When the receiver stalls, trace how a valid/ready interface holds one word until transfer. Then check how the stored word and its valid flag update when an old word leaves and a new word arrives on the same edge.

A sensor has handed over hex 31, but the receiver is busy. One storage slot allows the input and output handshakes to finish on different rising edges.

The slot is ready when empty or the sink is ready. A full slot can replace its word.
The slot is ready when empty or the sink is ready. A full slot can replace its word.

The RTL

The full bit records whether the slot contains an offer. An empty slot is ready to accept a byte. When a full slot stalls, out_valid stays high and the stored byte stays on out_data. A transfer uses valid and ready sampled together at the edge.

module word_buffer(
    input logic clk,
    input logic rst_n,
    input logic in_valid,
    input logic [7:0] in_data,
    input logic out_ready,
    output logic in_ready,
    output logic out_valid,
    output logic [7:0] out_data
);
logic full;
    logic [7:0] saved;
    assign in_ready = !full || out_ready;
    assign out_valid = full;
    assign out_data = full ? saved : 8'h00;

    always_ff @(posedge clk) begin
        if (!rst_n) begin
            full <= 1'b0;
        end else if (in_ready) begin
            full <= in_valid;
            if (in_valid) saved <= in_data;
        end
    end
endmodule

Trace the outputs

With 31 stored, the source offers 52. While the receiver stalls, 31 stays put and the source keeps offering 52. Once out_ready rises, one edge can transfer 31 and accept 52. The post-edge value 52 is the next offer.

Recorded simulation. Dashed lines mark rising edges; bus values are hexadecimal. Open the figure to enlarge it.
Recorded simulation. Dashed lines mark rising edges; bus values are hexadecimal. Open the figure to enlarge it.
Rising edgeInputs (hex)Observed after edge (hex)
E0rst_n=0, in_valid=0, in_data=00, out_ready=0in_ready=1, out_valid=0, out_data=00
E1rst_n=1, in_valid=1, in_data=31, out_ready=0in_ready=0, out_valid=1, out_data=31
E2rst_n=1, in_valid=1, in_data=52, out_ready=0in_ready=0, out_valid=1, out_data=31
E3rst_n=1, in_valid=1, in_data=52, out_ready=1in_ready=1, out_valid=1, out_data=52
E4rst_n=1, in_valid=0, in_data=00, out_ready=1in_ready=1, out_valid=0, out_data=00

Design choices

When both ends can transfer on every cycle, the slot can replace its word every cycle. A simpler ready signal that checks only for an empty slot adds a gap after each full-slot transfer.

Yosys synth_ice40 mapped this module to the following cell counts: SB_DFFE: 8, SB_DFFESR: 1, SB_LUT4: 12. The download records the tool versions and the commands to reproduce this mapping.

Interactive lab

Clear the slot, accept 31 and stall the receiver. Offer 52, then raise out_ready and inspect the word before and after the edge.

in_ready
out_valid
out_data
Show the last eight observations

    Teaching film

    Read the transcript

    Run the RTL yourself

    Extract the lab and follow the commands in its README. Compare the simulated outputs and waveform with your predictions from the interactive lab.

    Download Single-entry buffer RTL (.zip)

    Check your understanding

    1. With an empty slot and a stalled receiver, what is in_ready?
    2. Which word remains during a stall in a full slot?
    3. The full slot holds 31 and the source offers 52. Both handshakes fire. Which byte leaves?
    4. What is out_data after the replacement?
    5. With out_valid low and out_data 00, did the receiver get a zero byte?