P10.5.2 Debug the Descrambler That Never Recovers

MediumDebugIcarus · browser samples / server checksReview the topic

A descrambler turns every byte into noise from the middle of a packet on. Find the first cycle where it went wrong, and name the bug.

Hardware context: The digital blocks of a serializer/deserializer: line encoder and decoder, scrambler, CRC and error-correcting code. Keep the line balanced and busy, and detect or correct the errors a fast serial link makes.

A link trains, sends three good bytes, and then delivers only noise. The log says: ERROR cycle 6: data b5, expected 13. The sender is correct. The bug is in the descrambler.

Run the failing test to see its log and waveform. Each cycle is one received symbol. The waveform shows its kind, the byte on the wire, the descrambler output and the descrambler register lfsr.

Step 1: find the first cycle where a descrambler signal shows the wrong value, and name that signal. The error at cycle 6 is where the problem surfaced, not where it started.

Step 2: choose the cause from four possible bugs. Each one is a real bug that fails in a different way. Step 3 is optional: fix the descrambler in the editor and run the tests.

Signals in the Timeline

SignalWidthRole
test_number8input of each check
Full specification
The descrambler API
function automatic void dscr_reset();                                        // link reset
function automatic [7:0] dscr_symbol(input [1:0] kind, input [7:0] rx);     // one received symbol
Symbol kindCorrect descrambler
1 COMLoads the seed FFFFh into the register. The byte passes unchanged.
2 SKPThe register holds. The byte passes unchanged.
3 Any other K codeThe register takes eight shifts. The byte passes unchanged.
0 DataEach bit, bit 0 first, is XORed with register bit 15. The register shifts once after each bit.
One shiftShift left by one. If bit 15 was 1 before the shift, XOR 0039h into the register.
SignalIn each cycle
kind, rxThe symbol received at the rising edge that starts the cycle.
dataThe descrambler output for this symbol.
lfsrThe register after this symbol.

The sender follows the same rules: it reloads on COM, holds on SKP and shifts eight times on every other symbol. After a link reset the register is 0000h until the first COM.

Cycle N is the stretch where the cycle counter shows N. A signal is wrong in cycle N if its value there differs from what a correct descrambler shows.

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

Data with Skip Symbols
Input
COM, then 39 symbols of data and SKP
Output
wrong_bytes = 0

The register holds on every SKP, so it stays in step with the sender and no byte is wrong.

Example 2

Data with COM Symbols
Input
40 symbols of data and COM
Output
wrong_bytes = 0

Each COM reloads FFFFh at both ends. No byte is wrong.

Example 3

Data with Other K Codes
Input
COM, then 39 symbols of data and other K codes
Output
wrong_bytes = 0

Other K codes are not descrambled, but the register still takes eight shifts for each.

Constraints and Contract

  • Keep the two function names and their arguments.
  • Symbols arrive one at a time, in order.
  • The first symbol after a link reset is always COM.

Hints

Hint 1

The output was right for three bytes. What kind of symbol arrived between the last good byte and the first bad one?

Hint 2

Work out by hand what the register should hold after each symbol. A COM gives FFFFh. Compare with lfsr in the waveform.

Hint 3

The first cycle where your register and lfsr disagree is the first bad cycle. Ask which row of the table the descrambler broke on that symbol.

What the grader checks: The failing run is simulated live with the faulty descrambler. The fixture simulates the correct and each faulty descrambler on the same stream. The first bad cycle and each option's first wrong value come from those runs. The optional fix is checked on five seeded streams.

5 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

Report a problem with this page

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

Data with Skip Symbols

Input
COM, then 39 symbols of data and SKP
Expected output
wrong_bytes = 0

The register holds on every SKP, so it stays in step with the sender and no byte is wrong.

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

Icarus · browser samples / server checks