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.

CRC Driver Initialization and Configuration

CRC_Init() function enables the clock gate for the CRC module in the SIM module and fully (re-)configures the CRC module according to the configuration structure. The seed member of the configuration structure is the initial checksum for which new data can be added to. When starting a new checksum computation, the seed is set to the initial checksum per the CRC protocol specification. For continued checksum operation, the seed is set to the intermediate checksum value as obtained from previous calls to CRC_Get16bitResult() or CRC_Get32bitResult() function. After calling the CRC_Init(), one or multiple CRC_WriteData() calls follow to update the checksum with data and CRC_Get16bitResult() or CRC_Get32bitResult() follow to read the result. The crcResult member of the configuration structure determines whether the CRC_Get16bitResult() or CRC_Get32bitResult() return value is a final checksum or an intermediate checksum. The CRC_Init() function can be called as many times as required allowing for runtime changes of the CRC protocol.

CRC_GetDefaultConfig() function can be used to set the module configuration structure with parameters for CRC-16/CCIT-FALSE protocol.

CRC Write Data

The CRC_WriteData() function adds data to the CRC. Internally, it tries to use 32-bit reads and writes for all aligned data in the user buffer and 8-bit reads and writes for all unaligned data in the user buffer. This function can update the CRC with user-supplied data chunks of an arbitrary size, so one can update the CRC byte by byte or with all bytes at once. Prior to calling the CRC configuration function CRC_Init() fully specifies the CRC module configuration for the CRC_WriteData() call.

CRC Get Checksum

The CRC_Get16bitResult() or CRC_Get32bitResult() function reads the CRC module data register. Depending on the prior CRC module usage, the return value is either an intermediate checksum or the final checksum. For example, for 16-bit CRCs the following call sequences can be used.

CRC_Init() / CRC_WriteData() / CRC_Get16bitResult() to get the final checksum.

CRC_Init() / CRC_WriteData() / ... / CRC_WriteData() / CRC_Get16bitResult() to get the final checksum.

CRC_Init() / CRC_WriteData() / CRC_Get16bitResult() to get an intermediate checksum.

CRC_Init() / CRC_WriteData() / ... / CRC_WriteData() / CRC_Get16bitResult() to get an intermediate checksum.

Comments about API usage in RTOS

If multiple RTOS tasks share the CRC module to compute checksums with different data and/or protocols, the following needs to be implemented by the user.

The triplets

CRC_Init() / CRC_WriteData() / CRC_Get16bitResult() or CRC_Get32bitResult()

The triplets are protected by the RTOS mutex to protect the CRC module against concurrent accesses from different tasks. This is an example. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/crcRefer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/crcRefer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/crcRefer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/crcRefer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/crc

Data Structures

struct  crc_config_t
 CRC protocol configuration. More...
 

Macros

#define CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT   1
 Default configuration structure filled by CRC_GetDefaultConfig(). More...
 

Enumerations

enum  crc_bits_t {
  kCrcBits16 = 0U,
  kCrcBits32 = 1U
}
 CRC bit width. More...
 
enum  crc_result_t {
  kCrcFinalChecksum = 0U,
  kCrcIntermediateChecksum = 1U
}
 CRC result type. More...
 

Functions

void CRC_Init (CRC_Type *base, const crc_config_t *config)
 Enables and configures the CRC peripheral module. More...
 
static void CRC_Deinit (CRC_Type *base)
 Disables the CRC peripheral module. More...
 
void CRC_GetDefaultConfig (crc_config_t *config)
 Loads default values to the CRC protocol configuration structure. More...
 
void CRC_WriteData (CRC_Type *base, const uint8_t *data, size_t dataSize)
 Writes data to the CRC module. More...
 
uint32_t CRC_Get32bitResult (CRC_Type *base)
 Reads the 32-bit checksum from the CRC module. More...
 
