Detailed Description

This section describes the programming interface of the CRC driver.

Basic Operations of CRC

  1. To initialize the CRC module, call CRC_DRV_Init() function and pass the user configuration data structure to it.
    This is example code to configure the CRC driver use CRC_DRV_GetDefaultConfig function:
    #define INST_CRC1 (0U)
    /* Configuration structure crc1_InitConfig0 */
    crc_user_config_t crc1_InitConfig0;
    /* Get default configuration for CRC module: CRC-16-CCITT (0x1021) standard */
    CRC_DRV_GetDefaultConfig(&crc1_InitConfig0);
    /* Initializes the CRC */
    CRC_DRV_Init(INST_CRC1, &crc1_InitConfig0);
  2. To configuration and operation CRC module:
    Function CRC_DRV_Configure() shall be used to write user configuration to CRC hardware module before starting operation by calling CRC_DRV_WriteData().
    Finally, using CRC_DRV_GetCrcResult() function to get the result of CRC calculation.
    This is example code to Configure and get CRC block for S32K1xx:
    #define INST_CRC1 (0U)
    uint8_t buffer[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30 };
    uint32_t result;
    /* Set the CRC configuration: CRC-16-CCITT (0x1021) standard */
    CRC_DRV_Configure(INST_CRC1, &crc1_InitConfig0);
    /* Write data to the current CRC calculation */
    CRC_DRV_WriteData(INST_CRC1, buffer, 10U);
    /* Get result of CRC calculation (0x3218U) */
    result = CRC_DRV_GetCrcResult(INST_CRC1);
    /* De-init */
    CRC_DRV_Deinit(INST_CRC1);
  3. To Get result of 32-bit data then call CRC_DRV_GetCrc32() function.
    #define INST_CRC1 (0U)
    uint32_t seed = 0xFFFFU;
    uint32_t data = 0x12345678U;
    uint32_t result;
    /* Get result of 32-bit data (0x30EC) at CRC-16-CCITT (0x1021) standard configuration mode */
    result = CRC_DRV_GetCrc32(INST_CRC1, data, true, seed);
  4. To Get result of 16-bit data then call CRC_DRV_GetCrc16() function.
    #define INST_CRC1 (0U)
    uint32_t seed = 0xFFFFU;
    uint16_t data = 0x1234U;
    uint32_t result;
    /* Get result of 16-bit data (0x0EC9) at CRC-16-CCITT (0x1021) standard configuration mode */
    result = CRC_DRV_GetCrc16(INST_CRC1, data, true, seed);
  5. To Get current configuration of the CRC module, just call CRC_DRV_GetConfig() function.
    #define INST_CRC1 (0U)
    crc_user_config_t crc1_InitConfig0;
    /* Get current configuration of the CRC module */
    CRC_DRV_GetConfig(INST_CRC1, &crc1_InitConfig0);
  6. To Get default configuration of the CRC module, just call CRC_DRV_GetDefaultConfig() function.
    #define INST_CRC1 (0U)
    crc_user_config_t crc1_InitConfig0;
    /* Get default configuration of the CRC module */
    CRC_DRV_GetDefaultConfig(&crc1_InitConfig0);

Data Structures

struct  crc_user_config_t
 CRC configuration structure. Implements : crc_user_config_t_Class. More...
 

Enumerations

enum  crc_transpose_t { CRC_TRANSPOSE_NONE = 0x00U, CRC_TRANSPOSE_BITS = 0x01U, CRC_TRANSPOSE_BITS_AND_BYTES = 0x02U, CRC_TRANSPOSE_BYTES = 0x03U }
 CRC type of transpose of read write data Implements : crc_transpose_t_Class. More...
 
enum  crc_bit_width_t { CRC_BITS_16 = 0U, CRC_BITS_32 = 1U }
 CRC bit width Implements : crc_bit_width_t_Class. More...
 

CRC DRIVER API

status_t CRC_DRV_Init (uint32_t instance, const crc_user_config_t *userConfigPtr)
 Initializes the CRC module. More...
 
status_t CRC_DRV_Deinit (uint32_t instance)
 Sets the default configuration. More...
 
uint32_t CRC_DRV_GetCrc32 (uint32_t instance, uint32_t data, bool newSeed, uint32_t seed)
 Appends 32-bit data to the current CRC calculation and returns new result. More...
 
uint32_t CRC_DRV_GetCrc16 (uint32_t instance, uint16_t data, bool newSeed, uint32_t seed)
 Appends 16-bit data to the current CRC calculation and returns new result. More...
 
uint32_t CRC_DRV_GetCrc8 (uint32_t instance, uint8_t data, bool newSeed, uint32_t seed)
 Appends 8-bit data to the current CRC calculation and returns new result. More...
 
void CRC_DRV_WriteData (uint32_t instance, const uint8_t *data, uint32_t dataSize)
 Appends a block of bytes to the current CRC calculation. More...
 
uint32_t CRC_DRV_GetCrcResult (uint32_t instance)
 Returns the current result of the CRC calculation. More...
 
status_t CRC_DRV_Configure (uint32_t instance, const crc_user_config_t *userConfigPtr)
 Configures the CRC module from a user configuration structure. More...
 
status_t CRC_DRV_GetConfig (uint32_t instance, crc_user_config_t *const userConfigPtr)
 Get configures of the CRC module currently. More...
 
status_t CRC_DRV_GetDefaultConfig (crc_user_config_t *const userConfigPtr)
 Get default configures the CRC module for configuration structure. More...
 

