Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS

Functions

uint16_t crc16 (const uint8_t *src, size_t len, uint16_t polynomial, uint16_t initial_value, bool pad)
 Generic function for computing CRC 16. More...
 
uint8_t crc8 (const uint8_t *src, size_t len, uint8_t polynomial, uint8_t initial_value, bool reversed)
 Generic function for computing CRC 8. More...
 
uint16_t crc16_ccitt (uint16_t seed, const uint8_t *src, size_t len)
 Compute the CRC-16/CCITT checksum of a buffer. More...
 
uint16_t crc16_itu_t (uint16_t seed, const uint8_t *src, size_t len)
 Compute the CRC-16/XMODEM checksum of a buffer. More...
 
static uint16_t crc16_ansi (const uint8_t *src, size_t len)
 Compute ANSI variant of CRC 16. More...
 
uint32_t crc32_ieee (const uint8_t *data, size_t len)
 Generate IEEE conform CRC32 checksum. More...
 
uint32_t crc32_ieee_update (uint32_t crc, const uint8_t *data, size_t len)
 Update an IEEE conforming CRC32 checksum. More...
 
uint32_t crc32_c (uint32_t crc, const uint8_t *data, size_t len, bool first_pkt, bool last_pkt)
 Calculate CRC32C (Castagnoli) checksum. More...
 
uint8_t crc8_ccitt (uint8_t initial_value, const void *buf, size_t len)
 Compute CCITT variant of CRC 8. More...
 
uint8_t crc7_be (uint8_t seed, const uint8_t *src, size_t len)
 Compute the CRC-7 checksum of a buffer. More...
 

Detailed Description

Function Documentation

◆ crc16()

uint16_t crc16 ( const uint8_t src,
size_t  len,
uint16_t  polynomial,
uint16_t  initial_value,
bool  pad 
)

#include <include/sys/crc.h>

Generic function for computing CRC 16.

Compute CRC 16 by passing in the address of the input, the input length and polynomial used in addition to the initial value.

Parameters
srcInput bytes for the computation
lenLength of the input in bytes
polynomialThe polynomial to use omitting the leading x^16 coefficient
initial_valueInitial value for the CRC computation
padAdds padding with zeros at the end of input bytes
Returns
The computed CRC16 value

◆ crc16_ansi()

static uint16_t crc16_ansi ( const uint8_t src,
size_t  len 
)
inlinestatic

#include <include/sys/crc.h>

Compute ANSI variant of CRC 16.

ANSI variant of CRC 16 is using 0x8005 as its polynomial with the initial value set to 0xffff.

Parameters
srcInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC16 value

◆ crc16_ccitt()

uint16_t crc16_ccitt ( uint16_t  seed,
const uint8_t src,
size_t  len 
)

#include <include/sys/crc.h>

Compute the CRC-16/CCITT checksum of a buffer.

See ITU-T Recommendation V.41 (November 1988). Uses 0x1021 as the polynomial, reflects the input, and reflects the output.

To calculate the CRC across non-contiguous blocks use the return value from block N-1 as the seed for block N.

For CRC-16/CCITT, use 0 as the initial seed. Other checksums in the same family can be calculated by changing the seed and/or XORing the final value. Examples include:

  • X-25 (used in PPP): seed=0xffff, xor=0xffff, residual=0xf0b8
Note
API changed in Zephyr 1.11.
Parameters
seedValue to seed the CRC with
srcInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC16 value

◆ crc16_itu_t()

uint16_t crc16_itu_t ( uint16_t  seed,
const uint8_t src,
size_t  len 
)

#include <include/sys/crc.h>

Compute the CRC-16/XMODEM checksum of a buffer.

The MSB first version of ITU-T Recommendation V.41 (November 1988). Uses 0x1021 as the polynomial with no reflection.

To calculate the CRC across non-contiguous blocks use the return value from block N-1 as the seed for block N.

For CRC-16/XMODEM, use 0 as the initial seed. Other checksums in the same family can be calculated by changing the seed and/or XORing the final value. Examples include:

  • CCIITT-FALSE: seed=0xffff
  • GSM: seed=0, xorout=0xffff, residue=0x1d0f
Parameters
seedValue to seed the CRC with
srcInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC16 value

◆ crc32_c()

uint32_t crc32_c ( uint32_t  crc,
const uint8_t data,
size_t  len,
bool  first_pkt,
bool  last_pkt 
)

#include <include/sys/crc.h>

Calculate CRC32C (Castagnoli) checksum.

Parameters
crcCRC32C checksum that needs to be updated.
*dataPointer to data on which the CRC should be calculated.
lenData length.
first_pktWhether this is the first packet in the stream.
last_pktWhether this is the last packet in the stream.
Returns
CRC32 value.

◆ crc32_ieee()

uint32_t crc32_ieee ( const uint8_t data,
size_t  len 
)

#include <include/sys/crc.h>

Generate IEEE conform CRC32 checksum.

Parameters
*dataPointer to data on which the CRC should be calculated.
lenData length.
Returns
CRC32 value.

◆ crc32_ieee_update()

uint32_t crc32_ieee_update ( uint32_t  crc,
const uint8_t data,
size_t  len 
)

#include <include/sys/crc.h>

Update an IEEE conforming CRC32 checksum.

Parameters
crcCRC32 checksum that needs to be updated.
*dataPointer to data on which the CRC should be calculated.
lenData length.
Returns
CRC32 value.

◆ crc7_be()

uint8_t crc7_be ( uint8_t  seed,
const uint8_t src,
size_t  len 
)

#include <include/sys/crc.h>

Compute the CRC-7 checksum of a buffer.

See JESD84-A441. Used by the MMC protocol. Uses 0x09 as the polynomial with no reflection. The CRC is left justified, so bit 7 of the result is bit 6 of the CRC.

Parameters
seedValue to seed the CRC with
srcInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC7 value

◆ crc8()

uint8_t crc8 ( const uint8_t src,
size_t  len,
uint8_t  polynomial,
uint8_t  initial_value,
bool  reversed 
)

#include <include/sys/crc.h>

Generic function for computing CRC 8.

Compute CRC 8 by passing in the address of the input, the input length and polynomial used in addition to the initial value.

Parameters
srcInput bytes for the computation
lenLength of the input in bytes
polynomialThe polynomial to use omitting the leading x^8 coefficient
initial_valueInitial value for the CRC computation
reversedShould we use reflected/reversed values or not
Returns
The computed CRC8 value

◆ crc8_ccitt()

uint8_t crc8_ccitt ( uint8_t  initial_value,
const void buf,
size_t  len 
)

#include <include/sys/crc.h>

Compute CCITT variant of CRC 8.

Normal CCITT variant of CRC 8 is using 0x07.

Parameters
initial_valueInitial value for the CRC computation
bufInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC8 value