RTL Foundations / F11

Valid/Ready: Where Does the Result Wait During a Stall?

Build a one-entry result buffer and trace a three-cycle stall, simultaneous send and receive, and reset cancellation.

Lesson film

Film chapters

TranscriptCaptionsDownload film

The F10 collector enters REPORT after the fourth sample. Where can a finished report wait while the receiver is busy? We’ll test the result buffer on its own. The testbench supplies two finished results, 31 and 52, directly so it can test consecutive offers without a second round of sensor sampling. The receiver stalls for three cycles with 31 in the slot and 52 at the input. Which result should go out first when it can take one again?

Which edge counts as a transfer?

Both sides of this valid/ready interface use the same clock. The source asserts valid when it has data to offer. The receiver asserts ready when it has room to take a result at that edge. A transfer happens on a rising edge where valid && ready is true. We call it a fire. The buffer has one interface at each end, so we track in_fire and out_fire separately. All payload values in the lesson are hexadecimal.

The source can assert valid as soon as its result is ready. If the receiver leaves ready low on that edge, the source keeps both valid and the same payload on the interface until a fire or a reset that both sides accept. A receiver can assert ready early, or its design can wait to see valid. If the source also waits for the receiver to act first, the two sides can wait indefinitely.

The source offers 52, the one-entry buffer retains 31, and the receiver stalls. Data and valid flow downstream, while ready travels upstream.
The buffer owns 31 until the receiver takes it. The source still owns the unaccepted 52.

A four-phase req/ack interface follows a different sequence. The source raises req and holds its payload. The receiver raises ack after accepting it. Then req and ack return low in that order before the next request. With our synchronous valid/ready interface, two successive rising edges can each transfer a word if both signals stay high. In both protocols, the two sides need a shared rule for when the data is valid and who holds it until acceptance.

How does one slot make room for the next result?

In result_buffer.sv, full_q marks the slot as occupied, and data_q holds the eight-bit payload. This buffer has a registered output. When the slot is empty, it can accept an input. That input must enter the register before a later edge can deliver it. When the slot is full, it can accept a new input on the edge that sends the old result downstream.

Before the edgeout_readyCan accept input?What happens
EmptyEitherYesStore the input if it is valid. There is no output transfer at this edge.
Full0NoKeep full_q and data_q.
Full1YesSend the old result. Save a valid input in its place, or empty the slot.
assign out_valid = rst_ni && full_q;
assign out_data  = data_q;
assign in_ready  = rst_ni && (!full_q || out_ready);
assign in_fire   = in_valid && in_ready;
assign out_fire  = out_valid && out_ready;

always_ff @(posedge clk_i) begin
    if (!rst_ni) begin
        full_q <= 1'b0;
        data_q <= 8'h00;
    end else begin
        if (in_fire)
            data_q <= in_data;

        if (in_fire)
            full_q <= 1'b1;
        else if (out_fire)
            full_q <= 1'b0;
    end
end

When both transfers happen, in_fire sets the next full_q. The old result leaves, and the new one occupies the same slot. An output transfer clears the slot only if no input takes its place. With out_valid=0, the bits on out_data may still show the last stored value. The validity flag tells the receiver whether that value can be delivered.

Where do the two results wait during the stall?

At E1, the empty buffer accepts A (31). The output has nothing to transfer yet. At E2, E3 and E4 the receiver holds out_ready=0, so A stays in the slot. The source offers B (52) across those edges. With in_ready=0, it must keep B on offer.

The recorded VCD shows out_ready low and out_valid high at E2 through E4. The held result is 31. It changes to 52 after E5.
The shaded area marks E2 through E4 in the Icarus Verilog trace. Read the level just left of a sampling line to see whether that edge transfers data.
EdgeDownstream readyInput acceptedOutput deliveredSlot after the update
E1131none31
E2–E40nonenone31
E51523152
E61none52Empty

