Module esp_idf_svc::hal::rom::crc

source ·
Expand description

Cyclic Redundancy Check

These are safe abstractions to the CRC functions in the ESP32 ROM. Some chips may not include all of these functions so they will be compiled into the program binary in those cases.

§Parameters

The ROM provides the following polynomials for each CRC width:

CRC WidthPolynomial
CRC-80x07
CRC-160x1021
CRC-320x04c11db7

The “big-endian” *_be() functions are left-shifting algorithms to be used when input and output reflection are not needed. If input and output reflection are needed, the right-shifting “little-endian” *_le() functions should be used.

These functions are designed to compute a CRC over a single buffer or as an ongoing calculation over multiple buffers. To do this, the initial value passed in and the final value returned are one’s complemented.

// CRC-32/MPEG-2
const CRC_INITIAL = 0xffffffff; // "init" or "xorin" of all ones
let mut crc = crc32_be(!CRC_INITIAL, &data0); // start
crc = crc32_be(crc, &data1);
crc = !crc32_be(crc, &data2); // finish

§Examples

A catalogue of these parameters can be found at https://reveng.sourceforge.io/crc-catalogue/all.htm

CRC-32/ISO-HDLC poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0xffffffff

let crc = crc32_le(!0xffffffff, &data);

CRC-32/BZIP2 poly=0x04c11db7 init=0xffffffff refin=false refout=false xorout=0xffffffff

let crc = crc32_be(!0xffffffff, &data);

CRC-32/MPEG-2 poly=0x04c11db7 init=0xffffffff refin=false refout=false xorout=0x00000000

let crc = !crc32_be(!0xffffffff, &data);

CRC-32/CKSUM poly=0x04c11db7 init=0x00000000 refin=false refout=false xorout=0xffffffff

let crc = crc32_be(!0, &data);

CRC-16/KERMIT poly=0x1021 init=0x0000 refin=true refout=true xorout=0x0000

let crc = !crc16_le(!0, &data);

Functions§

  • Left-shifting CRC-8 with polynomial 0x07
  • Right-shifting CRC-8 with polynomial 0x07
  • Left-shifting CRC-16 with polynomial 0x1021
  • Right-shifting CRC-16 with polynomial 0x1021
  • Left-shifting CRC-32 with polynomial 0x04c11db7
  • Right-shifting CRC-32 with polynomial 0x04c11db7