uint16_t CRC_Get16bitResult (CRC_Type *base)
 Reads a 16-bit checksum from the CRC module. More...
 

Driver version

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

Data Structure Documentation

struct crc_config_t

This structure holds the configuration for the CRC protocol.

Data Fields

uint32_t polynomial
 CRC Polynomial, MSBit first. More...
 
uint32_t seed
 Starting checksum value.
 
bool reflectIn
 Reflect bits on input. More...
 
bool reflectOut
 Reflect bits on output. More...
 
bool complementChecksum
 True if the result shall be complement of the actual checksum. More...
 
crc_bits_t crcBits
 Selects 16- or 32- bit CRC protocol. More...
 
crc_result_t crcResult
 Selects final or intermediate checksum return from CRC_Get16bitResult() or CRC_Get32bitResult()
 

Field Documentation

uint32_t crc_config_t::polynomial

Example polynomial: 0x1021 = 1_0000_0010_0001 = x^12+x^5+1

bool crc_config_t::reflectIn
bool crc_config_t::reflectOut
bool crc_config_t::complementChecksum
crc_bits_t crc_config_t::crcBits

Macro Definition Documentation

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

Version 2.0.3.

Current version: 2.0.3

Change log:

  • Version 2.0.3
    • Fix MISRA issues
  • Version 2.0.2
    • Fix MISRA issues
  • Version 2.0.1
    • move DATA and DATALL macro definition from header file to source file
#define CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT   1

Use CRC16-CCIT-FALSE as defeault.

Enumeration Type Documentation

enum crc_bits_t
Enumerator
kCrcBits16 

Generate 16-bit CRC code.

kCrcBits32 

Generate 32-bit CRC code.

Enumerator
kCrcFinalChecksum 

CRC data register read value is the final checksum.

Reflect out and final xor protocol features are applied.

kCrcIntermediateChecksum 

CRC data register read value is intermediate checksum (raw value).

Reflect out and final xor protocol feature are not applied. Intermediate checksum can be used as a seed for CRC_Init() to continue adding data to this checksum.

Function Documentation

void CRC_Init ( CRC_Type *  base,
const crc_config_t config 
)

This function enables the clock gate in the SIM module for the CRC peripheral. It also configures the CRC module and starts a checksum computation by writing the seed.

Parameters
baseCRC peripheral address.
configCRC module configuration structure.
static void CRC_Deinit ( CRC_Type *  base)
inlinestatic

This function disables the clock gate in the SIM module for the CRC peripheral.

Parameters
baseCRC peripheral address.
void CRC_GetDefaultConfig ( crc_config_t config)

Loads default values to the CRC protocol configuration structure. The default values are as follows.

* config->polynomial = 0x1021;
* config->seed = 0xFFFF;
* config->reflectIn = false;
* config->reflectOut = false;
* config->complementChecksum = false;
* config->crcBits = kCrcBits16;
* config->crcResult = kCrcFinalChecksum;
*
Parameters
configCRC protocol configuration structure.
void CRC_WriteData ( CRC_Type *  base,
const uint8_t *  data,
size_t  dataSize 
)

Writes input data buffer bytes to the CRC data register. The configured type of transpose is applied.

Parameters
baseCRC peripheral address.
dataInput data stream, MSByte in data[0].
dataSizeSize in bytes of the input data buffer.
uint32_t CRC_Get32bitResult ( CRC_Type *  base)

Reads the CRC data register (either an intermediate or the final checksum). The configured type of transpose and complement is applied.

Parameters
baseCRC peripheral address.
Returns
An intermediate or the final 32-bit checksum, after configured transpose and complement operations.
uint16_t CRC_Get16bitResult ( CRC_Type *  base)

Reads the CRC data register (either an intermediate or the final checksum). The configured type of transpose and complement is applied.

Parameters
baseCRC peripheral address.
Returns
An intermediate or the final 16-bit checksum, after configured transpose and complement operations.