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 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.
| Rising edge | Inputs (hex) | Observed after edge (hex) |
|---|---|---|
| E0 | rst_n=0, in_valid=0, in_data=00, out_ready=0 | in_ready=1, out_valid=0, out_data=00 |
| E1 | rst_n=1, in_valid=1, in_data=31, out_ready=0 | in_ready=0, out_valid=1, out_data=31 |
| E2 | rst_n=1, in_valid=1, in_data=52, out_ready=0 | in_ready=0, out_valid=1, out_data=31 |
| E3 | rst_n=1, in_valid=1, in_data=52, out_ready=1 | in_ready=1, out_valid=1, out_data=52 |
| E4 | rst_n=1, in_valid=0, in_data=00, out_ready=1 | in_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
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)