P11.43.1 A 4B/5B Decoder with Code Violations

EasyImplementIcarus Verilog · serverReview the topic

Fast Ethernet sends every nibble as five bits. Write the table both ways, flag what is not in it, and find the end of a stream.

Hardware context: An Ethernet MAC and physical coding sublayer: frame builder and checker, reconciliation sublayer and block encoder. Build, check and pace Ethernet frames, and code them for the physical layer as IEEE 802.3 specifies.

The PCS of 100BASE-X turns each nibble from the MII into a code-group of five bits.

Sixteen of the 32 code-groups are data. A few more have a role, and the rest must never appear.

enc5 is the table of the lesson, from nibble to code-group. dec5 is the way back, with a violation bit.

rx_step is the RECEIVE state of the receiver. It looks at one code-group and at the one after it.

The four rules of rx_step never overlap, so their order does not matter.

The code-groups arrive already aligned here. Finding the start in a stream of bits is the lesson's example.

Signals in the Timeline

SignalWidthRole
test_number8input of each check
Full specification
The API (keep it)
function automatic [4:0] enc5(input [3:0] nib);
function automatic [4:0] dec5(input [4:0] cg);                      // {violation, nibble}
function automatic [5:0] rx_step(input [4:0] cur, input [4:0] nxt);  // {what, RXD}
ItemRule
A code-groupfive bits, written 4 down to 0 as in Table 24-1. Bit 4 goes on the line first (24.2.2.4)
enc5(nib)the Data code-group for the nibble (Table 24-1). The nibble is TXD<3:0>
dec5(cg)for a Data code-group: violation 0 and its nibble. For every other code-group: violation 1. A course choice: the nibble is then 0
00000a course choice: this port has no Energy-Efficient Ethernet. So 00000 is an invalid code-group, as the table says for that case
rx_step(cur, nxt)cur is the code-group to deal with, rx_bits[9:5] of Figure 24-11. nxt is the one after it, rx_bits[4:0]
End of streamcur is /T/ and nxt is /R/: what = 2
Premature endcur and nxt are both /I/: what = 3. The stream stopped with no /T/R/
Datacur is a Data code-group: what = 0, and RXD is its nibble. nxt does not matter
Data erroreverything else: what = 1. The receiver raises RX_ER
RXDa course choice: the low four bits are 0 when what is not 0. The figure sets no RXD there
The values of whata course choice of this API

The tests call rx_step about 2,500 times. One look-up in each function is plenty.

A decoder that searches the encoder bit by bit, for every code-group, is about 100 times slower. It may run out of time.

Examples

Example 1

Encode the Nibble 5h
Input
`enc5(4'h5)`
Output
code_group = 'b01011

The row for 5 in Table 24-1 is 01011.

Example 2

Decode 01110
Input
`dec5(5'b01110)`
Output
violation = 'b0, nibble = 0x6

01110 is the Data code-group 6. The violation bit is 0.

Example 3

Decode /H/
Input
`dec5(5'b00100)`
Output
violation = 'b1, nibble = 0x0

/H/ is not data. The violation bit is 1 and the nibble is 0.

Example 4

The End of a Stream
Input
`rx_step(5'b01101, 5'b00111)`
Output
what = end of stream (2), rxd = 0x0

/T/ followed by /R/ is the End-of-Stream delimiter: what is 2.

Constraints and Contract

  • Keep the three functions with their arguments.
  • The functions must not keep state: the same inputs always give the same result.
  • Type the table yourself. The readable library of the lesson holds only the six code-groups with a role.
  • Off limits: the names ref_c, rng, tb, root, names that begin with fx_ and the modules of the bench.

Hints

Hint 1

The lesson has the table. Which column is bit 4?

Hint 2

What does /T/ mean when the next code-group is not /R/?

Hint 3

One /I/ in a stream is not an end. What is it?

What the grader checks: The three functions have no state and few inputs, so every input is tried. The encoder gets all 16 nibbles and the decoder all 32 code-groups. Their expected values come from a JavaScript model built from the table. rx_step gets 26 scripted pairs with values from that model. It also gets all 1,024 pairs beside a private model, whose table was typed a second time. Two more rows call the three functions in a random order, which changes with every submission. So a function that keeps state fails. A failed row shows which nibble, code-group or kind of pair was wrong. The result layouts, the nibble 0 with a violation, RXD 0 outside data and 00000 as an invalid code-group are course choices. Alignment on /J/K/, false carrier, the Transmit process and the LPI states of Figures 24-8 and 24-11 are not graded here.

12 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 1 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

Encode the Nibble 5h

Input
`enc5(4'h5)`
Expected output
code_group = 'b01011

The row for 5 in Table 24-1 is 01011.

Run samples executes all 4 public checks. Check all tests runs 12 checks on the server.

Icarus Verilog · server