GPCRC - General Purpose CRC#
General Purpose Cyclic Redundancy Check (GPCRC) API.
The GPCRC API functions provide full support for the GPCRC peripheral.
The GPCRC module is a peripheral that implements a Cyclic Redundancy Check (CRC) function. It supports a fixed 32-bit polynomial and a user configurable 16-bit polynomial. The fixed 32-bit polynomial is the commonly used IEEE 802.3 polynomial 0x04C11DB7.
When using a 16-bit polynomial it is up to the user to choose a polynomial that fits the application. Commonly used 16-bit polynomials are 0x1021 (CCITT-16), 0x3D65 (IEC16-MBus), and 0x8005 (ZigBee, 802.15.4, and USB). See this link for other polynomials: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
Before a CRC calculation can begin, call the sl_hal_gpcrc_start function. This function will reset CRC calculation by copying the configured initialization value over to the CRC data register.
There are two ways of sending input data to the GPCRC. Either write the input data into the input data register using input functions sl_hal_gpcrc_write_input_32bit, sl_hal_gpcrc_write_input_16bit and sl_hal_gpcrc_write_input_8bit, or the user can configure LDMA - Linked DMA to transfer data directly to one of the GPCRC input data registers.
Example#
The following sections provide examples on how to use the GPCRC module for various CRC calculation standards.
// Example 1: CRC-32 calculation
void gpcrc_example_crc32(void)
{
uint32_t checksum;
// Initialize GPCRC, 32-bit fixed polynomial is default
sl_hal_gpcrc_init_t init = SL_HAL_GPCRC_INIT_DEFAULT;
init.init_value = 0xFFFFFFFF; // Standard CRC-32 init value
sl_hal_gpcrc_init(GPCRC0, &init);
sl_hal_gpcrc_start(GPCRC0);
sl_hal_gpcrc_write_input_8bit(GPCRC0, 0xC5);
// According to the CRC-32 specification, the end result should be inverted
checksum = ~sl_hal_gpcrc_read_data(GPCRC0);
// The checksum is now 0x390CD9B2
}
// Example 2: CRC-16 calculation with polynomial 0x8005
void gpcrc_example_crc16(void)
{
uint16_t checksum;
// Initialize GPCRC with the 16-bit polynomial 0x8005
sl_hal_gpcrc_init_t init = SL_HAL_GPCRC_INIT_DEFAULT;
init.crc_poly = 0x8005;
sl_hal_gpcrc_init(GPCRC0, &init);
sl_hal_gpcrc_start(GPCRC0);
sl_hal_gpcrc_write_input_8bit(GPCRC0, 0xAB);
checksum = (uint16_t) sl_hal_gpcrc_read_data(GPCRC0);
// The checksum is now 0xBF41
}
Modules#
Functions#
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module.
Reset GPCRC registers to the hardware reset state.
Enable GPCRC.
Disable GPCRC.
Issue a command to initialize the CRC calculation.
Set the initialization value of the CRC.
Write a 32-bit value to the input data register of the CRC.
Write a 16-bit value to the input data register of the CRC.
Write an 8-bit value to the CRC input data register.
Read the CRC data register.
Read the data register of the CRC bit reversed.
Read the data register of the CRC byte reversed.
Macros#
The fixed 32-bit polynomial commonly used by IEEE 802.3.
Check if GPCRC instance is valid.
Default configuration for sl_hal_gpcrc_init_t structure.
Function Documentation#
sl_hal_gpcrc_init#
void sl_hal_gpcrc_init (GPCRC_TypeDef * gpcrc, const sl_hal_gpcrc_init_t * init)
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | A pointer to the GPCRC peripheral register block. |
const sl_hal_gpcrc_init_t * | [in] | init | A pointer to the initialization structure used to configure the GPCRC. |
Use this function to configure the operational parameters of the GPCRC, such as the polynomial to use and how the input should be preprocessed before entering the CRC calculation.
Note
This function will not copy the initialization value to the data register to prepare for a new CRC calculation. Either call sl_hal_gpcrc_start before each calculation or by use the autoInit functionality.
sl_hal_gpcrc_reset#
void sl_hal_gpcrc_reset (GPCRC_TypeDef * gpcrc)
Reset GPCRC registers to the hardware reset state.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | A pointer to the GPCRC peripheral register block. |
Note
The data registers are not reset by this function.
sl_hal_gpcrc_enable#
void sl_hal_gpcrc_enable (GPCRC_TypeDef * gpcrc)
Enable GPCRC.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
sl_hal_gpcrc_disable#
void sl_hal_gpcrc_disable (GPCRC_TypeDef * gpcrc)
Disable GPCRC.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
sl_hal_gpcrc_start#
void sl_hal_gpcrc_start (GPCRC_TypeDef * gpcrc)
Issue a command to initialize the CRC calculation.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
Issues the command INIT in GPCRC_CMD that initializes the CRC calculation by writing the initial values to the DATA register.
sl_hal_gpcrc_set_init_value#
void sl_hal_gpcrc_set_init_value (GPCRC_TypeDef * gpcrc, uint32_t init_value)
Set the initialization value of the CRC.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
uint32_t | [in] | init_value | Value to use to initialize a CRC calculation. This value is moved into the data register when calling sl_hal_gpcrc_start. |
sl_hal_gpcrc_write_input_32bit#
void sl_hal_gpcrc_write_input_32bit (GPCRC_TypeDef * gpcrc, uint32_t data)
Write a 32-bit value to the input data register of the CRC.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
uint32_t | [in] | data | Data to be written to the input data register. |
Use this function to write a 32-bit input data to the CRC. CRC calculation is based on the provided input data using the configured CRC polynomial.
sl_hal_gpcrc_write_input_16bit#
void sl_hal_gpcrc_write_input_16bit (GPCRC_TypeDef * gpcrc, uint16_t data)
Write a 16-bit value to the input data register of the CRC.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
uint16_t | [in] | data | Data to be written to the input data register. |
Use this function to write a 16 bit input data to the CRC. CRC calculation is based on the provided input data using the configured CRC polynomial.
sl_hal_gpcrc_write_input_8bit#
void sl_hal_gpcrc_write_input_8bit (GPCRC_TypeDef * gpcrc, uint8_t data)
Write an 8-bit value to the CRC input data register.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
uint8_t | [in] | data | Data to be written to the input data register. |
Use this function to write an 8-bit input data to the CRC. CRC calculation is based on the provided input data using the configured CRC polynomial.
sl_hal_gpcrc_read_data#
uint32_t sl_hal_gpcrc_read_data (GPCRC_TypeDef * gpcrc)
Read the CRC data register.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
Use this function to read the calculated CRC value.
Returns
Content of the CRC data register.
sl_hal_gpcrc_read_data_bit_reversed#
uint32_t sl_hal_gpcrc_read_data_bit_reversed (GPCRC_TypeDef * gpcrc)
Read the data register of the CRC bit reversed.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
Use this function to read the calculated CRC value bit reversed. When using a 32-bit polynomial, bits [31:0] are reversed, when using a 16-bit polynomial, bits [15:0] are reversed.
Returns
Content of the CRC data register bit reversed.
sl_hal_gpcrc_read_data_byte_reversed#
uint32_t sl_hal_gpcrc_read_data_byte_reversed (GPCRC_TypeDef * gpcrc)
Read the data register of the CRC byte reversed.
Type | Direction | Argument Name | Description |
---|---|---|---|
GPCRC_TypeDef * | [in] | gpcrc | Pointer to GPCRC peripheral register block. |
Use this function to read the calculated CRC value byte reversed.
Returns
Content of the CRC data register byte reversed.