Fix an asynchronous FIFO whose read side waits for a clock edge before it obeys reset.
Hardware context: Gray-pointer asynchronous FIFO with a declared reset and synchronization model. Verify the specified cross-domain reset/flush sequence and traffic recovery.
A system flushes its asynchronous FIFO with one shared reset. One flush came while the read clock was stopped, and the read side ignored it until the clock came back. The power-on reset pulse has no clock edges at all, so the read side never started clean.
The module digital_async_fifo is a byte FIFO of depth 4 (AW = 2) or depth 8 (AW = 3). Each side keeps a binary pointer and sends a Gray copy through two flops of the other clock. Each side also has a reset guard that opens after two of its own edges.
The tests drive 128 events at different clock ratios. In an event, the write clock, the read clock, both or neither may rise. Some tests stop one clock for a while and reset during the pause. Every pin is compared before and after every event.
Find the bug and fix it. The full rules are in the specification.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
address_bits | 3 | input of each check |
reset_events | 3 | input of each check |
Full specification
module digital_async_fifo #(parameter int AW = 2) (
input logic wclk, rclk, reset, write_en, read_en,
input logic [7:0] write_data,
output wire full, empty, warmed, rarmed,
output logic write_accepted, read_valid,
output logic [7:0] read_data);
// your FIFO
endmodule
| Part | How this FIFO works |
|---|---|
| Size | Depth 4 (AW = 2) or depth 8 (AW = 3). Each entry is one byte. |
| Pointers | Each side counts in binary with one extra wrap bit. A pointer runs from 0 to 2 × depth − 1. |
| Crossing | Each side sends a Gray copy of its pointer. The other side catches it in two flops of its own clock. |
| Flags | full compares the write pointer with the read pointer after both flops. empty compares the read pointer with the write pointer after both flops. |
| Admission | A request is accepted on an edge only when the flag before that edge allows it. There is no look-ahead. |
| Edges together | When both clocks rise in one event, each side samples the other side's pointer from before the event. |
| Simulation | The flops have no metastability here. Each flop simply delays a value by one edge of its clock. |
| Reset rule | Meaning |
|---|---|
| Assert | One shared reset clears both sides at once, even while a clock is stopped. It does not wait for an edge. |
| Release guard | Each side has a guard. After reset falls, the guard opens after two rising edges of that side's own clock. |
| Before release | While its guard is closed, the write side shows full = 1 and the read side shows empty = 1. |
| Traffic | The tests offer no new requests until both guards are open. |
| Flush | Reset throws away every unread byte. A thrown-away byte must never come out later. |
| Design rule | Meaning |
|---|---|
| Pointers | wb and rb count in binary with AW + 1 bits. Each side sends its Gray copy, b ^ (b >> 1), to the other side. |
| Synchronizers | Each side loads the other side's Gray pointer into two flops of its own clock, one after the other. |
| full | full = 1 when warmed = 0. It is also 1 when the write Gray pointer equals the synchronized read Gray pointer with its top two bits inverted. |
| empty | empty = 1 when rarmed = 0. It is also 1 when the read Gray pointer equals the synchronized write Gray pointer. |
| Guards | Each side has a 2-bit shift register that shifts in a 1 on each of its own edges. warmed and rarmed are bit 1 of each. |
| Write | On a wclk edge with write_en = 1 and full = 0, store write_data at the write address and step wb. |
| Read | On an rclk edge with read_en = 1 and empty = 0, load read_data from the read address and step rb. |
| Receipts | write_accepted and read_valid are 1 after an edge of their side that accepted, and 0 after one that did not. With no edge on their side, they hold. |
| Reset | Asynchronous and active high on both sides. It clears the pointers, all four synchronizer flops, the guards, both receipts and read_data. |
In each event the tests apply reset and the requests 1 ns before the edges. They read the flags just before the edges and every pin just after them. A reset event clears everything even when no clock rises in it.
Each event adds one record to a text transcript. It holds the two flags before the edges, both receipts, read_data in hex, and full, empty, warmed and rarmed after the edges. The whole transcript is compared with the expected one.
The memory does not need clearing on reset. The pointers and receipts are what keep a thrown-away byte from coming out.
Simulation checks logic only. A real design also needs a CDC review of both synchronizer chains and reset recovery and removal checks. It also needs skew limits on the Gray buses and an MTBF target.
Examples
Example 1
A Fast Writer and a Slow Reader- Input
AW = 2. The write clock rises every event, the read clock every third event. No reset after the start.
- Output
transcript_length = 1792, expected_length = 1792, match = yes
The write guard opens at event 1 and the read guard at event 3. The first write is at event 4, but empty stays 1 until the read edge of event 9. The write pointer needs two read edges to cross. All 25 bytes come out in order.
Example 2
Reset While the Read Clock Is Stopped- Input
AW = 2. Write clock every event, read clock every third. The read clock stops for events 20 to 34 and the write clock for 40 to 59. Reset at event 21.
- Output
transcript_length = 1792, expected_length = 1792, match = yes
Four bytes are waiting when reset comes, and the read clock is stopped. Reset must still clear the read side at once, so both guards read 0 after event 21. The read guard opens at event 39, after two new read edges.
Example 3
A Reset with Nothing Waiting- Input
AW = 2. Write clock every second event, read clock every third. The same two pauses, and reset at event 47.
- Output
transcript_length = 1792, expected_length = 1792, match = yes
All four bytes were read before the reset, so nothing is thrown away. After reset, each side waits for two of its own edges. New writes start once both guards are open, and all 8 come out in order.
Constraints and Contract
- Keep reset asynchronous on both sides, and keep the release synchronous to each side's own clock.
- Keep the module name, the parameter and the ports.
Hints
Hint 1
Think about the reset pulse at the very start of each test. No clock rises during it. Which registers must it still clear?
Hint 2
A reset that waits for a clock edge is synchronous. The rules ask for an asynchronous reset on both sides. Compare how the two always blocks start.
Hint 3
The read-side block is triggered only by posedge rclk. Add posedge reset to its event list, as the write side does.
What the grader checks: The tests run real two-clock RTL through 27 schedules, at depths 4 and 8. They use three clock ratios, stopped clocks and resets at four points. Every pin record is compared. Simulation cannot show metastability, so CDC, reset and timing reviews are still needed.
27 checks on Icarus · browser samples / server checks. 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 8 steps and the final capstone