P11.5.1 Fix the FCS Generator

MediumFixIcarus Verilog · serverReview the topic

A MAC's check-sequence generator was ported from another design. Every frame it sends fails at the far end. Find the two wrong lines.

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 generator below takes the covered octets of a frame one at a time. They run from the first destination octet to the last pad octet. Then it hands out the four FCS octets in sending order.

It keeps the CRC register mirrored, the way many MACs do: bit 0 of crc holds the x^31 term. The register shifts right.

A receiver rejects every frame it builds. Two lines are wrong. Fix them so that the octets match any correct Ethernet FCS.

Run the samples first. The message "123456789" has the well-known CRC-32 value CBF43926h.

Signals in the Timeline

SignalWidthRole
test_number8input of each check
Full specification
The API (keep it)
bit [31:0] crc;                                      // the mirrored register
function automatic void fcs_init();                  // start of a frame
function automatic void fcs_add(input [7:0] b);       // one covered octet
function automatic [7:0] fcs_octet(input int k);      // FCS octet k, 0 = first sent
RuleValue
Generator04C11DB7h, the CRC-32 generator of 3.2.9
Startall ones before the first covered octet
Bit order ineach octet low bit first, as on the wire
Endthe remainder inverted, sent x^31 first
Mirrored registercrc[0] holds the x^31 term and crc[31] the x^0 term

The tests feed whole frames and short messages. Every test calls fcs_init first.

Examples

Example 1

The Check Message
Input
"123456789"
Output
fcs_octet_3 = 0xcb, fcs_octet_2 = 0xf4, fcs_octet_1 = 0x39, fcs_octet_0_sent_first = 0x26

CRC-32 of this text is CBF43926h. Sent low octet first, the four octets are 26h, 39h, F4h and CBh.

Example 2

The Lesson's Frame
Input
60 covered octets
Output
fcs_octet_3 = 0x9a, fcs_octet_2 = 0x76, fcs_octet_1 = 0xb1, fcs_octet_0_sent_first = 0xe6

The FCS of the P11.5 frame. The bench sent E6h, B1h, 76h and 9Ah.

Example 3

One Zero Octet
Input
00h
Output
fcs_octet_3 = 0xd2, fcs_octet_2 = 0x2, fcs_octet_1 = 0xef, fcs_octet_0_sent_first = 0x8d

Even one octet must give the right four octets, in the right order.

Constraints and Contract

  • Keep the three function names, their arguments and the register name.
  • Keep the register mirrored; do not switch to a left-shifting form.
  • The fix touches two lines. You may rewrite more if you prefer.
  • Off limits: the names lib, rng, tb, root and the modules of the bench.

Hints

Hint 1

The first wire bit of an octet is its bit 0. In a mirrored register, which end does the next bit meet first?

Hint 2

Sending x^31 first, with octets sent low bit first, decides which part of the inverted register is octet 0.

Hint 3

Compare your four octets for "123456789" with CBF43926h read low octet first: 26h, 39h, F4h, CBh.

What the grader checks: The fixture checks five fixed messages against Node's zlib.crc32 and 130 random frames against the bench library's FCS, octet by octet. It does not test a clocked design or frames with a part octet.

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

The Check Message

Input
"123456789"
Expected output
fcs_octet_3 = 0xcb, fcs_octet_2 = 0xf4, fcs_octet_1 = 0x39, fcs_octet_0_sent_first = 0x26

CRC-32 of this text is CBF43926h. Sent low octet first, the four octets are 26h, 39h, F4h and CBh.

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

Icarus Verilog · server