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 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 GPCRC_InputU32, GPCRC_InputU16 and GPCRC_InputU8, or the user can configure LDMA - Linked DMA to transfer data directly to one of the GPCRC input data registers.
Examples of GPCRC usage:
A CRC-32 Calculation:
#if !defined(_SILICON_LABS_32B_SERIES_2)
/* The GPCRC is a high frequency peripheral so we need to enable the
* HFPER clock in addition to the GPCRC clock. */
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPCRC, true);
#endif
uint32_t checksum;
/* Initialize GPCRC, 32-bit fixed polynomial is default */
GPCRC_Init_TypeDef init = GPCRC_INIT_DEFAULT;
init.initValue = 0xFFFFFFFF; // Standard CRC-32 init value
GPCRC_Init(GPCRC, &init);
GPCRC_Start(GPCRC);
GPCRC_InputU8(GPCRC, 0xC5);
/* According to the CRC-32 specification, the end result should be inverted */
checksum = ~GPCRC_DataRead(GPCRC);
/* The checksum is now 0x390CD9B2 */
A CRC-16 Calculation:
#if !defined(_SILICON_LABS_32B_SERIES_2)
/* The GPCRC is a high frequency peripheral so we need to enable the
* HFPER clock in addition to the GPCRC clock. */
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPCRC, true);
#endif
uint16_t checksum;
/* Initialize GPCRC with the 16-bit polynomial 0x8005. */
GPCRC_Init_TypeDef init = GPCRC_INIT_DEFAULT;
init.crcPoly = 0x8005;
GPCRC_Init(GPCRC, &init);
GPCRC_Start(GPCRC);
GPCRC_InputU8(GPCRC, 0xAB);
checksum = (uint16_t) GPCRC_DataRead(GPCRC);
/* The checksum is now 0xBF41 */
A CRC-CCITT calculation:
#if !defined(_SILICON_LABS_32B_SERIES_2)
/* The GPCRC is a high frequency peripheral so we need to enable the
* HFPER clock in addition to the GPCRC clock. */
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPCRC, true);
#endif
/* Initialize GPCRC with the 16-bit CRC-CCIT polynomial 0x1021 and use
* the inital value of 0xFFFF. */
GPCRC_Init_TypeDef init = GPCRC_INIT_DEFAULT;
init.crcPoly = 0x1021;
init.initValue = 0xFFFF;
init.reverseBits = true;
GPCRC_Init(GPCRC, &init);
char * input = "123456789";
GPCRC_Start(GPCRC);
for (size_t i = 0; i < strlen(input); i++) {
GPCRC_InputU8(GPCRC, (uint8_t) input[i]);
}
uint16_t checksum = (uint16_t)GPCRC_DataReadBitReversed(GPCRC);
/* checksum is now 0x29B1 */
Modules#
Functions#
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module.
Reset GPCRC registers to the hardware reset state.
Enable/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#
Default configuration for GPCRC_Init_TypeDef structure.
Function Documentation#
GPCRC_Init#
void GPCRC_Init (GPCRC_TypeDef * gpcrc, const GPCRC_Init_TypeDef * init)
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module.
[in] | gpcrc | A pointer to the GPCRC peripheral register block. |
[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 GPCRC_Start before each calculation or by use the autoInit functionality.
67
of file platform/emlib/src/em_gpcrc.c
GPCRC_Reset#
void GPCRC_Reset (GPCRC_TypeDef * gpcrc)
Reset GPCRC registers to the hardware reset state.
[in] | gpcrc | A pointer to the GPCRC peripheral register block. |
Note
The data registers are not reset by this function.
129
of file platform/emlib/src/em_gpcrc.c
GPCRC_Enable#
void GPCRC_Enable (GPCRC_TypeDef * gpcrc, bool enable)
Enable/disable GPCRC.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
[in] | enable | True to enable GPCRC, false to disable. |
182
of file platform/emlib/inc/em_gpcrc.h
GPCRC_Start#
void GPCRC_Start (GPCRC_TypeDef * gpcrc)
Issue a command to initialize the CRC calculation.
[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.
202
of file platform/emlib/inc/em_gpcrc.h
GPCRC_InitValueSet#
void GPCRC_InitValueSet (GPCRC_TypeDef * gpcrc, uint32_t initValue)
Set the initialization value of the CRC.
[in] | gpcrc | Value to use to initialize a CRC calculation. This value is moved into the data register when calling GPCRC_Start |
[in] | initValue | Pointer to GPCRC peripheral register block. |
218
of file platform/emlib/inc/em_gpcrc.h
GPCRC_InputU32#
void GPCRC_InputU32 (GPCRC_TypeDef * gpcrc, uint32_t data)
Write a 32-bit value to the input data register of the CRC.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
[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.
238
of file platform/emlib/inc/em_gpcrc.h
GPCRC_InputU16#
void GPCRC_InputU16 (GPCRC_TypeDef * gpcrc, uint16_t data)
Write a 16-bit value to the input data register of the CRC.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
[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.
258
of file platform/emlib/inc/em_gpcrc.h
GPCRC_InputU8#
void GPCRC_InputU8 (GPCRC_TypeDef * gpcrc, uint8_t data)
Write an 8-bit value to the CRC input data register.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
[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.
278
of file platform/emlib/inc/em_gpcrc.h
GPCRC_DataRead#
uint32_t GPCRC_DataRead (GPCRC_TypeDef * gpcrc)
Read the CRC data register.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
Use this function to read the calculated CRC value.
Returns
Content of the CRC data register.
296
of file platform/emlib/inc/em_gpcrc.h
GPCRC_DataReadBitReversed#
uint32_t GPCRC_DataReadBitReversed (GPCRC_TypeDef * gpcrc)
Read the data register of the CRC bit reversed.
[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.
316
of file platform/emlib/inc/em_gpcrc.h
GPCRC_DataReadByteReversed#
uint32_t GPCRC_DataReadByteReversed (GPCRC_TypeDef * gpcrc)
Read the data register of the CRC byte reversed.
[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.
334
of file platform/emlib/inc/em_gpcrc.h
Macro Definition Documentation#
GPCRC_INIT_DEFAULT#
#define GPCRC_INIT_DEFAULTValue:
Default configuration for GPCRC_Init_TypeDef structure.
154
of file platform/emlib/inc/em_gpcrc.h