px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_crc32.h : 32-bit CRC calculator

Description

32-bit CRC (Cyclic Redundancy Check) calculator for checksums.

File(s):

A CRC is an error-detecting code that is used for data integrity checks.

See also
http://en.wikipedia.org/wiki/Cyclic_redundancy_check
https://crccalc.com

Note that the polynomial value is bit reversed and a right shift operator is used during the calculation.

Macros

#define PX_CRC32_POLYNOMIAL   0xedb88320
 The generator polynomial CRC32 (reversed representation): x^32 + x^26 + x^23 + x^22 + x^16. More...
 
#define PX_CRC32_INIT_VAL   0xffffffff
 Initial CRC value. More...
 
#define PX_CRC32_RAM_TABLE   0
 Generate table in RAM to speed up CRC calculation. More...
 
#define PX_CRC32_ROM_TABLE   0
 Use table in ROM to speed up CRC calculation. More...
 

Functions

void px_crc32_init (void)
 Initialise 32-bit CRC calculator. More...
 
uint32_t px_crc32_update_u8 (uint32_t crc, uint8_t data)
 Calculate the 32-bit CRC over one byte. More...
 
uint32_t px_crc32_update_data (uint32_t crc, const void *data, size_t nr_of_bytes)
 Calculate the 32-bit CRC over a number of bytes. More...
 

Macro Definition Documentation

◆ PX_CRC32_POLYNOMIAL

#define PX_CRC32_POLYNOMIAL   0xedb88320

The generator polynomial CRC32 (reversed representation): x^32 + x^26 + x^23 + x^22 + x^16.

  • x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1

Definition at line 69 of file px_crc32.h.

◆ PX_CRC32_INIT_VAL

#define PX_CRC32_INIT_VAL   0xffffffff

Initial CRC value.

Definition at line 71 of file px_crc32.h.

◆ PX_CRC32_RAM_TABLE

#define PX_CRC32_RAM_TABLE   0

Generate table in RAM to speed up CRC calculation.

Definition at line 34 of file px_crc32_cfg_template.h.

◆ PX_CRC32_ROM_TABLE

#define PX_CRC32_ROM_TABLE   0

Use table in ROM to speed up CRC calculation.

Definition at line 37 of file px_crc32_cfg_template.h.

Function Documentation

◆ px_crc32_init()

void px_crc32_init ( void  )

Initialise 32-bit CRC calculator.

This function will initialise the table in RAM with constants to speed up CRC calculation. For other options it does nothing.

Definition at line 89 of file px_crc32.c.

◆ px_crc32_update_u8()

uint32_t px_crc32_update_u8 ( uint32_t  crc,
uint8_t  data 
)

Calculate the 32-bit CRC over one byte.

Parameters
crcThe initial CRC to start the calculation with
dataThe value to calculate the CRC over
Returns
uint32_t The resultant CRC

Definition at line 117 of file px_crc32.c.

◆ px_crc32_update_data()

uint32_t px_crc32_update_data ( uint32_t  crc,
const void *  data,
size_t  nr_of_bytes 
)

Calculate the 32-bit CRC over a number of bytes.

Parameters
crcThe initial CRC to start the calculation with
dataPointer to the data to calculate the CRC over
nr_of_bytesThe amount of bytes to calculate the CRC over
Returns
uint32_t The resultant CRC over the group of bytes

Definition at line 141 of file px_crc32.c.