Trace a missed oversize frame back to the declaration a shared name really means, and name the cause from four real bugs.
Hardware context: UART line watcher, link checkers and a bus lock that share declarations through packages. Trace a missed oversize frame to the declaration a shared limit really means.
A UART watcher must flag every frame longer than 16 bytes. The test sends a 20-byte frame and ends with ERROR: 1 oversize frame was sent, 0 flagged. The code reads correctly: too_long is set when the length is above MAX_LEN, and uart_pkg says MAX_LEN is 16.
Three declarations sit close to that name. spi_pkg also declares MAX_LEN, as 64. An older file in the same compilation unit declares GAP and TIMEOUT at file scope. The watcher uses all three names, and nothing in the compile log says which declaration each one means.
Run the failing test to see its log and waveform. Step 1: find the first cycle where an output shows a wrong value, and name the signal. Step 2: choose the cause from four bugs. Each is a real bug with a different first symptom, and each compiles without a message.
Step 3 is optional: fix uart_watch in the editor and run the tests.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
frames | 16 | input of each check |
Full specification
// uart_pkg.sv and spi_pkg.sv: both declare MAX_LEN.
package uart_pkg;
parameter int TIMEOUT = 6; // idle cycles before the line counts as dead
parameter int MAX_LEN = 16; // longest legal frame, in bytes
parameter int GAP = 2; // cycles a sender waits after a frame
endpackage
package spi_pkg;
parameter int MAX_LEN = 64; // longest SPI transfer, in bytes
parameter int CS_HOLD = 1;
endpackage
// old_defs.sv: file-scope constants from before the packages existed.
parameter int GAP = 4;
parameter int TIMEOUT = 4;
| Output | Correct watcher (numbers from uart_pkg) |
|---|---|
| too_long | 1 for one cycle after a frame whose length is 0 or above MAX_LEN (16). |
| timeout | 1 once the line has been quiet for TIMEOUT (6) cycles; 0 again after the next frame. |
| gap_left | GAP (2) in the cycle after a frame, then counts down to 0. |
Cycle N is the stretch where the cycle counter shows N. Inputs change in the middle of a cycle, and the outputs answer in the next cycle.
The test: reset, a legal 8-byte frame, eight quiet cycles, a 20-byte frame, three quiet cycles.
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
A Legal Frame, a Quiet Line, an Oversize Frame- Input
Frames: cycle 0: 8 bytes, cycle 9: 20 bytes
- Output
gap_left_total = 6, timeout_cycles = {6, 7, 8, 15}, too_long_cycles = {9}
The gap is 2 then 1 after each frame. The line is quiet from cycle 1, so timeout is 1 in cycles 6 to 8. The 20-byte frame sets too_long in cycle 9.
Example 2
The Longest Legal Frame, Then One Byte More- Input
Frames: cycle 2: 16 bytes, cycle 3: 17 bytes
- Output
gap_left_total = 5, timeout_cycles = {9, 10, 11, 12, 13, 14, 15}, too_long_cycles = {3}
Sixteen bytes is legal. Seventeen is flagged, in the cycle the frame arrives.
Example 3
A Line That Never Speaks- Input
No frames
- Output
gap_left_total = 0, timeout_cycles = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, too_long_cycles = {}
After five quiet cycles the sixth raises timeout, and it stays up.
Constraints and Contract
- Keep the module name and ports of uart_watch.
- Every number comes from uart_pkg; write none of them as a literal.
- The packages and the old file-scope constants stay as they are.
Hints
Hint 1
The 20-byte frame arrives late in the test. Check the earlier outputs too: if they are right, the wrong name is used only where the length is checked.
Hint 2
Walk the search for each use of MAX_LEN, TIMEOUT and GAP. It starts in the scope of the use, then tries the module, then the file scope. The first declaration you meet is the one the compiler takes.
Hint 3
Two wildcard imports clash only when they are in the same scope. An import inside a function is a closer scope than the module, so it wins there without any error.
What the grader checks: The failing run is simulated live with the buggy watcher. The first wrong cycle and each option's first wrong value come from real runs of the correct and the buggy watchers. The optional fix is checked on frames of many lengths, quiet lines and back-to-back frames. All runs use Icarus 12, which follows the import rules of the standard.
16 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