Find the first cycle where a shared bus reads a wrong value, and name which driver or keeper caused it.
Hardware context: A board bus shared by a CPU, peripherals and a DMA engine through tri-state drivers, with a keeper. Find the decode bug behind a bus that reads x.
Three devices share an 8-bit bus through tri-state drivers, and a keeper holds the last value when nobody drives. A read of device k should return its data; an idle cycle should keep the value of the last read. The test reports: ERROR: cycle 3 read 0011x1x0, expected 36. The bench is correct. The bug is in bus3.
Run the failing test to see its log and waveform. Each cycle sets go and sel, lets the bus settle, and checks the value the reader sees.
Step 1: find the first cycle where rd shows a value a correct bus would not. Step 2: choose the cause from four possible bugs; each is real and fails in a different cycle. Step 3 is optional: fix bus3 and run the tests (lesson G4.10).
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
script | 24 | input of each check |
Full specification
module bus3 (
input logic [1:0] sel, // 0, 1, 2: the device to read; 3: nobody
input logic go, // 1: a read this cycle
input logic [7:0] d0, d1, d2, // the data each device would drive
output wire [7:0] rd // the bus, as the reader sees it
);
...
endmodule
| Request | Correct bus |
|---|---|
| go = 1, sel = 0, 1 or 2 | Exactly that device drives; rd is its data (d0 = 3c, d1 = 36, d2 = 5a). |
| go = 0, or sel = 3 | Nobody drives; the keeper holds the last driven value. |
| never | Two drivers at once (x), or a floating bus (z). |
| Cycle | go | sel |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 1 | 2 |
| 2 | 0 | 3 |
| 3 | 1 | 1 |
| 4 | 0 | 0 |
| 5 | 1 | 2 |
| 6 | 1 | 0 |
| 7 | 0 | 1 |
| 8 | 1 | 1 |
| 9 | 0 | 3 |
Cycle N is the stretch where the cycle counter shows N. The fix tests apply eight requests, one every 2 ns. They record rd, and flag any bit that was x or z.
Diagnose the Failing Run
The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.
Log
Waveform
Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.
Step 3 is optional: fix the code in the editor, then run the tests.
Examples
Example 1
Read Each Device, with Idle Cycles Between- Input
read 0, idle, read 1, idle, read 2, idle, idle, read 0
- Output
rd_step0 = 0x3c, rd_has_x_step0 = no, rd_has_z_step0 = no, rd_step1 = 0x3c, rd_has_x_step1 = no, rd_has_z_step1 = no, rd_step2 = 0x36, rd_has_x_step2 = no, rd_has_z_step2 = no, rd_step3 = 0x36, rd_has_x_step3 = no, rd_has_z_step3 = no, rd_step4 = 0x5a, rd_has_x_step4 = no, rd_has_z_step4 = no, rd_step5 = 0x5a, rd_has_x_step5 = no, rd_has_z_step5 = no, rd_step6 = 0x5a, rd_has_x_step6 = no, rd_has_z_step6 = no, rd_step7 = 0x3c, rd_has_x_step7 = no, rd_has_z_step7 = no
Each read gives that device's data, and the idle cycle after it holds that value. So rd reads 3c, 3c, 36, 36, 5a, 5a, 5a, 3c.
Example 2
Back-to-Back Reads- Input
read 1, read 2, read 0, read 1, read 0, read 2, read 2, read 1
- Output
rd_step0 = 0x36, rd_has_x_step0 = no, rd_has_z_step0 = no, rd_step1 = 0x5a, rd_has_x_step1 = no, rd_has_z_step1 = no, rd_step2 = 0x3c, rd_has_x_step2 = no, rd_has_z_step2 = no, rd_step3 = 0x36, rd_has_x_step3 = no, rd_has_z_step3 = no, rd_step4 = 0x3c, rd_has_x_step4 = no, rd_has_z_step4 = no, rd_step5 = 0x5a, rd_has_x_step5 = no, rd_has_z_step5 = no, rd_step6 = 0x5a, rd_has_x_step6 = no, rd_has_z_step6 = no, rd_step7 = 0x36, rd_has_x_step7 = no, rd_has_z_step7 = no
No idle cycles: the bus moves straight from one device's data to the next.
Example 3
Address 3 Holds the Bus- Input
read 2, read 3 (nobody), read 1, read 3 (nobody), idle, read 0, read 3 (nobody), idle
- Output
rd_step0 = 0x5a, rd_has_x_step0 = no, rd_has_z_step0 = no, rd_step1 = 0x5a, rd_has_x_step1 = no, rd_has_z_step1 = no, rd_step2 = 0x36, rd_has_x_step2 = no, rd_has_z_step2 = no, rd_step3 = 0x36, rd_has_x_step3 = no, rd_has_z_step3 = no, rd_step4 = 0x36, rd_has_x_step4 = no, rd_has_z_step4 = no, rd_step5 = 0x3c, rd_has_x_step5 = no, rd_has_z_step5 = no, rd_step6 = 0x3c, rd_has_x_step6 = no, rd_has_z_step6 = no, rd_step7 = 0x3c, rd_has_x_step7 = no, rd_has_z_step7 = no
A read of address 3 enables nobody, so the keeper holds the value of the read before.
Constraints and Contract
- go, sel and the data inputs are known 0/1 values.
- Keep the module name and the ports.
Hints
Hint 1
Work out the correct rd for each cycle from the table. A read gives that device's data; an idle cycle keeps the last value read. Compare with the waveform from cycle 0.
Hint 2
An x on some bits means two drivers disagree on them. A z means nobody drives and nothing holds the bus. A stale value means the device that should drive did not.
Hint 3
In the first wrong cycle, ask which devices were enabled. The bit pattern of the x tells you which two values fought.
What the grader checks: The failing run is simulated live with the shipped bus. The correct and each buggy bus run on the same ten-cycle bench. That gives the first bad cycle and value of every option. The optional fix is compared with a model written in JavaScript on four directed and eight seeded scripts of eight requests.
12 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 3 steps and the final capstone