Enumeration Type Documentation

CRC bit width Implements : crc_bit_width_t_Class.

Enumerator
CRC_BITS_16 

Generate 16-bit CRC code

CRC_BITS_32 

Generate 32-bit CRC code

Definition at line 59 of file crc_driver.h.

CRC type of transpose of read write data Implements : crc_transpose_t_Class.

Enumerator
CRC_TRANSPOSE_NONE 

No transpose

CRC_TRANSPOSE_BITS 

Transpose bits in bytes

CRC_TRANSPOSE_BITS_AND_BYTES 

Transpose bytes and bits in bytes

CRC_TRANSPOSE_BYTES 

Transpose bytes

Definition at line 46 of file crc_driver.h.

Function Documentation

status_t CRC_DRV_Configure ( uint32_t  instance,
const crc_user_config_t userConfigPtr 
)

Configures the CRC module from a user configuration structure.

This function configures the CRC module from a user configuration structure

Parameters
[in]instanceThe CRC instance number
[in]userConfigPtrPointer to structure of initialization
Returns
Execution status (success)

Definition at line 239 of file crc_driver.c.

status_t CRC_DRV_Deinit ( uint32_t  instance)

Sets the default configuration.

This function sets the default configuration

Parameters
[in]instanceThe CRC instance number
Returns
Execution status (success)

Definition at line 91 of file crc_driver.c.

status_t CRC_DRV_GetConfig ( uint32_t  instance,
crc_user_config_t *const  userConfigPtr 
)

Get configures of the CRC module currently.

This function Get configures of the CRC module currently

Parameters
[in]instanceThe CRC instance number
[out]userConfigPtrPointer to structure of initialization
Returns
Execution status (success)

Definition at line 271 of file crc_driver.c.

uint32_t CRC_DRV_GetCrc16 ( uint32_t  instance,
uint16_t  data,
bool  newSeed,
uint32_t  seed 
)

Appends 16-bit data to the current CRC calculation and returns new result.

This function appends 16-bit data to the current CRC calculation and returns new result. If the newSeed is true, seed set and result are calculated from the seed new value (new CRC calculation)

Parameters
[in]instanceThe CRC instance number
[in]dataInput data for CRC calculation
[in]newSeedSets new CRC calculation
  • true: New seed set and used for new calculation.
  • false: Seed argument ignored, continues old calculation.
[in]seedNew seed if newSeed is true, else ignored
Returns
New CRC result

Definition at line 142 of file crc_driver.c.

uint32_t CRC_DRV_GetCrc32 ( uint32_t  instance,
uint32_t  data,
bool  newSeed,
uint32_t  seed 
)

Appends 32-bit data to the current CRC calculation and returns new result.

This function appends 32-bit data to the current CRC calculation and returns new result. If the newSeed is true, seed set and result are calculated from the seed new value (new CRC calculation)

Parameters
[in]instanceThe CRC instance number
[in]dataInput data for CRC calculation
[in]newSeedSets new CRC calculation
  • true: New seed set and used for new calculation.
  • false: Seed argument ignored, continues old calculation.
[in]seedNew seed if newSeed is true, else ignored
Returns
New CRC result

Definition at line 111 of file crc_driver.c.

uint32_t CRC_DRV_GetCrc8 ( uint32_t  instance,
uint8_t  data,
bool  newSeed,
uint32_t  seed 
)

Appends 8-bit data to the current CRC calculation and returns new result.

This function appends 8-bit data to the current CRC calculation and returns new result. If the newSeed is true, seed set and result are calculated from the seed new value (new CRC calculation)

Parameters
[in]instanceThe CRC instance number
[in]dataInput data for CRC calculation
[in]newSeedSets new CRC calculation
  • true: New seed set and used for new calculation.
  • false: Seed argument ignored, continues old calculation.
[in]seedNew seed if newSeed is true, else ignored
Returns
New CRC result

Definition at line 172 of file crc_driver.c.

uint32_t CRC_DRV_GetCrcResult ( uint32_t  instance)

Returns the current result of the CRC calculation.

This function returns the current result of the CRC calculation

Parameters
[in]instanceThe CRC instance number
Returns
Result of CRC calculation

Definition at line 223 of file crc_driver.c.

status_t CRC_DRV_GetDefaultConfig ( crc_user_config_t *const  userConfigPtr)

Get default configures the CRC module for configuration structure.

This function Get default configures the CRC module for user configuration structure

Parameters
[out]userConfigPtrPointer to structure of initialization
Returns
Execution status (success)

Definition at line 303 of file crc_driver.c.

status_t CRC_DRV_Init ( uint32_t  instance,
const crc_user_config_t userConfigPtr 
)

Initializes the CRC module.

This function initializes CRC driver based on user configuration input. The user must make sure that the clock is enabled

Parameters
[in]instanceThe CRC instance number
[in]userConfigPtrPointer to structure of initialization
Returns
Execution status (success)

Definition at line 68 of file crc_driver.c.

void CRC_DRV_WriteData ( uint32_t  instance,
const uint8_t *  data,
uint32_t  dataSize 
)

Appends a block of bytes to the current CRC calculation.

This function appends a block of bytes to the current CRC calculation

Parameters
[in]instanceThe CRC instance number
[in]dataData for current CRC calculation
[in]dataSizeLength of data to be calculated

Definition at line 200 of file crc_driver.c.