MCUXpresso SDK API Reference Manual  Rev 2.12.1
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
CRC: Cyclic Redundancy Check Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the Cyclic Redundancy Check (CRC) module of MCUXpresso SDK devices.

The cyclic redundancy check (CRC) module generates 16/32-bit CRC code for error detection. The CRC module also provides a programmable polynomial, seed, and other parameters required to implement a 16-bit or 32-bit CRC standard.

Data Structures

struct  crc_config_t
 CRC protocol configuration. More...
 

Macros

#define FSL_CRC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 CRC driver version 2.0.0. More...
 
#define FSL_CRC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 CRC driver version 2.0.0. More...
 

Enumerations

enum  crc_type_t {
  kCRC_Crc16 = CRC_CONTROL_CRCMOD(0),
  kCRC_Crc32 = CRC_CONTROL_CRCMOD(1)
}
 CRC type. More...
 
enum  crc_endian_t {
  kCRC_MsbFirst = CRC_CONTROL_CRCINV(0),
  kCRC_LsbFirst = CRC_CONTROL_CRCINV(1)
}
 CRC INV selection. More...
 
enum  {
  kStatus_CRC_ParameterError = PN76_STATUS_PARAMETER_ERROR,
  kStatus_CRC_InternalError = PN76_STATUS_INTERNAL_ERROR,
  kStatus_CRC_Busy = PN76_STATUS_BUSY
}
 CRC status. More...
 

Functions

void CRC_Init (CRC_Type *base)
 Enables the CRC peripheral module. More...
 
void CRC_Deinit (CRC_Type *base)
 Disables the CRC peripheral module. More...
 
void CRC_GetDefaultConfig (crc_config_t *config)
 Provide default CRC protocol configuration. More...
 
void CRC_SetConfig (CRC_Type *base, const crc_config_t *config)
 Configures the CRC peripheral module. More...
 
static void CRC_SetSeed (CRC_Type *base, uint32_t crcPreload)
 Set the CRC seed value. More...
 
void CRC_WriteData (CRC_Type *base, const uint8_t *buffer, uint32_t len)
 Set CRC type of transpose of write data. More...
 
static uint32_t CRC_GetResult (CRC_Type *base)
 Reads the checksum from the CRC module. More...
 
static void CRC_Init (void)
 Enables the CRC peripheral module.
 
static void CRC_DeInit (void)
 Disables the CRC peripheral module.
 
static status_t CRC_CalculateCrc (uint32_t crcPreload, uint8_t *buffer, uint32_t dataLength, uint32_t *crcValue)
 This function calculate CRC32 or CRC16 on selected data area. More...
 
static status_t CRC_CheckCrc16 (uint16_t crcPreload, uint8_t *buffer, uint32_t dataLength)
 This function check CRC16 calculation on buffer with calculated CRC value. More...
 
static status_t CRC_CalculateHDLLCrc16 (uint16_t crcPreload, uint8_t *buffer, uint32_t dataLength, uint16_t *crcValue)
 This function calculate CRC16 on selected FW buffer area. More...
 
static status_t CRC_CheckHDLLCrc16 (uint16_t crcPreload, uint8_t *buffer, uint32_t dataLength)
 This function check CRC16 calculation on incoming frame buffer with calculated CRC value. More...
 
static status_t CRC_Calc (uint8_t *buffer, uint32_t length)
 This function calculates the CRC on selected FW buffer area using the CRC HW. More...
 

Data Structure Documentation

struct crc_config_t

This structure holds the configuration for the CRC protocol.

Data Fields

bool crcEnable: 1
 Block Enable or Disable. More...
 
crc_type_t crcMode
 Select CRC protocol. More...
 
crc_endian_t crcEndian
 Select MSB or ILSB first data processing. More...
 

Field Documentation

bool crc_config_t::crcEnable
crc_type_t crc_config_t::crcMode
crc_endian_t crc_config_t::crcEndian

Macro Definition Documentation

#define FSL_CRC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
#define FSL_CRC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))

Enumeration Type Documentation

enum crc_type_t

CRC-16: poly:0x1021 CRC-32: poly:0x04C11DB7

Enumerator
kCRC_Crc16 

CRC-16 protocol.

kCRC_Crc32 

CRC-32 protocol.

Enumerator
kCRC_MsbFirst 

MSB, in this mode, refIn = false, refOut = false.

kCRC_LsbFirst 

LSB, in this mode, refIn = true, refOut = true.

anonymous enum
Enumerator
kStatus_CRC_ParameterError 

Value to be returned in case of wrong parameter.

kStatus_CRC_InternalError 

Value to be returned in case of an internal error or an error which is not specified in more detail.

kStatus_CRC_Busy 

Device or resource busy.

Function Documentation

void CRC_Init ( CRC_Type *  base)

This function enables the clock gate for the CRC peripheral.

Parameters
baseCRC peripheral address.
void CRC_Deinit ( CRC_Type *  base)

This function disables the clock gate for the CRC peripheral.

Parameters
baseCRC peripheral address.
void CRC_GetDefaultConfig ( crc_config_t config)

The purpose of this API is to initialize the configuration structure to default value for CRC_SetConfig to use. Provides the configuration of commonly used CRC protocols. The default configuration is:

config->enable = true;
config->crcMode = kCRC_Crc16;
config->crcEndian = kCRC_LsbFirst;
*

