Fix an asynchronous FIFO whose pointers cross through one flop instead of two, and deliver it with its checker.
Hardware context: Gray-pointer asynchronous FIFO with a declared reset and synchronization model. Combine digital fault detection with explicit CDC structure and reset-analysis obligations.
An asynchronous FIFO and its checker are delivered together. On a correct FIFO the checker stays silent. On this FIFO it reports flag errors, and the FIFO's own pins differ from the expected record too.
You submit both parts: the module digital_async_fifo and the function verify_cdc. The FIFO's pin record and the checker's report are each compared. So a checker cannot hide a broken FIFO.
The tests run the FIFO at depth 4 and depth 8, at several clock ratios, with pauses and resets. Some tests then plant one fault in the samples that the checker reads.
Find the bug and fix it. The FIFO rules and the checker 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 |
observation_fault | 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
function automatic string verify_cdc(input logic [4095:0] samples, input int aw, input bit check_visibility);
| 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.
| Bits of a sample | Holds |
|---|---|
| 0 | pre_full: full just before the edges of this event. |
| 1 | pre_empty: empty just before the edges. |
| 2 | write_edge: wclk rises in this event. |
| 3 | read_edge: rclk rises in this event. |
| 4 | reset: reset is high in this event. |
| 5 | write_en: the write request. |
| 6 | read_en: the read request. |
| 7 | write_accepted after the event. |
| 8 | read_valid after the event. |
| 16:9 | write_data: the byte offered for writing. |
| 24:17 | read_data after the event. |
| 25 | warmed: the write guard after the event. |
| 26 | rarmed: the read guard after the event. |
| 31:27 | Always 0. |
Event t sits in bits 32t + 31 down to 32t, so event 0 is in the lowest bits. There are always 128 events. aw is 2 for depth 4 or 3 for depth 8.
| Step | Rule for each event |
|---|---|
| Reset event | Add the waiting bytes to canceled and empty the queue. Clear both counts, both histories and both edge counters. Skip the edge rules; only the reset checks and the balance check apply. |
| Reset checks | Set bit 5 if write_accepted, read_valid, warmed or rarmed is 1. With check_visibility = 1, set bit 3 unless pre_full and pre_empty are both 1. |
| Flags | With check_visibility = 1, predict full and empty as in the next table. Set bit 3 if either pin differs. |
| Write receipt | On a write edge, write_accepted must equal write_en and not pre_full and an open write guard. Otherwise set bit 0. |
| Read receipt | On a read edge, read_valid must equal read_en and not pre_empty and an open read guard. Otherwise set bit 1. |
| Read | On a read edge with read_valid = 1, count the read. Pop the oldest waiting byte and set bit 2 if it differs from read_data. If nothing is waiting, set bit 4 and pop nothing. |
| Write | On a write edge with write_accepted = 1, count the write and push write_data. If depth bytes were already waiting, set bit 4 but still push. |
| Order | Retire the read before you add the write. A receipt counts only on its own edge, because it holds its value between edges. |
| Guards | After the edges, warmed must be 1 exactly when the write side has had two or more edges since reset. The same holds for rarmed. Otherwise set bit 5. |
| Balance | Writes must equal reads + canceled + waiting. Otherwise set bit 6. |
A guard is open when its side has had two or more edges since the last reset, counted before this event.
In this problem check_visibility is always 1, so the checker predicts the flags on every event.
| Visibility rule | Meaning |
|---|---|
| Counts | wcount and rcount count the accepted writes and reads since the last reset. |
| Histories | The write side keeps two history stages of rcount. The read side keeps two stages of wcount. |
| Shift | On a write edge, the second stage takes the first stage, and the first stage takes rcount from before this event. The read side does the same with wcount. |
| Edges together | When both clocks rise in one event, each side samples the other side's count from before the event. |
| full | full = 1 when the write side has had fewer than two edges since reset. It is also 1 when (wcount − second stage) modulo 2 × depth equals depth. |
| empty | empty = 1 when the read side has had fewer than two edges since reset. It is also 1 when rcount equals the second stage, modulo 2 × depth. |
Each event adds one entry to the report. It is the error mask as two hex digits, a colon, four decimal counts and a semicolon. The counts are writes, reads, canceled and waiting, separated by commas. For example, 04:4,1,0,3; is a data error after 4 writes and 1 read, with 3 bytes waiting. Writes, reads and canceled keep counting across resets.
| Planted fault | What changes in the samples |
|---|---|
| 0 | Nothing. The samples are clean. |
| 1 | Bit 7 of read_data is flipped on the first accepted read. |
| 2 | write_accepted is cleared on the first accepted write. |
| 3 | pre_full is flipped at event 7. |
| 4 | warmed is flipped at event 4. |
| 5 | read_valid is set on the first reset event. |
The checker sees only the pins. It never sees the FIFO's pointers or memory, so it keeps its own queue of waiting bytes.
The expected result is the FIFO transcript followed by the checker report, compared as one string. The result shows its length, the expected length and whether the two match.
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 Clean Run with a Fast Writer- Input
aw = 2, planted fault 0. The write clock rises every event, the read clock every third event. No reset after the start.
- Output
output_length = 3363, expected_length = 3363, match = yes
The read side sees each write two read edges late, so empty stays 1 at event 9 with 4 bytes stored. The checker predicts that lag and reports 00 on every event. All 25 bytes come out in order.
Example 2
Reset While the Read Clock Is Stopped- Input
aw = 2, planted fault 0. 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
output_length = 3285, expected_length = 3285, match = yes
Reset clears the read side at once, although its clock is stopped. The four waiting bytes are canceled, so the entry for event 21 is 00:4,0,4,0. The read guard opens at event 39.
Example 3
A Changed Read Byte- Input
The clean run of the first example, with planted fault 1.
- Output
output_length = 3363, expected_length = 3363, match = yes
The FIFO record is clean. Only the samples given to the checker change: the first read shows 0x36 instead of 0xb6. The checker entry for event 21 is 04:4,1,0,3.
Constraints and Contract
- Keep the module name, the parameter, the ports, the function name and its arguments.
- Model exactly two synchronizer stages in the FIFO and two history stages in the checker.
Hints
Hint 1
Read the checker report on a clean test. Which error bit does it set? Bit 3 means a flag did not match the two-stage model.
Hint 2
Each side must see the other side's pointer only after two of its own edges. Count the flops each Gray pointer passes through in the design.
Hint 3
Look at the lines that load rg2 and wg2. They load the second flop from the live Gray pointer. Load them from rg1 and wg1 instead.
What the grader checks: Both the FIFO pins and the checker report are compared, at depths 4 and 8, with pauses, resets and planted faults. Simulation has no metastability. A real design still needs a CDC review, reset checks, Gray bus skew limits and an MTBF target.
54 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