RA Flexible Software Package Documentation  Release v5.1.0

 
CRC (r_crc)

Functions

fsp_err_t R_CRC_Open (crc_ctrl_t *const p_ctrl, crc_cfg_t const *const p_cfg)
 
fsp_err_t R_CRC_Close (crc_ctrl_t *const p_ctrl)
 
fsp_err_t R_CRC_Calculate (crc_ctrl_t *const p_ctrl, crc_input_t *const p_crc_input, uint32_t *calculatedValue)
 
fsp_err_t R_CRC_CalculatedValueGet (crc_ctrl_t *const p_ctrl, uint32_t *calculatedValue)
 
fsp_err_t R_CRC_SnoopEnable (crc_ctrl_t *const p_ctrl, uint32_t crc_seed)
 
fsp_err_t R_CRC_SnoopDisable (crc_ctrl_t *const p_ctrl)
 

Detailed Description

Driver for the CRC peripheral on RA MCUs. This module implements the CRC Interface.

Overview

The CRC module provides a API to calculate 8, 16 and 32-bit CRC values on a block of data in memory or a stream of data over a Serial Communication Interface (SCI) channel using industry-standard polynomials.

Features

Configuration

Build Time Configurations for r_crc

The following build time configurations are defined in fsp_cfg/r_crc_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Monitoring > CRC (r_crc)

This module can be added to the Stacks tab via New Stack > Monitoring > CRC (r_crc). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_crc0 Module name.
CRC Polynomial
  • CRC-8
  • CRC-16
  • CRC-CCITT
  • CRC-32
  • CRC-32C
CRC-32C Select the CRC polynomial.
Bit Order
  • LSB
  • MSB
MSB Select the CRC bit order.
Snoop AddressMCU Specific OptionsSelect the SCI register address CRC snoop

Clock Configuration

There is no clock configuration for the CRC module.

Pin Configuration

This module does not use I/O pins.

Usage Notes

CRC Snoop

The CRC snoop function monitors reads from and writes to a specified I/O register address and performs CRC calculation on the data read from and written to the register address automatically. Instead of calling R_CRC_Calculate on a block of data, R_CRC_SnoopEnable is called to start monitoring reads/writes and R_CRC_CalculatedValueGet is used to obtain the current CRC.

Note
Snoop mode is available for transmit/receive operations on SCI only.

Limitations

When using CRC32 polynomial functions the CRC module produces the same results as popular online CRC32 calculators, but it is important to remember a few important points.

Examples

Basic Example

This is a basic example of minimal use of the CRC module in an application.

void crc_example ()
{
uint32_t length;
uint32_t uint8_calculated_value;
length = sizeof(g_data_8bit) / sizeof(g_data_8bit[0]);
crc_input_t example_input =
{
.p_input_buffer = g_data_8bit,
.num_bytes = length,
.crc_seed = 0,
};
/* Open CRC module with 8 bit polynomial */
R_CRC_Open(&crc_ctrl, &g_crc_test_cfg);
/* 8-bit CRC calculation */
R_CRC_Calculate(&crc_ctrl, &example_input, &uint8_calculated_value);
}

Snoop Example

This example demonstrates CRC snoop operation.

void crc_snoop_example ()
{
/* Open CRC module with 8 bit polynomial */
R_CRC_Open(&crc_ctrl, &g_crc_test_cfg);
/* Open SCI Driver */
/* Configure Snoop address and enable snoop mode */
R_CRC_SnoopEnable(&crc_ctrl, 0);
/* Perfrom SCI read/Write operation depending on the SCI snoop address configure */
/* Read CRC value */
R_CRC_CalculatedValueGet(&crc_ctrl, &g_crc_buff);
}

Data Structures

struct  crc_instance_ctrl_t
 

Data Structure Documentation

◆ crc_instance_ctrl_t

struct crc_instance_ctrl_t

Driver instance control structure.

Function Documentation

◆ R_CRC_Open()

fsp_err_t R_CRC_Open ( crc_ctrl_t *const  p_ctrl,
crc_cfg_t const *const  p_cfg 
)

Open the CRC driver module

Implements crc_api_t::open

Open the CRC driver module and initialize the driver control block according to the passed-in configuration structure.

Return values
FSP_SUCCESSConfiguration was successful.
FSP_ERR_ASSERTIONp_ctrl or p_cfg is NULL.
FSP_ERR_ALREADY_OPENModule already open

◆ R_CRC_Close()

fsp_err_t R_CRC_Close ( crc_ctrl_t *const  p_ctrl)

Close the CRC module driver.

Implements crc_api_t::close

Return values
FSP_SUCCESSConfiguration was successful.
FSP_ERR_ASSERTIONp_ctrl is NULL.
FSP_ERR_NOT_OPENThe driver is not opened.

◆ R_CRC_Calculate()

fsp_err_t R_CRC_Calculate ( crc_ctrl_t *const  p_ctrl,
crc_input_t *const  p_crc_input,
uint32_t *  calculatedValue 
)

Perform a CRC calculation on a block of 8-bit/32-bit (for 32-bit polynomial) data.

Implements crc_api_t::calculate

This function performs a CRC calculation on an array of 8-bit/32-bit (for 32-bit polynomial) values and returns an 8-bit/32-bit (for 32-bit polynomial) calculated value

Return values
FSP_SUCCESSCalculation successful.
FSP_ERR_ASSERTIONEither p_ctrl, inputBuffer, or calculatedValue is NULL.
FSP_ERR_INVALID_ARGUMENTlength value is NULL.
FSP_ERR_NOT_OPENThe driver is not opened.

◆ R_CRC_CalculatedValueGet()

fsp_err_t R_CRC_CalculatedValueGet ( crc_ctrl_t *const  p_ctrl,
uint32_t *  calculatedValue 
)

Return the current calculated value.

Implements crc_api_t::crcResultGet

CRC calculation operates on a running value. This function returns the current calculated value.

Return values
FSP_SUCCESSReturn of calculated value successful.
FSP_ERR_ASSERTIONEither p_ctrl or calculatedValue is NULL.
FSP_ERR_NOT_OPENThe driver is not opened.

◆ R_CRC_SnoopEnable()

fsp_err_t R_CRC_SnoopEnable ( crc_ctrl_t *const  p_ctrl,
uint32_t  crc_seed 
)

Configure the snoop channel and set the CRC seed.

Implements crc_api_t::snoopEnable

The CRC calculator can operate on reads and writes over any of the first ten SCI channels. For example, if set to channel 0, transmit, every byte written out SCI channel 0 is also sent to the CRC calculator as if the value was explicitly written directly to the CRC calculator.

Return values
FSP_SUCCESSSnoop configured successfully.
FSP_ERR_ASSERTIONPointer to control stucture is NULL
FSP_ERR_NOT_OPENThe driver is not opened.
FSP_ERR_UNSUPPORTEDSNOOP operation is not supported.

◆ R_CRC_SnoopDisable()

fsp_err_t R_CRC_SnoopDisable ( crc_ctrl_t *const  p_ctrl)

Disable snooping.

Implements crc_api_t::snoopDisable

Return values
FSP_SUCCESSSnoop disabled.
FSP_ERR_ASSERTIONp_ctrl is NULL.
FSP_ERR_NOT_OPENThe driver is not opened.
FSP_ERR_UNSUPPORTEDSNOOP operation is not supported.