Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Enumerations

enum  crc_type {
  CRC4 , CRC4_TI , CRC7_BE , CRC8 ,
  CRC8_CCITT , CRC8_ROHC , CRC16 , CRC16_ANSI ,
  CRC16_CCITT , CRC16_ITU_T , CRC24_PGP , CRC32_C ,
  CRC32_IEEE
}
 CRC algorithm enumeration. More...
 

Functions

uint16_t crc16 (uint16_t poly, uint16_t seed, const uint8_t *src, size_t len)
 Generic function for computing a CRC-16 without input or output reflection.
 
uint16_t crc16_reflect (uint16_t poly, uint16_t seed, const uint8_t *src, size_t len)
 Generic function for computing a CRC-16 with input and output reflection.
 
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.
 
uint16_t crc16_ccitt (uint16_t seed, const uint8_t *src, size_t len)
 Compute the checksum of a buffer with polynomial 0x1021, reflecting input and output.
 
uint16_t crc16_itu_t (uint16_t seed, const uint8_t *src, size_t len)
 Compute the checksum of a buffer with polynomial 0x1021, no reflection of input or output.
 
static uint16_t crc16_ansi (const uint8_t *src, size_t len)
 Compute the ANSI (or Modbus) variant of CRC-16.
 
uint32_t crc32_ieee (const uint8_t *data, size_t len)
 Generate IEEE conform CRC32 checksum.
 
uint32_t crc32_ieee_update (uint32_t crc, const uint8_t *data, size_t len)
 Update an IEEE conforming CRC32 checksum.
 
uint32_t crc32_c (uint32_t crc, const uint8_t *data, size_t len, bool first_pkt, bool last_pkt)
 Calculate CRC32C (Castagnoli) checksum.
 
uint8_t crc8_ccitt (uint8_t initial_value, const void *buf, size_t len)
 Compute CCITT variant of CRC 8.
 
uint8_t crc8_rohc (uint8_t initial_value, const void *buf, size_t len)
 Compute ROHC variant of CRC 8.
 
uint8_t crc7_be (uint8_t seed, const uint8_t *src, size_t len)
 Compute the CRC-7 checksum of a buffer.
 
uint8_t crc4_ti (uint8_t seed, const uint8_t *src, size_t len)
 Compute the CRC-4 checksum of a buffer.
 
uint8_t crc4 (const uint8_t *src, size_t len, uint8_t polynomial, uint8_t initial_value, bool reversed)
 Generic function for computing CRC 4.
 
uint32_t crc24_pgp (const uint8_t *data, size_t len)
 Generate an OpenPGP CRC-24 checksum as defined in RFC 4880 section 6.1.
 
uint32_t crc24_pgp_update (uint32_t crc, const uint8_t *data, size_t len)
 Update an OpenPGP CRC-24 checksum.
 
static uint32_t crc_by_type (enum crc_type type, const uint8_t *src, size_t len, uint32_t seed, uint32_t poly, bool reflect, bool first, bool last)
 Compute a CRC checksum, in a generic way.
 

Detailed Description

Enumeration Type Documentation

◆ crc_type

enum crc_type

#include <zephyr/sys/crc.h>

CRC algorithm enumeration.

These values should be used with the CRC dispatch function.

Enumerator
CRC4 

Use crc4.

CRC4_TI 

Use crc4_ti.

CRC7_BE 

Use crc7_be.

CRC8 

Use crc8.

CRC8_CCITT 

Use crc8_ccitt.

CRC8_ROHC 

Use crc8_rohc.

CRC16 

Use crc16.

CRC16_ANSI 

Use crc16_ansi.

CRC16_CCITT 

Use crc16_ccitt.

CRC16_ITU_T 

Use crc16_itu_t.

CRC24_PGP 

Use crc24_pgp.

CRC32_C 

Use crc32_c.

CRC32_IEEE 

Use crc32_ieee.

Function Documentation

◆ crc16()

uint16_t crc16 ( uint16_t poly,
uint16_t seed,
const uint8_t * src,
size_t len )

#include <zephyr/sys/crc.h>

Generic function for computing a CRC-16 without input or output reflection.

Compute CRC-16 by passing in the address of the input, the input length and polynomial used in addition to the initial value. This is O(n*8) where n is the length of the buffer provided. No reflection is performed.

Note
If you are planning to use a CRC based on poly 0x1012 the functions crc16_itu_t() is faster and thus recommended over this one.
Parameters
polyThe polynomial to use omitting the leading x^16 coefficient
seedInitial value for the CRC computation
srcInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC16 value (without any XOR applied to it)

◆ crc16_ansi()

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

#include <zephyr/sys/crc.h>

Compute the ANSI (or Modbus) variant of CRC-16.

The ANSI variant of CRC-16 uses 0x8005 (0xA001 reflected) 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 <zephyr/sys/crc.h>

Compute the checksum of a buffer with polynomial 0x1021, reflecting input and output.

This function is able to calculate any CRC that uses 0x1021 as it polynomial and requires reflecting both the input and the output. It is a fast variant that runs in O(n) time, where n is the length of the input buffer.

