Write the sender's CRC-32 and the receiver's check, and get the seed, the bit order, the inversion and the residue right.
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 packet carries up to nine bytes and a 32-bit CRC. Write both ends.
crc32_field(msg, n) is the sender. It runs the CRC-32 over the first n bytes and returns the CRC field. For the text "123456789" the answer is the well-known CBF43926h.
crc32_ok(msg, n, field) is the receiver. It returns 1 for a good packet and 0 for a damaged one. It must also reject packets from a sender that got the seed, the bit order or the inversion wrong.
Most CRC bugs are one of those three settings. The tests include a sender with each mistake.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
test_number | 8 | input of each check |
Full specification
function automatic [31:0] crc32_field(input [71:0] msg, input int n);
function automatic bit crc32_ok(input [71:0] msg, input int n, input [31:0] field);
| Setting | Value |
|---|---|
| Generator | 04C11DB7h (the x^32 term is implied) |
| Seed | FFFFFFFFh |
| Register step | XOR the data bit with register bit 31. Shift left by one. If the XOR was 1, XOR the generator in. |
| Byte order | Byte 0 is msg[7:0]. Bytes enter in order, each one bit 0 first. |
| Field | The inverted register. Register bit 31 is sent first. |
Return value of crc32_field | The field with its first-sent bit in bit 0 |
| Residue | After the message and the 32 field bits, a good packet leaves C704DD7Bh in the register |
n is 0 to 9. With n = 0 no byte enters the register.
These settings are the CRC-32 of USB 3.2 (§7.2.1.2.2).
Examples
Example 1
The Text "123456789"- Input
nine bytes, 31h to 39h
- Output
value = 0xcbf43926
This is the standard test message for a CRC. Any correct CRC-32 with these settings returns CBF43926h.
Example 2
One Byte, 61h- Input
the letter 'a'
- Output
value = 0xe8b7be43
Eight register steps, then the inversion and the turn-around.
Example 3
A Good Packet- Input
the first message with its own CRC
- Output
accepted = yes
After the nine bytes and the 32 field bits the register holds C704DD7Bh, so the packet is accepted.
Constraints and Contract
- Keep both function names, their arguments and their result types.
nis between 0 and 9. Bytes at and abovenmust be ignored.- You may add helper functions.
Hints
Hint 1
Write the one-bit register step first and test it by hand on a single bit.
Hint 2
The check value has the first-sent bit in bit 0, but the first-sent bit is register bit 31. One loop turns the word around.
Hint 3
The receiver does not need the sender's CRC as a number. Run the field through the same register, in the order it was sent, and compare with the residue.
What the grader checks: The fixture checks published values, 40 random messages against a CRC model, and 180 good, damaged and wrong-sender packets. It does not test messages longer than nine bytes.
8 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