GPCRC - General Purpose CRC
Description
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 it is important to 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:
A CRC-16 Calculation:
A CRC-CCITT calculation:
Data Structures |
|
struct | GPCRC_Init_TypeDef |
CRC initialization structure.
|
|
Functions |
|
void | GPCRC_Init (GPCRC_TypeDef *gpcrc, const GPCRC_Init_TypeDef *init) |
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module.
|
|
void | GPCRC_Reset (GPCRC_TypeDef *gpcrc) |
Reset GPCRC registers to the hardware reset state.
|
|
void | GPCRC_Enable (GPCRC_TypeDef *gpcrc, bool enable) |
Enable/disable GPCRC.
|
|
void | GPCRC_Start (GPCRC_TypeDef *gpcrc) |
Issues a command to initialize CRC calculation.
|
|
void | GPCRC_InitValueSet (GPCRC_TypeDef *gpcrc, uint32_t initValue) |
Set the initialization value of the CRC.
|
|
void | GPCRC_InputU32 (GPCRC_TypeDef *gpcrc, uint32_t data) |
Writes a 32-bit value to the input data register of the CRC.
|
|
void | GPCRC_InputU16 (GPCRC_TypeDef *gpcrc, uint16_t data) |
Writes a 16-bit value to the input data register of the CRC.
|
|
void | GPCRC_InputU8 (GPCRC_TypeDef *gpcrc, uint8_t data) |
Writes an 8-bit value to the input data register of the CRC.
|
|
uint32_t | GPCRC_DataRead (GPCRC_TypeDef *gpcrc) |
Reads the data register of the CRC.
|
|
uint32_t | GPCRC_DataReadBitReversed (GPCRC_TypeDef *gpcrc) |
Reads the data register of the CRC bit reversed.
|
|
uint32_t | GPCRC_DataReadByteReversed (GPCRC_TypeDef *gpcrc) |
Reads the data register of the CRC byte reversed.
|
|
Macros |
|
#define | GPCRC_INIT_DEFAULT |
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.
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.
- Parameters
-
[in] gpcrc
A pointer to the GPCRC peripheral register block. [in] init
A pointer to the initialization structure used to configure the GPCRC.
◆ GPCRC_Reset()
void GPCRC_Reset | ( | GPCRC_TypeDef * |
gpcrc
|
) |
Reset GPCRC registers to the hardware reset state.
- Note
- The data registers are not reset by this function.
- Parameters
-
[in] gpcrc
A pointer to the GPCRC peripheral register block.
◆ GPCRC_Enable()
|
inline |
Enable/disable GPCRC.
- Parameters
-
[in] gpcrc
Pointer to GPCRC peripheral register block. [in] enable
True to enable GPCRC, false to disable.
◆ GPCRC_Start()
|
inline |
Issues a command to initialize CRC calculation.
Issues the command INIT in GPCRC_CMD that initializes CRC calculation by writing the initial values to the DATA register.
- Parameters
-
[in] gpcrc
Pointer to GPCRC peripheral register block.
◆ GPCRC_InitValueSet()
|
inline |
Set the initialization value of the CRC.
- Parameters
-
[in] initValue
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.
◆ GPCRC_InputU32()
|
inline |
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. CRC calculation is based on the provided input data using the configured CRC polynomial.
- Parameters
-
[in] gpcrc
Pointer to GPCRC peripheral register block. [in] data
Data to be written to the input data register.
◆ GPCRC_InputU16()
|
inline |
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. CRC calculation is based on the provided input data using the configured CRC polynomial.
- Parameters
-
[in] gpcrc
Pointer to GPCRC peripheral register block. [in] data
Data to be written to the input data register.
◆ GPCRC_InputU8()
|
inline |
Writes an 8-bit value to the input data register of the CRC.
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.
- Parameters
-
[in] gpcrc
Pointer to GPCRC peripheral register block. [in] data
Data to be written to the input data register.
◆ GPCRC_DataRead()
|
inline |
Reads the data register of the CRC.
Use this function to read the calculated CRC value.
- Parameters
-
[in] gpcrc
Pointer to GPCRC peripheral register block.
- Returns
- Content of the CRC data register.
◆ GPCRC_DataReadBitReversed()
|
inline |
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, bits [31:0] are reversed, when using a 16-bit polynomial, bits [15:0] are reversed.
- Parameters
-
[in] gpcrc
Pointer to GPCRC peripheral register block.
- Returns
- Content of the CRC data register bit reversed.
◆ GPCRC_DataReadByteReversed()
|
inline |
Reads the data register of the CRC byte reversed.
Use this function to read the calculated CRC value byte reversed.
- Parameters
-
[in] gpcrc
Pointer to GPCRC peripheral register block.
- Returns
- Content of the CRC data register byte reversed.
Macro Definition Documentation
◆ GPCRC_INIT_DEFAULT
#define GPCRC_INIT_DEFAULT |
Default configuration for GPCRC_Init_TypeDef structure.