High level interface for interacting with the CRC, which provides hardware accelerated CRC computations.
The CRC APIs are structured to enable usage in situations where the entire input data set is not available in memory at the same time. Therefore, each conversion consists of three steps:
The table below provides CRC parameters for some common CRC algorithms.
CRC algorithm Name | Len | Polynomial | Initial seed | Data REV | Data XOR | Rem REV | Remainder XOR | Expected CRC |
---|---|---|---|---|---|---|---|---|
CRC-6 / CDMA2000-A | 6 | 0x27 | 0x3F | false | 0 | false | 0x00 | 0x0D |
CRC-6 / CDMA2000-B | 6 | 0x07 | 0x3F | false | 0 | false | 0x00 | 0x3B |
CRC-6 / DARC | 6 | 0x19 | 0x00 | true | 0 | true | 0x00 | 0x26 |
CRC-6 / ITU | 6 | 0x03 | 0x00 | true | 0 | true | 0x00 | 0x06 |
CRC-8 / ITU | 8 | 0x07 | 0x00 | false | 0 | false | 0x55 | 0xA1 |
CRC-8 / MAXIM | 8 | 0x31 | 0x00 | true | 0 | true | 0x00 | 0xA1 |
CRC-8 / ROHC | 8 | 0x07 | 0xFF | true | 0 | true | 0x00 | 0xD0 |
CRC-8 / WCDMA | 8 | 0x9B | 0x00 | true | 0 | true | 0x00 | 0x25 |
CRC-16 / CCITT-0 | 16 | 0x1021 | 0xFFFF | false | 0 | false | 0x0000 | 0x29B1 |
CRC-16 / CDMA2000 | 16 | 0xC867 | 0xFFFF | false | 0 | false | 0x0000 | 0x4C06 |
CRC-32 | 32 | 0x04C11DB7 | 0xFFFFFFFF | true | 0 | true | 0xFFFFFFFF | 0xCBF43926 |
CRC-32 / BZIP2 | 32 | 0x04C11DB7 | 0xFFFFFFFF | false | 0 | false | 0xFFFFFFFF | 0xFC891918 |
See crc_algorithm_t and Snippet1: CRC Generation for more details.
cyhal_crc_init initializes the CRC generator and passes the pointer to the CRC block through the obj object of type cyhal_crc_t.
The following snippet initializes a CRC generator and computes the CRC for a sample message.
API Reference | |
CRC HAL Results | |
CRC specific return codes. | |
Data Structures | |
struct | crc_algorithm_t |
CRC algorithm parameters. More... | |
Functions | |
cy_rslt_t | cyhal_crc_init (cyhal_crc_t *obj) |
Initialize the CRC generator. More... | |
void | cyhal_crc_free (cyhal_crc_t *obj) |
Release the CRC generator. More... | |
cy_rslt_t | cyhal_crc_start (cyhal_crc_t *obj, const crc_algorithm_t *algorithm) |
The CRC block is setup to perform CRC computation. More... | |
cy_rslt_t | cyhal_crc_compute (const cyhal_crc_t *obj, const uint8_t *data, size_t length) |
Computes the CRC for the given data and accumulates the CRC with the CRC generated from previous calls. More... | |
cy_rslt_t | cyhal_crc_finish (const cyhal_crc_t *obj, uint32_t *crc) |
Finalizes the CRC computation and returns the CRC for the complete set of data passed through a single call or multiple calls to cyhal_crc_compute. More... | |
struct crc_algorithm_t |
cy_rslt_t cyhal_crc_init | ( | cyhal_crc_t * | obj | ) |
Initialize the CRC generator.
This function reserves the CRYPTO block for CRC calculations.
[out] | obj | Pointer to a CRC generator object. The caller must allocate the memory for this object but the init function will initialize its contents. |
Returns CY_RSLT_SUCCESS if the operation was successful. Refer Snippet1: CRC Generation for more information.
void cyhal_crc_free | ( | cyhal_crc_t * | obj | ) |
Release the CRC generator.
[in,out] | obj | The CRC generator object |
cy_rslt_t cyhal_crc_start | ( | cyhal_crc_t * | obj, |
const crc_algorithm_t * | algorithm | ||
) |
The CRC block is setup to perform CRC computation.
[in,out] | obj | The CRC generator object |
[in] | algorithm | The CRC algorithm to use for computations Refer crc_algorithm_t. |
Returns CY_RSLT_SUCCESS if the operation was successful.
cy_rslt_t cyhal_crc_compute | ( | const cyhal_crc_t * | obj, |
const uint8_t * | data, | ||
size_t | length | ||
) |
Computes the CRC for the given data and accumulates the CRC with the CRC generated from previous calls.
This function can be called multiple times to provide additional data.
[in] | obj | The CRC generator object |
[in] | data | The input data |
[in] | length | The number of bytes in the data |
Returns CY_RSLT_SUCCESS if the operation was successful.
cy_rslt_t cyhal_crc_finish | ( | const cyhal_crc_t * | obj, |
uint32_t * | crc | ||
) |
Finalizes the CRC computation and returns the CRC for the complete set of data passed through a single call or multiple calls to cyhal_crc_compute.
[in] | obj | The CRC generator object |
[out] | crc | The computed CRC |
Returns CY_RSLT_SUCCESS if the operation was successful.