H1.4 FIFO-to-Stream Adapter

MediumFixVerilator · serverReview the topic

Fix an adapter that turns registered FIFO reads into a ready/valid stream, so a stall cannot lose data.

Hardware context: Clocked FIFO plus ready/valid output adapter. Hold registered FIFO read responses until the stream receiver accepts them.

A FIFO returns read data one edge after the read. A stream needs a value that stays put until the receiver takes it. This adapter connects the two, and it drops data when the receiver stalls.

The module submitted_adapter asks the FIFO for one entry at a time with read_request. It captures the response into a holding register and offers it on out_valid and out_data. The receiver takes the value on an edge where ready = 1.

The adapter has one holding register and room for one read in flight. It must not issue a read while a held value is stalled, because the next response would have nowhere to go. Find the bug and fix it.

The tests connect it to real FIFOs of depth 1, 3 and 5 for 32 edges. They drive writes, change ready and apply resets. They check the request and the stream before and after every edge.

Signals in the Timeline

SignalWidthRole
profile2input of each check
controls96input of each check
values256input of each check
Full specification
The ports (keep them)
module submitted_adapter #(parameter int FAULT = 0) (
  input  bit        clk, initialize, reset,
  input  wire       fifo_empty, fifo_read_valid,
  input  wire [31:0] fifo_read_data,
  input  bit        ready,
  output wire       read_request,
  output bit        out_valid,
  output bit [31:0] out_data);
  // your adapter
endmodule
Adapter ruleMeaning
One creditThe adapter has one holding register for the stream and room for one read in flight. It never has two reads in flight.
Issue a readread_request = !reset && !pending && (!out_valid || ready) && !fifo_empty, using values before the edge.
TimingA read accepted on edge k gives FIFO data after edge k. The adapter captures it on edge k+1. The stream can take it on edge k+2 at the earliest.
CaptureCapturing a FIFO response never waits for ready. pending clears when the response is captured.
StallWhile out_valid = 1 and ready = 0, out_valid and out_data hold their values exactly.
Hand overThe edge where the stream takes the held value may also issue the next read.
ResetReset cancels every stored entry, the read in flight and the held value. After the edge, out_valid = 0 and out_data = 0.

This adapter leaves gaps between values on purpose. It is a one-credit design, not one that moves a value every cycle.

Before a reset edge, an old out_valid may still show, but no transfer counts on that edge. After the reset, a new write must not be preceded by a cancelled value.

Data is 8 bits, zero-extended on 32-bit ports. Keep all 32 bits of the response.

The result has error_edges, with bit i set when edge i broke a rule. It counts accepted writes, issued reads, stream transfers, entries cancelled by reset, and entries still outstanding. Outstanding includes stored entries, the read in flight and the held value. A correct run has writes = transfers + cancelled + outstanding.

Examples

Example 1

One Write Crosses Both Registers
Input
Depth 1: write 0x11 on edge 0; ready is always 1; no later writes
Output
error_edges = {}, accepted_writes = 1, issued_reads = 1, transfers = 1, reset_cancelled = 0, outstanding = 0, depth = 1

The read issues on edge 1, the adapter captures 0x11 on edge 2, and the stream takes it on edge 3. One write, one read and one transfer, with nothing left over.

Example 2

A Held Value Blocks the Next Read
Input
Depth 3: write 0x21 on edge 0 and 0x22 on edge 1; ready is 0 through edge 6, then 1
Output
error_edges = {}, accepted_writes = 2, issued_reads = 2, transfers = 2, reset_cancelled = 0, outstanding = 0, depth = 3

The adapter captures 0x21 on edge 2 and holds it until edge 7. That edge also issues the next read. 0x22 is captured on edge 8 and taken on edge 9.

Example 3

Reset Cancels Held and Stored Entries
Input
Depth 5: write 0x31, 0x32, 0x33 on edges 0 to 2 with ready = 0; reset with write 0x99 on edge 3; write 0x41 on edge 4; ready = 1 from edge 4
Output
error_edges = {}, accepted_writes = 4, issued_reads = 2, transfers = 1, reset_cancelled = 3, outstanding = 0, depth = 5

At the reset one value is held and two are stored, so three are cancelled. The write of 0x99 is refused. Only 0x41 reaches the stream later.

Constraints and Contract

  • Never overwrite a stalled held value with a second response.
  • The adapter sees fifo_read_valid on the edge after the read, as nonblocking updates require.
  • Keep the module name, the parameter and the ports. FAULT is always 0.

Hints

Hint 1

Set pending when you issue a read. It reserves the holding register for the response that is coming.

Hint 2

Capture a FIFO response whether or not ready is 1. pending is free again after the capture.

Hint 3

Look at read_request. Can it be 1 while out_valid = 1 and ready = 0? Then the next response would overwrite the held value.

What the grader checks: The adapter drives real FIFOs of depth 1, 3 and 5. An independent model checks every request, every stream offer, the order and the counts. The tests require this one-credit schedule; a faster adapter would have different timing.

48 checks on Verilator · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 9 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

One Write Crosses Both Registers

Input
Depth 1: write 0x11 on edge 0; ready is always 1; no later writes
Expected output
error_edges = {}, accepted_writes = 1, issued_reads = 1, transfers = 1, reset_cancelled = 0, outstanding = 0, depth = 1

The read issues on edge 1, the adapter captures 0x11 on edge 2, and the stream takes it on edge 3. One write, one read and one transfer, with nothing left over.

Run samples executes all 3 public checks. Check all tests runs 48 checks on the server.

Verilator · server