S7.2.3 Two Writers, One Lost Bit

MediumDebug22 minIcarus Verilog · serverReview the topic

A foreground update turns off a lamp that an interrupt handler just switched on. Find the first wrong output and repair the update.

Hardware context: ap_soc 16-pin GPIO bank. Board bring-up and interrupt-driven I/O

A foreground update turns off a lamp that an interrupt handler just switched on. Find the first wrong output and repair the update.

Signals in the Timeline

SignalWidthRole
port_clk1stimulus, the same for every design
port_rst_n1stimulus, the same for every design
port_op2stimulus, the same for every design
port_mask16stimulus, the same for every design
port_value16stimulus, the same for every design
Full specification

This fixture replays a driver transaction. Operation 1 snapshots the current latch for the foreground writer. Operation 2 lets the handler set the pins named in mask.

Operation 3 writes the inverse of the snapshot on selected pins only. All other pins keep their current live values. Operation 0 holds. The snapshot persists until replaced. Reset clears both words.

Inspect the waveform, identify the first incorrect cycle and signal, then repair the failing design.

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 1 · The first bad cycle and signal
Step 2 · The cause

Step 3 is optional: fix the code in the editor, then run the tests.

Examples

Example 1

Cold Start
Input
rst_n=1'h0, op=2'h0, mask=16'h0000
Output
value = 0x0

Both writers start from a clear latch.

Example 2

Handler Sets Pin Zero
Input
rst_n=1'h1, op=2'h2, mask=16'h0001
Output
value = 0x1

The live word now holds one.

Example 3

Foreground Reads
Input
rst_n=1'h1, op=2'h1, mask=16'h0000
Output
value = 0x1

Taking a snapshot leaves the output alone.

Example 4

Handler Sets Pin Three
Input
rst_n=1'h1, op=2'h2, mask=16'h0008
Output
value = 0x9

The live latch now holds nine while the saved word still holds one.

Example 5

Foreground Commits
Input
rst_n=1'h1, op=2'h3, mask=16'h0001
Output
value = 0x8

Pin zero turns off. The handler’s pin stays on.

Constraints and Contract

  • Sample on each rising edge. Synchronous active-low reset wins over all other inputs. Binary inputs only.

Hints

Hint 1

Mark the foreground read and its later write.

Hint 2

List which pins each writer owns.

Hint 3

Track the saved and live words in separate columns.

What the grader checks: Trials include repeated snapshots, overlapping and disjoint masks, idle cycles, cold and warm reset and every pin position.

203 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 3 problems on this path

Report a problem with this page

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

Cold Start

Input
rst_n=1'h0, op=2'h0, mask=16'h0000
Expected output
value = 0x0

Both writers start from a clear latch.

Run samples executes all 5 public checks. Check all tests runs 203 checks on the server.

Icarus Verilog · server