File syn_crc.h¶
FileList > src > syntropic > util > syn_crc.h
Go to the source code of this file
CRC calculation for communication protocols. More...
#include <stddef.h>#include <stdint.h>
Public Functions¶
| Type | Name |
|---|---|
| uint16_t | syn_crc16_ccitt_update (uint16_t crc, const void * data, size_t len) Update CRC-16 CCITT with a block of data. |
| uint16_t | syn_crc16_modbus_update (uint16_t crc, const void * data, size_t len) Update CRC-16 Modbus with a block of data. |
| uint32_t | syn_crc32_update (uint32_t crc, const void * data, size_t len) Update CRC-32 with a block of data. |
| uint8_t | syn_crc8_update (uint8_t crc, const void * data, size_t len) Update CRC-8 with a block of data. |
Public Static Functions¶
| Type | Name |
|---|---|
| uint16_t | syn_crc16_ccitt (const void * data, size_t len) Compute CRC-16 CCITT of a complete buffer. |
| uint16_t | syn_crc16_modbus (const void * data, size_t len) Compute CRC-16 Modbus of a complete buffer. |
| uint32_t | syn_crc32 (const void * data, size_t len) Compute CRC-32 of a complete buffer. |
| uint32_t | syn_crc32_final (uint32_t crc) Finalize CRC-32 (XOR with 0xFFFFFFFF). |
| uint8_t | syn_crc8 (const void * data, size_t len) Compute CRC-8 of a complete buffer. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_CRC16_CCITT_INIT 0xFFFFuCRC-16 CCITT initial value. |
| define | SYN_CRC16_MODBUS_INIT 0xFFFFuCRC-16 Modbus initial value. |
| define | SYN_CRC32_INIT 0xFFFFFFFFuCRC-32 initial value. |
| define | SYN_CRC8_INIT 0x00uCRC-8 initial value. |
| define | SYN_CRC_USE_TABLE 1 |
Detailed Description¶
Provides CRC-8, CRC-16 (CCITT, Modbus), and CRC-32 (Ethernet). Configure SYN_CRC_USE_TABLE to trade ROM for speed: 1 = 256-entry lookup table (fast, ~256–1024 bytes ROM per variant) 0 = bit-by-bit computation (small, slower)
All variants support incremental (streaming) computation.
** **
uint16_t crc = syn_crc16_ccitt(data, len);
// Incremental:
uint16_t crc = SYN_CRC16_CCITT_INIT;
crc = syn_crc16_ccitt_update(crc, chunk1, len1);
crc = syn_crc16_ccitt_update(crc, chunk2, len2);
Public Functions Documentation¶
function syn_crc16_ccitt_update¶
Update CRC-16 CCITT with a block of data.
Parameters:
crcRunning CRC value (start with SYN_CRC16_CCITT_INIT).dataData buffer.lenLength in bytes.
Returns:
Updated CRC-16.
function syn_crc16_modbus_update¶
Update CRC-16 Modbus with a block of data.
Parameters:
crcRunning CRC value (start with SYN_CRC16_MODBUS_INIT).dataData buffer.lenLength in bytes.
Returns:
Updated CRC-16.
function syn_crc32_update¶
Update CRC-32 with a block of data.
Parameters:
crcRunning CRC value (start with SYN_CRC32_INIT).dataData buffer.lenLength in bytes.
Returns:
Updated CRC-32 (call syn_crc32_final to finalize).
function syn_crc8_update¶
Update CRC-8 with a block of data.
Parameters:
crcRunning CRC value (start with SYN_CRC8_INIT).dataData buffer.lenLength in bytes.
Returns:
Updated CRC-8.
Public Static Functions Documentation¶
function syn_crc16_ccitt¶
Compute CRC-16 CCITT of a complete buffer.
Parameters:
dataData buffer.lenLength in bytes.
Returns:
CRC-16 CCITT value.
function syn_crc16_modbus¶
Compute CRC-16 Modbus of a complete buffer.
Parameters:
dataData buffer.lenLength in bytes.
Returns:
CRC-16 Modbus value.
function syn_crc32¶
Compute CRC-32 of a complete buffer.
Parameters:
dataData buffer.lenLength in bytes.
Returns:
CRC-32 value.
function syn_crc32_final¶
Finalize CRC-32 (XOR with 0xFFFFFFFF).
Parameters:
crcRunning CRC-32 value.
Returns:
Final CRC-32.
function syn_crc8¶
Compute CRC-8 of a complete buffer.
Parameters:
dataData buffer.lenLength in bytes.
Returns:
CRC-8 value.
Macro Definition Documentation¶
define SYN_CRC16_CCITT_INIT¶
CRC-16 CCITT initial value.
define SYN_CRC16_MODBUS_INIT¶
CRC-16 Modbus initial value.
define SYN_CRC32_INIT¶
CRC-32 initial value.
define SYN_CRC8_INIT¶
CRC-8 initial value.
define SYN_CRC_USE_TABLE¶
Set to 1 for lookup-table CRC (fast), 0 for bit-by-bit (small).
The documentation for this class was generated from the following file src/syntropic/util/syn_crc.h