Fix the two bugs in a full AXI memory campaign: one in the write observer and one in the memory checker.
Hardware context: AXI4 burst engine using an explicitly limited protocol subset. Qualify the burst engine against channel-stall, beat-loss, response-order and reset defects.
This is the whole checking side of a small AXI memory system. A write engine and a read engine share one memory. write_observer checks the write channels. memory_read_checker and memory_read_expectation check memory and reads.
On correct engines, the campaign reports false errors in two kinds of test. One kind has a burst with a wrong WLAST. The other has a reset in the middle of traffic.
The tests run real engines, correct and faulty, on one memory. They compare both reports with the expected reports, character by character.
There are two bugs, one in each checker. Find both and fix them.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
fault | 4 | input of each check |
naddresses | 3 | input of each check |
nbeats | 5 | input of each check |
descriptors | 128 | input of each check |
beats0 | 256 | input of each check |
beats1 | 256 | input of each check |
beats2 | 128 | input of each check |
address_release | 32 | input of each check |
data_release | 128 | input of each check |
ready_calendar | 64 | input of each check |
reset_cycle | 8 | input of each check |
restart_aw | 3 | input of each check |
restart_w | 5 | input of each check |
read_fault | 2 | input of each check |
Full specification
class write_observer;
function new();
function void sample(input int cycle, input bit resetn,
awvalid, awready, input bit [1:0] awid, input bit [15:0] awaddr, input bit [1:0] awlen, awburst,
input bit wvalid, wready, input bit [31:0] wdata, input bit [3:0] wstrb, input bit wlast,
bready, bvalid, input bit [1:0] bid, bresp,
input bit commit_valid, input bit [1:0] commit_id, input bit [15:0] commit_addr,
input bit [31:0] commit_data, input bit [3:0] commit_strb, input bit commit_last, input bit [1:0] commit_resp);
function bit [79:0] finish(); // {error_cycles[63:0], accepted_aw[7:0], accepted_w[7:0]}
function bit [79:0] rendezvous(); // {error_cycles[63:0], error_kinds[7:0], pending_aw[3:0], pending_w[3:0]}
endclass
class memory_read_expectation;
function new(input bit [1:0] id, input bit [15:0] address, input bit [1:0] length, burst,
input bit [127:0] words); // word j of the burst in bits 32*j+31 : 32*j
endclass
class memory_read_checker;
bit [7:0] memory_bytes[8192];
function new();
function void sample(input int cycle, input bit resetn,
arvalid, arready, input bit [1:0] arid, input bit [15:0] araddr, input bit [1:0] arlen, arburst,
rvalid, rready, input bit [1:0] rid, rresp, input bit [31:0] rdata, input bit rlast);
function void write_edge(input write_observer writer);
function bit [79:0] finish(); // {error_cycles[63:0], error_kinds[7:0], pending_reads[7:0]}
endclass
| AXI rule | Meaning |
|---|---|
| Handshake | A transfer happens on a rising edge where VALID and READY are both 1. |
| Stall | A sender that is not yet taken keeps VALID and its payload unchanged. |
| Write data order | AW and W are separate channels. In AXI4, W beats follow the order of the addresses and carry no ID. |
| Response order | Responses with the same ID come back in request order. Different IDs may come back in any order. |
| This design | Choice |
|---|---|
| Bus | 16-bit addresses, 32-bit data, four byte strobes and 2-bit IDs. |
| Bursts | Full-word, aligned bursts. FIXED and INCR have 1 to 4 beats. WRAP has 2 or 4 beats. A burst stays inside one 4 KiB page. |
| Map | Addresses 0x0000 to 0x1fff are memory. Any other address completes with DECERR (3). |
| Responses | OKAY is 0, SLVERR is 2 and DECERR is 3. EXOKAY is not used. |
| Left out | Narrow or unaligned transfers, longer bursts, exclusive access, cache, QoS, protection and user fields. |
| Burst | Address of beat i |
|---|---|
| FIXED (0) | The start address on every beat. |
| INCR (1) | start + 4 × i. |
| WRAP (2) | The window is beats × 4 bytes, aligned to its own size. Add 4 per beat and wrap to the window start at its end. |
| Write engine rule | Meaning |
|---|---|
| Buffers | Two AW descriptors, four W beats and two B responses. |
| Ready | AWREADY = 1 when fewer than 2 descriptors are stored before the edge. WREADY = 1 when fewer than 4 beats are stored. |
| Early data | A W beat accepted before its address waits in the W buffer. |
| Join | From the next edge on, each edge may use one beat: the oldest W beat with the oldest descriptor. |
| Burst end | A descriptor stays until its declared last beat, AWLEN + 1 beats in all. WLAST does not end a burst. |
| B space | The last beat of a burst waits while the B buffer was full before the edge. A B handshake on that edge does not help. |
| Commit | After the edge that uses a beat, commit_valid = 1 and the commit fields describe it. commit_last marks the declared last beat. |
| Status | DECERR for an unmapped address. Otherwise SLVERR once any beat of the burst had a wrong WLAST. Otherwise OKAY. |
| B | One response per burst. BVALID shows the oldest stored response from the edge after the last beat. |
| Reset | resetn is active low. It empties every buffer and clears all valid outputs. |
A wrong WLAST is a test of this design only. A correct AXI manager never sends one. This design still uses exactly AWLEN + 1 beats and reports SLVERR once. That recovery is a choice of this design, not an AXI rule.
| Step in sample() | What it does |
|---|---|
| Reset edge | Empty all three queues. Clear the beat count, the sticky WLAST error and the stalled B record. Check that the ready outputs, BVALID and commit_valid are 0. |
| Ready | AWREADY must equal (fewer than 2 addresses stored). WREADY must equal (fewer than 4 beats stored). Use the queues before this edge. |
| B offer | BVALID must equal (a response is expected). BID and BRESP must match the oldest expected response, even while BREADY is 0. |
| Stalled B | If the last edge had BVALID = 1 and BREADY = 0, this edge must show the same BID and BRESP with BVALID = 1. |
| Predict | From the queues before this edge, decide whether a beat is used, as the engine rules say. |
| Commit | commit_valid must equal that decision. A used beat must match in ID, address, data, strobes, last and status. |
| Retire | Pop the oldest expected response on a real B handshake. A used last beat adds one expected response. |
| Append | Last, add the AW and W beats accepted on this edge. They count as handshakes even when a faulty engine should not have accepted them. |
| Memory rule | Meaning |
|---|---|
| Start | 8192 bytes. The byte at address a starts as ((17 × a) XOR 0x5a) & 0xff. |
| Write | A commit with OKAY changes only its enabled byte lanes, after the edge. SLVERR and DECERR commits change nothing. |
| Partial burst | Earlier OKAY beats of a burst stay written even when a later beat fails. |
| Read | The edge that accepts AR takes a snapshot of every beat of the burst, from memory before that edge. |
| Same edge | An AR and a write commit on the same edge: the read sees the old bytes. |
| Late beats | R beats may come much later. They still carry the snapshot, not the current memory. |
| Reset | Reset cancels every read, write and response in flight. Bytes already written stay. |
| Each edge | What happens |
|---|---|
| 1 | The tests call sample() with the AR and R channels before the edge. |
| 2 | They call write_edge(writer). It applies the next predicted write to memory_bytes, from the write observer's queues before the edge. |
| 3 | The clock rises. The real engines move, and real OKAY commits change the real memory. |
| 4 | The write observer samples the write channels. |
| Step in sample() | What it does |
|---|---|
| Reset edge | Empty every queue and clear the stall record. ARREADY and RVALID must be 0. |
| AR credit | ARREADY must equal (fewer than 4 bursts outstanding before the edge). |
| Hold | After an edge with RVALID = 1 and RREADY = 0, the beat must stay. RVALID stays 1, and RID, RDATA, RRESP and RLAST do not change. |
| Offer | On every edge with RVALID = 1, find the oldest burst of RID. Check its next beat: data, response and RLAST. |
| Retire | Only on RVALID and RREADY, move to the next beat. Pop the burst after its declared last beat, whatever RLAST said. |
| Append | Last, add a burst for an AR handshake on this edge. A new AR cannot explain a beat on the same edge. |
| error_kinds bit | Raised when |
|---|---|
| 0 | A beat has an RID with no outstanding burst. |
| 1 | Wrong data or response for the oldest burst of the ID. |
| 2 | Wrong RLAST. |
| 3 | A stalled beat changed or vanished. |
| 4 | finish() finds bursts still outstanding. |
| 5 | ARREADY disagrees with the free credits. |
| 6 | ARREADY or RVALID is 1 during reset. |
write_edge() must predict from the observer's queues. It must not copy the real commit data, address or strobes.
All bursts here are fully mapped or fully unmapped. An unmapped read returns zero data and DECERR.
| Engines | Behaviour |
|---|---|
| Write engine | Correct, or one of seven faults. Data faults: zeroed data, a flipped data bit, or all strobes on. |
| Other write faults: a wrong BID, a BID that moves in a stall, an early burst end, or the newest address first. | |
| Read engine | Correct, or one fault: a flipped data bit, or a wrong RRESP with correct data. |
| Tests | Each test runs 64 edges. One test keeps BREADY at 0, so a write response is still owed at the end. |
The tests build the text write_report|read_report, each 20 hex digits. write_report is finish() of the write observer: {error_cycles, accepted_aw, accepted_w}. read_report is finish() of memory_read_checker.
They compare it with the expected text, character by character. reports_match = yes means both reports are exactly right. report_chars and expected_chars are the two lengths, normally 41.
Examples
Example 1
A Read Before the Write Keeps the Old Bytes- Input
Correct engines. Write: ID 1, INCR, 2 beats at 0x20, strobes 0x5 then 0xa; W on edges 0 and 1, AW on edge 6. Reads: ID 0 at 0x20 on edge 0, ID 1 at 0x30 on 6, ID 0 at 0x20 on 18, ID 2 at 0x80 on 32. RREADY from edge 10.
- Output
report_chars = 41, expected_chars = 41, reports_match = yes
The first read of 0x20 is accepted before the write, so its beats carry the old bytes. They retire only after the commits on edges 7 and 8. The read on edge 18 sees the new lanes. Both reports are clean. Expected text: 00000000000000000102|00000000000000000000.
Example 2
A Wrong WLAST Makes the Rest of Its Burst SLVERR- Input
Correct engines. Write: ID 0, INCR, 2 beats at 0x100, with WLAST on both beats; then ID 3, 1 beat at 0x8000 with WLAST = 0. AW and W from edge 0. Same reads.
- Output
report_chars = 41, expected_chars = 41, reports_match = yes
The first burst raises WLAST one beat early, on beat 0. That makes the burst SLVERR, so beat 1 must also expect SLVERR, although its WLAST is right. The write to 0x8000 is unmapped, so it gets DECERR whatever WLAST says. Both reports are clean. Expected text: 00000000000000000203|00000000000000000000.
Example 3
Reset Keeps Written Bytes- Input
Write: ID 1, 4 beats at 0x20 from edge 0, reset on edges 12 and 13, then ID 1, 2 beats at 0x80. BREADY is 0 until edge 30. Reads restart after the reset.
- Output
report_chars = 41, expected_chars = 41, reports_match = yes
The first burst commits all four beats before the reset. Its response is still waiting, and reset cancels it. The bytes stay, so the read of 0x20 accepted on edge 21 must see them. Expected text: 00000000000000000206|00000000000000000000.
Example 4
Bad Write Data Shows up in a Later Read- Input
The first traffic on a write engine that stores zeros instead of the W data
- Output
report_chars = 41, expected_chars = 41, reports_match = yes
The write observer flags the commits on edges 7 and 8. Real memory now holds zeros in the enabled lanes. The read on edge 18 expects the predicted bytes, so its two beats fail on edges 20 and 22. Expected text: 00000000000001800102|00000000005000000200.
Constraints and Contract
- A reset cancels transactions, not bytes already written.
- A wrong WLAST makes the rest of its burst SLVERR.
- Keep the class names, the method names and the argument types.
Hints
Hint 1
Split the problem by scene. A wrong WLAST matters only to the write side. A reset matters to both sides. Which state does each scene depend on?
Hint 2
A WLAST error is sticky for the rest of its burst. A reset cancels the work in flight but keeps the bytes already written.
Hint 3
Look at how write_observer computes new_bad. Then look at the reset branch of memory_read_checker.sample().
What the grader checks: Real write and read engines share one byte memory. Faulty engines change real data, strobes, IDs, statuses and responses, and some tests reset in the middle. Both reports are compared exactly. This is the teaching subset of AXI, not full AXI.
147 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 8 steps and the final capstone