EFM32 Pearl Gecko 12 Software Documentation
efm32pg12-doc-5.1.2
|
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's up to the user to choose a polynomial that fits the application. Commonly used 16-bit polynomial 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 it is important to call the GPCRC_Start function. This function will reset the 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. You can either write the input data into the input data register using the input functions GPCRC_InputU32, GPCRC_InputU16 and GPCRC_InputU8, or the user can setup the LDMA to transfer data directly to one of the GPCRC input data registers.
Examples of GPCRC usage:
A CRC-32 Calculation:
A CRC-16 Calculation:
A CRC-CCITT calculation:
Data Structures | |
struct | GPCRC_Init_TypeDef |
Macros | |
#define | GPCRC_INIT_DEFAULT |
Functions | |
__STATIC_INLINE uint32_t | GPCRC_DataRead (GPCRC_TypeDef *gpcrc) |
Reads the data register of the CRC. More... | |
__STATIC_INLINE uint32_t | GPCRC_DataReadBitReversed (GPCRC_TypeDef *gpcrc) |
Reads the data register of the CRC bit reversed. More... | |
__STATIC_INLINE uint32_t | GPCRC_DataReadByteReversed (GPCRC_TypeDef *gpcrc) |
Reads the data register of the CRC byte reversed. More... | |
__STATIC_INLINE void | GPCRC_Enable (GPCRC_TypeDef *gpcrc, bool enable) |
Enable/disable GPCRC. More... | |
void | GPCRC_Init (GPCRC_TypeDef *gpcrc, const GPCRC_Init_TypeDef *init) |
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module. More... | |
__STATIC_INLINE void | GPCRC_InitValueSet (GPCRC_TypeDef *gpcrc, uint32_t initValue) |
Set the initialization value of the CRC. More... | |
__STATIC_INLINE void | GPCRC_InputU16 (GPCRC_TypeDef *gpcrc, uint16_t data) |
Writes a 16 bit value to the input data register of the CRC. More... | |
__STATIC_INLINE void | GPCRC_InputU32 (GPCRC_TypeDef *gpcrc, uint32_t data) |
Writes a 32 bit value to the input data register of the CRC. More... | |
__STATIC_INLINE void | GPCRC_InputU8 (GPCRC_TypeDef *gpcrc, uint8_t data) |
Writes an 8 bit value to the input data register of the CRC. More... | |
void | GPCRC_Reset (GPCRC_TypeDef *gpcrc) |
Reset GPCRC registers to the hardware reset state. More... | |
__STATIC_INLINE void | GPCRC_Start (GPCRC_TypeDef *gpcrc) |
Issues a command to initialize the CRC calculation. More... | |
#define GPCRC_INIT_DEFAULT |
Default configuration for GPCRC_Init_TypeDef structure.
Definition at line 162 of file em_gpcrc.h.
__STATIC_INLINE uint32_t GPCRC_DataRead | ( | GPCRC_TypeDef * | gpcrc | ) |
Reads the data register of the CRC.
Use this function to read the calculated CRC value.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
Definition at line 300 of file em_gpcrc.h.
References GPCRC_TypeDef::DATA.
__STATIC_INLINE uint32_t GPCRC_DataReadBitReversed | ( | GPCRC_TypeDef * | gpcrc | ) |
Reads the data register of the CRC bit reversed.
Use this function to read the calculated CRC value bit reversed. When using a 32-bit polynomial then bits [31:0] are reversed, when using a 16-bit polynomial then bits [15:0] are reversed.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
Definition at line 320 of file em_gpcrc.h.
References GPCRC_TypeDef::DATAREV.
__STATIC_INLINE uint32_t GPCRC_DataReadByteReversed | ( | GPCRC_TypeDef * | gpcrc | ) |
Reads the data register of the CRC byte reversed.
Use this function to read the calculated CRC value byte reversed.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
Definition at line 338 of file em_gpcrc.h.
References GPCRC_TypeDef::DATABYTEREV.
__STATIC_INLINE 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. |
Definition at line 190 of file em_gpcrc.h.
References _GPCRC_CTRL_EN_SHIFT, BUS_RegBitWrite(), and GPCRC_TypeDef::CTRL.
void GPCRC_Init | ( | GPCRC_TypeDef * | gpcrc, |
const GPCRC_Init_TypeDef * | init | ||
) |
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module.
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.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
[in] | init | Pointer to initialization structure used to configure the GPCRC. |
Definition at line 73 of file em_gpcrc.c.
References _GPCRC_CTRL_AUTOINIT_SHIFT, _GPCRC_CTRL_BITREVERSE_SHIFT, _GPCRC_CTRL_BYTEMODE_SHIFT, _GPCRC_CTRL_BYTEREVERSE_SHIFT, _GPCRC_CTRL_EN_SHIFT, _GPCRC_POLY_POLY_MASK, GPCRC_Init_TypeDef::autoInit, GPCRC_Init_TypeDef::crcPoly, GPCRC_TypeDef::CTRL, GPCRC_Init_TypeDef::enable, GPCRC_Init_TypeDef::enableByteMode, GPCRC_CTRL_POLYSEL_16, GPCRC_CTRL_POLYSEL_CRC32, GPCRC_TypeDef::INIT, GPCRC_Init_TypeDef::initValue, GPCRC_TypeDef::POLY, GPCRC_Init_TypeDef::reverseBits, and GPCRC_Init_TypeDef::reverseByteOrder.
__STATIC_INLINE void GPCRC_InitValueSet | ( | GPCRC_TypeDef * | gpcrc, |
uint32_t | initValue | ||
) |
Set the initialization value of the CRC.
[in] | initValue | The value to use to initialize a CRC calculation. This value is moved into the data register when calling GPCRC_Start |
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
Definition at line 222 of file em_gpcrc.h.
References GPCRC_TypeDef::INIT.
__STATIC_INLINE void GPCRC_InputU16 | ( | GPCRC_TypeDef * | gpcrc, |
uint16_t | data | ||
) |
Writes a 16 bit value to the input data register of the CRC.
Use this function to write a 16 bit input data to the CRC. The CRC calculation is based on the provided input data using the configured CRC polynomial.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
[in] | data | Data to be written to the input data register. |
Definition at line 262 of file em_gpcrc.h.
References GPCRC_TypeDef::INPUTDATAHWORD.
__STATIC_INLINE void GPCRC_InputU32 | ( | GPCRC_TypeDef * | gpcrc, |
uint32_t | data | ||
) |
Writes a 32 bit value to the input data register of the CRC.
Use this function to write a 32 bit input data to the CRC. The CRC calculation is based on the provided input data using the configured CRC polynomial.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
[in] | data | Data to be written to the input data register. |
Definition at line 242 of file em_gpcrc.h.
References GPCRC_TypeDef::INPUTDATA.
__STATIC_INLINE void GPCRC_InputU8 | ( | GPCRC_TypeDef * | gpcrc, |
uint8_t | data | ||
) |
Writes an 8 bit value to the input data register of the CRC.
Use this function to write a 8 bit input data to the CRC. The CRC calculation is based on the provided input data using the configured CRC polynomial.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
[in] | data | Data to be written to the input data register. |
Definition at line 282 of file em_gpcrc.h.
References GPCRC_TypeDef::INPUTDATABYTE.
void GPCRC_Reset | ( | GPCRC_TypeDef * | gpcrc | ) |
Reset GPCRC registers to the hardware reset state.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
Definition at line 116 of file em_gpcrc.c.
References _GPCRC_CTRL_RESETVALUE, _GPCRC_INIT_RESETVALUE, _GPCRC_POLY_RESETVALUE, GPCRC_TypeDef::CTRL, GPCRC_TypeDef::INIT, and GPCRC_TypeDef::POLY.
__STATIC_INLINE void GPCRC_Start | ( | GPCRC_TypeDef * | gpcrc | ) |
Issues a command to initialize the CRC calculation.
This function issues the command INIT in GPCRC_CMD that initializes the CRC calculation by writing the initial values to the DATA register.
[in] | gpcrc | Pointer to GPCRC peripheral register block. |
Definition at line 206 of file em_gpcrc.h.
References GPCRC_TypeDef::CMD, and GPCRC_CMD_INIT.