This is an example:

crc_config_t crc16Config;
//Load CRC-16 protocol configuration.
CRC_GetDefaultConfig(&crc16Config);
CRC_SetConfig(CRC, crc16Config);
*
Parameters
configCRC protocol configuration structure.
void CRC_SetConfig ( CRC_Type *  base,
const crc_config_t config 
)

This function configures the CRC module and starts a checksum computation by writing the seed.

Parameters
baseCRC peripheral address.
configCRC module configuration structure.
static void CRC_SetSeed ( CRC_Type *  base,
uint32_t  crcPreload 
)
inlinestatic

This function is help to write a 16/32 bit CRC seed value.

Parameters
baseCRC peripheral address.
crcPreloadThe value of seed.
void CRC_WriteData ( CRC_Type *  base,
const uint8_t *  buffer,
uint32_t  len 
)

This function writes data to CRC.

Parameters
baseCRC peripheral address.
bufferdata message to be checked.
lenlength of buffer.
static uint32_t CRC_GetResult ( CRC_Type *  base)
inlinestatic

Reads the CRC data register (either an intermediate or the final checksum).

Parameters
baseCRC peripheral address.
Returns
An intermediate or the final checksum, after transpose and complement operations configured.
static status_t CRC_CalculateCrc ( uint32_t  crcPreload,
uint8_t *  buffer,
uint32_t  dataLength,
uint32_t *  crcValue 
)
inlinestatic

This function is protected by semaphore. Functions that are protected by semaphores must not be called in interrupts. CRC will always calculate MSB first, this will be set internally

Parameters
crcPreload: Value of pre-load DATA for CRC calculation
buffer:Pointer to data message structure on which CRC will be calculated.
dataLength: Length of buffer in bytes Note - Len must match with Buffer size.
crcValue: Pointer on calculated CRC value
Return values
kStatus_SuccessOperation Successful.
kStatus_CRC_ParameterErrorUnknown EEPROM address or address pointed by pDataToWrite is incorrect.
kStatus_CRC_Busy
kStatus_CRC_InternalError
static status_t CRC_CheckCrc16 ( uint16_t  crcPreload,
uint8_t *  buffer,
uint32_t  dataLength 
)
inlinestatic
Note
It is assumed that CRC16 result is part of the buffer (usually last two bytes, after data on which CRC is calculated )
Function is protected by semaphore
Functions that are protected by semaphores must not be called in interrupts
CRC will always calculate MSB first, this will be set internally
Parameters
crcPreload: Value of pre-load DATA for CRC calculation
buffer:Pointer to data message structure on which CRC will be calculated.
dataLength: Length of buffer in bytes Note - Len must match with Buffer size.
Return values
kStatus_SuccessOperation Successful.
kStatus_CRC_ParameterErrorUnknown EEPROM address or address pointed by pDataToWrite is incorrect.
kStatus_CRC_Busy
kStatus_CRC_InternalError
static status_t CRC_CalculateHDLLCrc16 ( uint16_t  crcPreload,
uint8_t *  buffer,
uint32_t  dataLength,
uint16_t *  crcValue 
)
inlinestatic
Note
Function is protected by semaphore
Functions that are protected by semaphores must not be called in interrupts
CRC will always calculate lsb first and byte by byte, but buffer doesn't have to be aligned
Parameters
crcPreload: Value of pre-load DATA for CRC calculation
buffer:Pointer to data message structure on which CRC will be calculated.
dataLength: Length of buffer in bytes Note - Len must match with Buffer size.
crcValue: Pointer on calculated CRC value
Return values
kStatus_SuccessOperation Successful.
kStatus_CRC_ParameterErrorUnknown EEPROM address or address pointed by pDataToWrite is incorrect.
kStatus_CRC_Busy
kStatus_CRC_InternalError
static status_t CRC_CheckHDLLCrc16 ( uint16_t  crcPreload,
uint8_t *  buffer,
uint32_t  dataLength 
)
inlinestatic
Note
It is assumed that CRC16 result is part of the buffer (usually last two bytes, after data on which CRC is calculated )
Function is protected by semaphore
Functions that are protected by semaphores must not be called in interrupts
CRC will always calculate lsb first and byte by byte, but buffer doesn't have to be aligned
Parameters
crcPreload: Value of pre-load DATA for CRC calculation
buffer:Pointer to data message structure on which CRC will be calculated.
dataLength: Length of buffer in bytes Note - Len must match with Buffer size.
Return values
kStatus_SuccessOperation Successful.
kStatus_CRC_ParameterErrorUnknown EEPROM address or address pointed by pDataToWrite is incorrect.
kStatus_CRC_Busy
kStatus_CRC_InternalError
static status_t CRC_Calc ( uint8_t *  buffer,
uint32_t  length 
)
inlinestatic
Note
CRC will always calculate lsb first and byte by byte, but buffer doesn't have to be aligned
Parameters
buffer:Pointer to data message structure on which CRC will be calculated.
length: Length of buffer in bytes Note - Len must match with Buffer size.
Return values
kStatus_SuccessOperation Successful.
kStatus_CRC_ParameterErrorUnknown EEPROM address or address pointed by pDataToWrite is incorrect.
kStatus_CRC_Busy
kStatus_CRC_InternalError