P10.3.1 Fix the Disparity Bug

MediumFixIcarus · browser samples / server checksReview the topic

An 8b/10b encoder sends codes that no decoder accepts. Find the one defect in how it tracks the running disparity.

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.

This is a Fix problem. The encoder in the editor has one realistic defect. Find it and repair it.

The link partner reports code errors on about one symbol in five. Most bytes that decode are right. A scope shows runs of six equal bits, which 8b/10b never sends.

The function enc8b10b(d, k, rd) encodes one byte. It returns the ten-bit code and the running disparity after it. The two tables in the code are correct. So is the rule that inverts a code at RD+.

Run the first example. Compare the four-bit part of your code with the expected one, then ask which disparity chose it.

Signals in the Timeline

SignalWidthRole
test_number8input of each check
Full specification
Signature (keep it)
function automatic [10:0] enc8b10b(input [7:0] d, input bit k, input bit rd);   // returns {rd_out, code[9:0]}
ItemRule
code{a,b,c,d,e,i,f,g,h,j}. Bit a is code[9] and goes on the wire first.
rd, rd_out0 is RD-, 1 is RD+.
Six-bit partFrom d[4:0], chosen by rd. Unbalanced codes and 111000 are inverted at RD+.
Disparity after six bitsMore ones: RD+. More zeros: RD-. 000111: RD+. 111000: RD-. Otherwise unchanged.
Four-bit partFrom d[7:5], chosen by the disparity after the six bits. Unbalanced codes and 1100 are inverted at RD+.
rd_outThe same rule on the four bits: 0011 gives RD+, 1100 gives RD-.
K codesk = 1 is used only with K28.0 to K28.7, K23.7, K27.7, K29.7 and K30.7.

The tests encode all 256 data bytes and the 12 K codes at both disparities. They then send 5,000 symbols and measure the wire: the longest run and the range of ones minus zeros.

Examples

Example 1

D0.0 At RD-
Input
d = 8'h00, k = 0, rd = 0
Output
code = 'b1001110100, rd_out = RD- (0)

The six bits 100111 have four ones, so the four-bit part is chosen at RD+: 0100. The code has five ones and the disparity ends at RD-.

Example 2

K28.5 At RD-
Input
d = 8'hbc, k = 1, rd = 0
Output
code = 'b0011111010, rd_out = RD+ (1)

K28 uses 001111 at RD-. The disparity is then RD+, so the four bits are 1010. Six ones in all: the result is RD+.

Example 3

D11.7 At RD+
Input
d = 8'heb, k = 0, rd = 1
Output
code = 'b1101001000, rd_out = RD- (0)

110100 is balanced and stays. At RD+ D11.7 takes the alternate form 1000, which avoids five equal bits in a row.

Constraints and Contract

  • Keep the function name, the arguments and the 11-bit result.
  • The helper tables five_six, three_four and three_four_k are correct. You may leave them alone.
  • k = 1 is only used with the 12 K codes.

Hints

Hint 1

An 8b/10b code has four, five or six ones. Count the ones in the code your function returns for D0.0 at RD-.

Hint 2

A symbol is two small codes in a row. Each one is chosen by the disparity that the bits before it left behind.

Hint 3

Follow the variable that carries the disparity from the six-bit part to the four-bit part. What should it hold when the six bits were not balanced?

What the grader checks: The fixture compares your function with a table model on every data byte and K code at both disparities. It also checks a 5,000-symbol stream. It does not test serialization, timing or a decoder.

7 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 2 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

D0.0 At RD-

Input
d = 8'h00, k = 0, rd = 0
Expected output
code = 'b1001110100, rd_out = RD- (0)

The six bits `100111` have four ones, so the four-bit part is chosen at RD+: `0100`. The code has five ones and the disparity ends at RD-.

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

Icarus · browser samples / server checks