Macros | Functions
Sw_crc_api

Macros

#define CRC8_ITER(crc, data)   g_pui8Crc8CCITT[(uint8_t)((crc) ^ (data))]
 
#define CRC16_ITER(crc, data)
 
#define CRC32_ITER(crc, data)
 

Functions

uint8_t Crc8CCITT (uint8_t ui8Crc, const uint8_t *pui8Data, uint32_t ui32Count)
 
uint16_t Crc16 (uint16_t ui16Crc, const uint8_t *pui8Data, uint32_t ui32Count)
 
uint16_t Crc16Array (uint32_t ui32WordLen, const uint32_t *pui32Data)
 
void Crc16Array3 (uint32_t ui32WordLen, const uint32_t *pui32Data, uint16_t *pui16Crc3)
 
uint32_t Crc32 (uint32_t ui32Crc, const uint8_t *pui8Data, uint32_t ui32Count)
 

Detailed Description

Macro Definition Documentation

§ CRC8_ITER

#define CRC8_ITER (   crc,
  data 
)    g_pui8Crc8CCITT[(uint8_t)((crc) ^ (data))]

Referenced by Crc8CCITT().

§ CRC16_ITER

#define CRC16_ITER (   crc,
  data 
)
Value:
(((crc) >> 8) ^ \
g_pui16Crc16[(uint8_t)((crc) ^ (data))])

Referenced by Crc16(), and Crc16Array3().

§ CRC32_ITER

#define CRC32_ITER (   crc,
  data 
)
Value:
(((crc) >> 8) ^ \
g_pui32Crc32[(uint8_t)((crc & 0xFF) ^ \
(data))])

Referenced by Crc32().

Function Documentation

§ Crc8CCITT()

uint8_t Crc8CCITT ( uint8_t  ui8Crc,
const uint8_t *  pui8Data,
uint32_t  ui32Count 
)

Calculates the CRC-8-CCITT of an array of bytes.

Parameters
ui8Crcis the starting CRC-8-CCITT value.
pui8Datais a pointer to the data buffer.
ui32Countis the number of bytes in the data buffer.

This function is used to calculate the CRC-8-CCITT of the input buffer. The CRC-8-CCITT is computed in a running fashion, meaning that the entire data block that is to have its CRC-8-CCITT computed does not need to be supplied all at once. If the input buffer contains the entire block of data, then ui8Crc should be set to 0. If, however, the entire block of data is not available, then ui8Crc should be set to 0 for the first portion of the data, and then the returned value should be passed back in as ui8Crc for the next portion of the data.

For example, to compute the CRC-8-CCITT of a block that has been split into three pieces, use the following:

//!     ui8Crc = Crc8CCITT(0, pui8Data1, ui32Len1);
//!     ui8Crc = Crc8CCITT(ui8Crc, pui8Data2, ui32Len2);
//!     ui8Crc = Crc8CCITT(ui8Crc, pui8Data3, ui32Len3);
//! 
Computing a CRC-8-CCITT in a running fashion is useful in cases where the
data is arriving via a serial link (for example) and is therefore not all
available at one time.

\return The CRC-8-CCITT of the input data.  

References CRC8_ITER.

§ Crc16()

uint16_t Crc16 ( uint16_t  ui16Crc,
const uint8_t *  pui8Data,
uint32_t  ui32Count 
)

Calculates the CRC-16 of an array of bytes.

Parameters
ui16Crcis the starting CRC-16 value.
pui8Datais a pointer to the data buffer.
ui32Countis the number of bytes in the data buffer.

This function is used to calculate the CRC-16 of the input buffer. The CRC-16 is computed in a running fashion, meaning that the entire data block that is to have its CRC-16 computed does not need to be supplied all at once. If the input buffer contains the entire block of data, then ui16Crc should be set to 0. If, however, the entire block of data is not available, then ui16Crc should be set to 0 for the first portion of the data, and then the returned value should be passed back in as ui16Crc for the next portion of the data.

For example, to compute the CRC-16 of a block that has been split into three pieces, use the following:

//!     ui16Crc = Crc16(0, pui8Data1, ui32Len1);
//!     ui16Crc = Crc16(ui16Crc, pui8Data2, ui32Len2);
//!     ui16Crc = Crc16(ui16Crc, pui8Data3, ui32Len3);
//! 
Computing a CRC-16 in a running fashion is useful in cases where the data
is arriving via a serial link (for example) and is therefore not all
available at one time.

\return The CRC-16 of the input data.  

References CRC16_ITER.

Referenced by Crc16Array().

§ Crc16Array()

uint16_t Crc16Array ( uint32_t  ui32WordLen,
const uint32_t *  pui32Data 
)

Calculates the CRC-16 of an array of words.

Parameters
ui32WordLenis the length of the array in words (the number of bytes divided by 4).
pui32Datais a pointer to the data buffer.

This function is a wrapper around the running CRC-16 function, providing the CRC-16 for a single block of data.

Returns
The CRC-16 of the input data.

References Crc16().

§ Crc16Array3()

void Crc16Array3 ( uint32_t  ui32WordLen,
const uint32_t *  pui32Data,
uint16_t *  pui16Crc3 
)

Calculates three CRC-16s of an array of words.

Parameters
ui32WordLenis the length of the array in words (the number of bytes divided by 4).
pui32Datais a pointer to the data buffer.
pui16Crc3is a pointer to an array in which to place the three CRC-16 values.

This function is used to calculate three CRC-16s of the input buffer; the first uses every byte from the array, the second uses only the even-index bytes from the array (in other words, bytes 0, 2, 4, etc.), and the third uses only the odd-index bytes from the array (in other words, bytes 1, 3, 5, etc.).

Returns
None

References CRC16_ITER.

§ Crc32()

uint32_t Crc32 ( uint32_t  ui32Crc,
const uint8_t *  pui8Data,
uint32_t  ui32Count 
)

Calculates the CRC-32 of an array of bytes.

Parameters
ui32Crcis the starting CRC-32 value.
pui8Datais a pointer to the data buffer.
ui32Countis the number of bytes in the data buffer.

This function is used to calculate the CRC-32 of the input buffer. The CRC-32 is computed in a running fashion, meaning that the entire data block that is to have its CRC-32 computed does not need to be supplied all at once. If the input buffer contains the entire block of data, then ui32Crc should be set to 0xFFFFFFFF. If, however, the entire block of data is not available, then ui32Crc should be set to 0xFFFFFFFF for the first portion of the data, and then the returned value should be passed back in as ui32Crc for the next portion of the data. Once all data has been passed to the function, the final CRC-32 can be obtained by inverting the last returned value.

For example, to compute the CRC-32 of a block that has been split into three pieces, use the following:

//!     ui32Crc = Crc32(0xFFFFFFFF, pui8Data1, ui32Len1);
//!     ui32Crc = Crc32(ui32Crc, pui8Data2, ui32Len2);
//!     ui32Crc = Crc32(ui32Crc, pui8Data3, ui32Len3);
//!     ui32Crc ^= 0xFFFFFFFF;
//! 
Computing a CRC-32 in a running fashion is useful in cases where the data
is arriving via a serial link (for example) and is therefore not all
available at one time.

\return The accumulated CRC-32 of the input data.  

References CRC32_ITER.

Referenced by EMACHashFilterBitCalculate(), and EMACVLANHashFilterBitCalculate().

Copyright 2017, Texas Instruments Incorporated