G1.10.1 Serial CRC-8

MediumImplementIcarus · browser samples / server checksReview the topic

Build a CRC-8 register that takes one message bit per clock. It has a seed, an enable and the generator x^8 + x^2 + x + 1.

Hardware context: The receiver of a serial sensor link, a network card that drops packets, and a bar-code digit reader. Build a serial CRC-8 register with a seed, an enable and the generator x^8 + x^2 + x + 1.

A sensor sends its readings over a slow serial wire, one bit per clock. Each packet ends with a CRC-8 so that the receiver can spot corrupted readings. The receiver must compute the same CRC as the bits arrive.

This is an Implement problem. Write crc8_serial. At a rising edge with init set, crc becomes the seed FF. At a rising edge with init clear and en set, the register takes in din. Otherwise it holds its value.

Use the generator x^8 + x^2 + x + 1, the 9-bit pattern 1_0000_0111. Message bits arrive most significant first. There is no final inversion: crc is the register itself.

The check runs 32 clock cycles per case and records crc after chosen cycles.

Signals in the Timeline

SignalWidthRole
clk1input of each check
init1input of each check
en1input of each check
din1input of each check
crc8input of each check
Full specification
The module (keep the name and the ports)
module crc8_serial (
  input  logic       clk,
  input  logic       init,   // at the next rising edge, load the seed FF
  input  logic       en,     // at the next rising edge, take in din (when init is 0)
  input  logic       din,    // the next message bit
  output logic [7:0] crc     // the CRC of the bits taken in since the last init
);
  // your design
endmodule
At a rising edgecrc becomes
init = 1 (en is ignored)FF, the seed
init = 0, en = 1the running remainder with din taken in
init = 0, en = 0its old value

With the seed FF, the CRC after n bits is a remainder. Divide FF x^n + M(x) x^8 by the generator, where M(x) is the polynomial of the n message bits.

The result fields record0 to record9 are the values of crc in the order they were recorded. A case records crc after init, after the last bit of each byte, and in some idle cycles.

Examples

Example 1

One Byte: 31
Input
init, then the bytes 31, most significant bit first, then idle
Output
record0 = 0xff, record1 = 0x64, record2 = 0x64, record3 = 0x0, record4 = 0x0, record5 = 0x0, record6 = 0x0, record7 = 0x0, record8 = 0x0, record9 = 0x0

record0 is the seed FF, read after the init cycle. record1 is the CRC of the byte 31. record2 is read after many idle cycles and must equal record1.

Example 2

Three Bytes of 00
Input
init, then the bytes 00 00 00, most significant bit first, then idle
Output
record0 = 0xff, record1 = 0xf3, record2 = 0xd7, record3 = 0x2b, record4 = 0x2b, record5 = 0x0, record6 = 0x0, record7 = 0x0, record8 = 0x0, record9 = 0x0

The message is all zeros, but the CRC is not 0, because the register starts at FF. One record follows each byte.

Example 3

Three Bytes: 12 34 56
Input
init, then the bytes 12 34 56, most significant bit first, then idle
Output
record0 = 0xff, record1 = 0x8d, record2 = 0x26, record3 = 0x57, record4 = 0x57, record5 = 0x0, record6 = 0x0, record7 = 0x0, record8 = 0x0, record9 = 0x0

record0 is the seed. record1 to record3 follow the three bytes, and record4 is read after the idle cycles at the end.

Constraints and Contract

  • Inputs change only between rising edges. Every case starts with an init cycle, so crc need not have a reset value.
  • Keep the module name and the ports. crc is a register clocked by clk.

Hints

Hint 1

Follow the CRC-3 register of the lesson. The feedback bit is the top bit of the register XOR din.

Hint 2

Shift the register up by one. Where the generator has a 1 below the top, XOR in the feedback: here that is bits 2, 1 and 0.

Hint 3

Give init the first test, then en. A register with no else holds its value on its own.

What the grader checks: Thirteen cases of 32 clock cycles each run on the register, with pauses, a second init and init together with en. Every record is compared with a model that computes the CRC by polynomial division. A reset value before the first init is outside this problem.

13 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 3 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

One Byte: 31

Input
init, then the bytes 31, most significant bit first, then idle
Expected output
record0 = 0xff, record1 = 0x64, record2 = 0x64, record3 = 0x0, record4 = 0x0, record5 = 0x0, record6 = 0x0, record7 = 0x0, record8 = 0x0, record9 = 0x0

record0 is the seed FF, read after the init cycle. record1 is the CRC of the byte 31. record2 is read after many idle cycles and must equal record1.

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

Icarus · browser samples / server checks