Decode every ten-bit code. Flag the 560 codes that do not exist, and flag a valid code that arrives in the wrong column.
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 receiver hands you ten bits and its running disparity. Write dec8b10b(code, rd).
For a valid code it returns the byte and whether it is a K code. It raises code_err when the ten bits are in neither column of the table. It raises disp_err when the code is valid, but only at the other disparity.
It also returns the running disparity after the code. Compute it from the received bits, even when the code is bad. The receiver must keep tracking the line through an error.
The encoder enc8b10b(d, k, rd) is given. It is the full table: call it for all 268 symbols at both disparities and you know every valid code.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
test_number | 8 | input of each check |
Full specification
function automatic [11:0] dec8b10b(input [9:0] code, input bit rd); // returns {rd_out, disp_err, code_err, k, d[7:0]}
function automatic [10:0] enc8b10b(input [7:0] d, input bit k, input bit rd); // given: returns {rd_out, code[9:0]}
| The code is | d, k | code_err | disp_err |
|---|---|---|---|
| Valid at the current disparity | The byte and its K flag | 0 | 0 |
| Valid only at the other disparity | The byte and its K flag | 0 | 1 |
| In neither column | 0 and 0 | 1 | 0 |
| Bits | Disparity afterwards |
|---|---|
Six bits code[9:4] with more ones than zeros, or 000111 | RD+ |
Six bits with more zeros, or 111000 | RD- |
| Any other six bits | Unchanged |
Four bits code[3:0] with more ones than zeros, or 0011 | RD+ |
Four bits with more zeros, or 1100 | RD- |
| Any other four bits | As it was after the six bits |
The 268 symbols are the 256 data bytes and 12 K codes. K28.0 to K28.7 are 1Ch, 3Ch and so on up to FCh. K23.7 is F7h, K27.7 is FBh, K29.7 is FDh and K30.7 is FEh.
Returning 0 for the byte of an invalid code is this problem's rule. USB 3.2 substitutes K28.4 instead (§6.3.1.4).
The tests decode all 1,024 codes at both disparities. That gives 536 valid decodes, 392 in the wrong column and 1,120 for codes that do not exist.
Examples
Example 1
K28.5 At RD-- Input
code = 10'b0011111010, rd = 0
- Output
d = 0xbc, k = yes, code_err = no, disp_err = no, rd_out = RD+ (1)
The code is in the RD- column for K28.5, so both flags are 0, k is 1 and d is BCh. Six ones leave RD+.
Example 2
A Valid Code in the Wrong Column- Input
code = 10'b1001110100, rd = 1
- Output
d = 0x0, k = no, code_err = no, disp_err = yes, rd_out = RD- (0)
This is D0.0 for RD-. At RD+ the encoder would have sent 0110001011, so disp_err is 1. The byte is still 00h.
Example 3
A Code That Does Not Exist- Input
code = 10'b1111111111, rd = 0
- Output
d = 0x0, k = no, code_err = yes, disp_err = no, rd_out = RD+ (1)
No symbol encodes to ten ones: code_err is 1 and the byte is 0. The disparity still follows the bits: RD+.
Constraints and Contract
- Keep the function name, the arguments and the 12-bit result.
- You may declare module-level variables and helper functions, for example a table that is built on the first call.
rdis 0 for RD- and 1 for RD+.
Hints
Hint 1
There are only 1,024 possible inputs. What would you like to know about each one before the first call returns?
Hint 2
A code can be valid at RD-, at RD+, at both or at neither. Two one-bit tables hold that, and the encoder can fill them.
Hint 3
The disparity after the code does not depend on the tables at all. Count the ones in the six bits, then in the four bits, and apply the six rules of the specification.
What the grader checks: The fixture compares your function with a table model on all 1,024 codes at both disparities. It does not test symbol alignment, a stream of symbols or timing.
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