E5 takes some care. At 55 ns the receiver samples out_data=31, while the buffer samples in_data=52. The nonblocking assignments from F08 take effect after those reads. Only then does data_q become 52. If the testbench uses that updated value in its E5 delivery record, it will report that the receiver took 52. Our test logs the fires and their payloads at the edge, then waits 1 ns to observe the updated slot.

At E5, the receiver takes 31 and the buffer accepts 52. After the NBA update the buffer holds 52 and full_q stays high.
The E5 transfer record contains 31. The buffer holds 52 after the update.

What can this stall reveal?

In the overwrite version, in_valid controls the data write. At E2, B is on offer but the buffer has no space for it. The faulty design writes 52 anyway and overwrites the waiting 31. At E5, the receiver takes 52 and the first result is lost.

In the pulse version, out_valid lasts for one cycle after an input fire. A is valid at the start of E2. There is no input transfer on E2, so the update drops out_valid even though the receiver is stalled. At E5, the receiver is finally ready but cannot accept A. The data was stored, yet the interface lost its opportunity to deliver it.

At E5, the correct design transfers 31, the overwrite fault transfers 52 and the pulse fault transfers nothing. After E2, the faults change the payload and withdraw valid, respectively.
All three designs see the same stall. Compare the state just after E2 with what the receiver can take at E5.

When you connect modules, also trace their combinational dependencies. Here out_valid comes from the stored full_q and reset. There is no path back to that output from out_ready. The input side does use out_ready to calculate whether it will have space. Follow those combinational paths across module boundaries. A path that eventually feeds back to its starting point creates a combinational loop.

Does the pending result survive reset?

This interface cancels undelivered results on reset. The buffer accepts C (73) at E7. At E8, rst_ni is low and the receiver is ready. Reset gates off out_valid and in_ready, so neither interface transfers a word at E8. The rising edge clears the registers. The test also discards C from its pending expectations and starts a new epoch. At E9 the buffer accepts D (94), and at E10 the receiver takes it. A system that must resend after reset needs a shared recovery rule for the source and receiver.

Back in F09, sample_take belongs at the sensor input. Drive it from that interface’s sample_valid && sample_ready so the count advances on accepted samples. An FSM that drives the receiver directly uses the receiver’s out_fire as report_taken and then leaves REPORT. If the FSM hands the report to this buffer, use the buffer’s in_fire as the FSM’s report_taken. The buffer now owns that report. External delivery still happens at out_fire. Log both handoffs so F12 can check them word by word.

Replay the transfer record

Extract the lab package on Linux or WSL and run bash run.sh. The test records 11 rising edges. The main design accepts four words, delivers three and cancels one on reset. The test also checks the two faulty versions at E5. Yosys runs generic synthesis and connectivity checks for all three versions. See the run summary, raw VCD and replay evidence.

Transfer exercise — What could an always-ready receiver hide?

Keep A and B, and have the source advance only after in_fire. Hold out_ready high. Could the two faulty designs produce the correct sequence? How would you change the test to tell them apart?

Answer

Yes. The receiver can take a valid result on every edge. The slot can accept a new input on the same edge, so there may be no blocked input to trigger the overwrite. A one-cycle pulse can also succeed if the receiver is always ready. First accept A, then hold ready low for three edges while offering B continuously. A must be the first word delivered when ready returns. Inspect valid and data across the stalled edges to distinguish an overwrite from a premature drop in valid.

Trace one word through a stall

The source offers hexadecimal 31, 52, 73 and 94. Change out_ready before a rising edge. On a simultaneous handoff, compare what the receiver gets with what stays in the buffer. E8 defaults to a synchronous reset.

edgereadyInput firedOutput firedBuffer after

Download RTL, testbench and results

Check your understanding

1. The slot is empty at E1. in_valid and out_ready are high, and the input is 31. What happens?
2. At E4 the slot holds 31. The source offers 52 and downstream ready is low. Who holds each word?
3. Ready returns at E5. The input offers 52 and the slot held 31. What goes in the output record and what is in the slot after NBA?
4. At reset E8, ready is high and 73 is pending. The next epoch offers 94. Which word is delivered?
5. Why might the overwrite and one-cycle valid faults both pass with ready held high?