CRC16 (lightweight)

Lightweight CRC16 checksum algorithms.

This CRC16 implementation does not use pre-calculated lookup tables and is thus very lightweight (memory-wise), but as a caveat slower (about factor 8) than the version with pre-calculated lookup tables.

Additionally compared to CRC16-CCITT this is a generalized implementation. One can easily exchange generator polynomials and starting seeds.

UCRC16_CCITT_POLY_BE

Various generator polynomials.

1
(0x1021)

CRC16-CCITT polynomial (big-endian)

UCRC16_CCITT_POLY_LE

CRC16-CCITT polynomial (little-endian)

1
(0x8408)
uint16_t ucrc16_calc_be(const uint8_t * buf, msp430_types.h::size_t len, uint16_t poly, uint16_t seed)

Calculate CRC16 (big-endian version)

Parameters

buf:Start of memory are to checksum
len:Number of bytes in buf to calculate checksum for
poly:The generator polynomial for the checksum
seed:The seed (starting value) for the checksum

Note

The return value is not the complement of the sum but the sum itself

Return values

  • Checksum of the specified memory area based on seed and poly
uint16_t ucrc16_calc_le(const uint8_t * buf, msp430_types.h::size_t len, uint16_t poly, uint16_t seed)

Calculate CRC16 (little-endian version)

Parameters

buf:Start of memory are to checksum
len:Number of bytes in buf to calculate checksum for
poly:The generator polynomial for the checksum
seed:The seed (starting value) for the checksum

Note

The return value is not the complement of the sum but the sum itself

Return values

  • Checksum of the specified memory area based on seed and poly