The following checksums can, among others, be calculated by this function, depending on the value provided for the initial seed and the value the final calculated CRC is XORed with:

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

See ITU-T Recommendation V.41 (November 1988).

Parameters
seedValue to seed the CRC with
srcInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC16 value (without any XOR applied to it)

◆ crc16_itu_t()

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

#include <zephyr/sys/crc.h>

Compute the checksum of a buffer with polynomial 0x1021, no reflection of input or output.

This function is able to calculate any CRC that uses 0x1021 as it polynomial and requires no reflection on both the input and the output. It is a fast variant that runs in O(n) time, where n is the length of the input buffer.

The following checksums can, among others, be calculated by this function, depending on the value provided for the initial seed and the value the final calculated CRC is XORed with:

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

See ITU-T Recommendation V.41 (November 1988) (MSB first).

Parameters
seedValue to seed the CRC with
srcInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC16 value (without any XOR applied to it)

◆ crc16_reflect()

uint16_t crc16_reflect ( uint16_t poly,
uint16_t seed,
const uint8_t * src,
size_t len )

#include <zephyr/sys/crc.h>

Generic function for computing a CRC-16 with input and output reflection.

Compute CRC-16 by passing in the address of the input, the input length and polynomial used in addition to the initial value. This is O(n*8) where n is the length of the buffer provided. Both input and output are reflected.

Note
If you are planning to use a CRC based on poly 0x1012 the function crc16_ccitt() is faster and thus recommended over this one.

The following checksums can, among others, be calculated by this function, depending on the value provided for the initial seed and the value the final calculated CRC is XORed with:

Parameters
polyThe polynomial to use omitting the leading x^16 coefficient. Important: please reflect the poly. For example, use 0xA001 instead of 0x8005 for CRC-16-MODBUS.
seedInitial value for the CRC computation
srcInput bytes for the computation
lenLength of the input in bytes
Returns
The computed CRC16 value (without any XOR applied to it)

◆ crc24_pgp()

uint32_t crc24_pgp ( const uint8_t * data,
size_t len )

#include <zephyr/sys/crc.h>

Generate an OpenPGP CRC-24 checksum as defined in RFC 4880 section 6.1.

Parameters
dataA pointer to the data on which the CRC will be calculated.
lenData length in bytes.
Returns
The CRC-24 value.

◆ crc24_pgp_update()

uint32_t crc24_pgp_update ( uint32_t crc,
const uint8_t * data,
size_t len )

#include <zephyr/sys/crc.h>

Update an OpenPGP CRC-24 checksum.

Parameters
crcThe CRC-24 checksum that needs to be updated. The full 32-bit value of the CRC needs to be used between calls, do not mask the value to keep only the last 24 bits.
dataA pointer to the data on which the CRC will be calculated.
lenData length in bytes.
Returns
The CRC-24 value. When the last buffer of data has been processed, mask the value with CRC24_FINAL_VALUE_MASK to keep only the meaningful 24 bits of the CRC result.

◆ crc32_c()

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

#include <zephyr/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 <zephyr/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 <zephyr/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.

◆ crc4()

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

#include <zephyr/sys/crc.h>

Generic function for computing CRC 4.

Compute CRC 4 by passing in the address of the input, the input length and polynomial used in addition to the initial value. The input buffer must be aligned to a whole byte. It is guaranteed that 4 most significant bits of the result will be set to zero.

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

◆ crc4_ti()

uint8_t crc4_ti ( uint8_t seed,
const uint8_t * src,
size_t len )

#include <zephyr/sys/crc.h>

Compute the CRC-4 checksum of a buffer.

Used by the TMAG5170 sensor. Uses 0x03 as the polynomial with no reflection. 4 most significant bits of the CRC result will be set to zero.

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

◆ crc7_be()

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

#include <zephyr/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 <zephyr/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 <zephyr/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

◆ crc8_rohc()

uint8_t crc8_rohc ( uint8_t initial_value,
const void * buf,
size_t len )

#include <zephyr/sys/crc.h>

Compute ROHC variant of CRC 8.

ROHC (Robust Header Compression) variant of CRC 8. Uses 0x07 as the polynomial with reflection.

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

◆ crc_by_type()

static uint32_t crc_by_type ( enum crc_type type,
const uint8_t * src,
size_t len,
uint32_t seed,
uint32_t poly,
bool reflect,
bool first,
bool last )
inlinestatic

#include <zephyr/sys/crc.h>

Compute a CRC checksum, in a generic way.

This is a dispatch function that calls the individual CRC routine determined by type.

For 7, 8, 16 and 24-bit CRCs, the relevant seed and poly values should be passed in via the least-significant byte(s).

Similarly, for 7, 8, 16 and 24-bit CRCs, the relevant result is stored in the least-significant byte(s) of the returned value.

Parameters
typeCRC algorithm to use.
srcInput bytes for the computation
lenLength of the input in bytes
seedValue to seed the CRC with
polyThe polynomial to use omitting the leading coefficient
reflectShould we use reflected/reversed values or not
firstWhether this is the first packet in the stream.
lastWhether this is the last packet in the stream.
Returns
uint32_t the computed CRC value