Cyclic Redundancy Check#

Introduction#

The Cyclic Redundancy Check (CRC) is a method used to verify the integrity of data in embedded systems. CRCs are commonly employed in communication protocols, storage devices, and error detection algorithms. By generating a checksum, CRC helps ensure that the data received or stored is accurate and unaltered.

Common use cases for CRC include:

  • Error Detection: Identifying data transmission errors in communication protocols.

  • Data Integrity Verification: Ensuring stored data remains uncorrupted.

  • Checksum Calculation: Generating checksums for data validation.

Configuration#

CRC can be configured using several parameters, including:

  • Polynomial: The polynomial used for CRC calculation (sl_crc_params_t).

  • Width: The width of the CRC polynomial.

  • Data Input Type: The width of the data input for the CRC engine.

These configurations are encapsulated in the sl_crc_params_t structure and initialized using the respective CRC APIs.

For more details on configuration parameters, see the respective peripheral example readme document.

Usage#

After defining the CRC configuration structures and passing an instance of sl_crc_params_t, the following functions can be used to initiate and configure the CRC module. The typical flow for implementation is as follows:

  1. Set general control: sl_si91x_crc_set_gen_control

  2. Enable CRC peripheral: sl_si91x_crc_enable

  3. Load polynomial value: sl_si91x_crc_polynomial

  4. Set polynomial width: sl_si91x_crc_polynomial_width

  5. Initialize LFSR: sl_si91x_crc_lfsr_init

  6. Configure data width type: sl_si91x_crc_set_data_width_type

  7. Monitor CRC calculation: sl_si91x_crc_monitor_crc_calc

  8. Reset FIFO: sl_si91x_crc_reset_fifo

  9. Disable CRC peripheral: sl_si91x_crc_disable /

Typedefs#

typedef RSI_CRC_PARAMS_T

Renamed CRC param structure.

Functions#

sl_status_t

Clears the FIFO and resets all state machines.

sl_status_t
sl_si91x_crc_get_general_status(uint32_t *reg_status)

To retrieve the general status of the CRC signals.

sl_status_t
sl_si91x_crc_polynomial(sl_crc_params_t *pCRCParams)

To load the polynomial value into the polynomial register.

sl_status_t
sl_si91x_crc_polynomial_width(sl_crc_params_t *pCRCParams, uint32_t *reg_status)

To set the width of the polynomial for CRC computation.

sl_status_t
sl_si91x_crc_lfsr_init(sl_crc_params_t *pCRCParams)

To initialize the LFSR value for CRC computation.

sl_status_t
sl_si91x_crc_use_swapped_init(sl_crc_params_t *pCRCParams, uint32_t *reg_status)

To load a swapped version of the LFSR init value into the LFSR state.

sl_status_t
sl_si91x_crc_set_data_width_type(sl_crc_params_t *pCRCParams, uint32_t *oper_status)

To set and control the data width types for CRC computation.

sl_status_t
sl_si91x_crc_set_fifo_thresholds(sl_crc_params_t *pCRCParams, uint32_t *oper_status)

To set the FIFO threshold levels for CRC computation.

sl_status_t
sl_si91x_crc_write_data(sl_crc_params_t *pCRCParams, uint32_t data, uint32_t *oper_status)

To set the input data for CRC calculation.

sl_status_t
sl_si91x_crc_monitor_crc_calc(sl_crc_params_t *pCRCParams, uint32_t *crc)

To monitor the CRC calculation status and return the CRC value.

sl_status_t
sl_si91x_crc_lfsr_dynamic_write(sl_crc_params_t *pCRCParams)

To write the LFSR state directly for dynamic operation.

sl_status_t

To reset the FIFO pointer and clear the FIFO.

sl_status_t
sl_si91x_crc_get_fifo_status(uint32_t *reg_status)

To retrieve the FIFO status of the CRC occupancy.

sl_status_t

To enable the CRC peripheral by enabling its clock.

sl_status_t

To disable the CRC peripheral by disabling its clock.

Macros#

#define
SL_CRC_POLYNOMIAL 0x04C11DB7

Polynomial used for CRC calculation.

#define
SL_CRC_POLY_WIDTH 31

Width of the polynomial.

#define
SL_CRC_LFSR_VAL 0x0000

Initial LFSR value.

#define
SL_CRC_WIDTH_TYPE 0

Type of CRC.

#define
SL_CRC_DIN_WIDTH 31

Width of the input data.

#define
SL_CRC_NUM_BYTES 3

Number of bytes to be written to the CRC.

#define
SL_CRC_AEMPTY 6

Empty threshold level.

#define
SL_CRC_AFULL 2

Full threshold level.

#define
SL_CRC_SWAP_DIN 0

Swap the input data.

#define
SL_CRC_USE_UDMA 1

Use uDMA for CRC calculation.

#define
SL_CRC_SWAP_LFSR 1

Swap the LFSR value.

Typedef Documentation#

sl_crc_params_t#

typedef RSI_CRC_PARAMS_T sl_crc_params_t

Renamed CRC param structure.


Function Documentation#

sl_si91x_crc_set_gen_control#

sl_status_t sl_si91x_crc_set_gen_control (void )

Clears the FIFO and resets all state machines.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This API clears the FIFO and resets all state machines. It ensures that the CRC module is in a known state before starting a new operation.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Invalid parameter.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_get_general_status#

sl_status_t sl_si91x_crc_get_general_status (uint32_t * reg_status)

To retrieve the general status of the CRC signals.

Parameters
TypeDirectionArgument NameDescription
uint32_t *[out]reg_status

Pointer to store the status of the GEN_STS Register.

This API retrieves the general status of the CRC signals and stores it in the provided pointer.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_NULL_POINTER (0x0021) - Invalid null pointer received as an argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_polynomial#

sl_status_t sl_si91x_crc_polynomial (sl_crc_params_t * pCRCParams)

To load the polynomial value into the polynomial register.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure containing the polynomial value.

This API loads the polynomial value into the polynomial register using the provided CRC parameters.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_NULL_POINTER (0x0021) - Invalid null pointer received as an argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_polynomial_width#

sl_status_t sl_si91x_crc_polynomial_width (sl_crc_params_t * pCRCParams, uint32_t * reg_status)

To set the width of the polynomial for CRC computation.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure containing the polynomial width.

uint32_t *[out]reg_status

Pointer to store the FIFO status register value.

This API sets the width of the polynomial for CRC computation. If a new width needs to be configured, clear the existing length first by writing 0x1F to the polynomial_ctrl_reset register.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Invalid parameters.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_lfsr_init#

sl_status_t sl_si91x_crc_lfsr_init (sl_crc_params_t * pCRCParams)

To initialize the LFSR value for CRC computation.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure containing the LFSR value.

This API initializes the Linear Feedback Shift Register (LFSR) value for CRC computation. The LFSR needs to be initialized with the init value whenever required.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Invalid parameters

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_use_swapped_init#

sl_status_t sl_si91x_crc_use_swapped_init (sl_crc_params_t * pCRCParams, uint32_t * reg_status)

To load a swapped version of the LFSR init value into the LFSR state.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure.

uint32_t *[out]reg_status

Pointer to store the FIFO status register value.

This API loads a swapped version of the Linear Feedback Shift Register (LFSR) init value into the LFSR state. It is used to initialize the LFSR with a swapped init value for CRC computation.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_set_data_width_type#

sl_status_t sl_si91x_crc_set_data_width_type (sl_crc_params_t * pCRCParams, uint32_t * oper_status)

To set and control the data width types for CRC computation.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure containing the data width type.

uint32_t *[out]oper_status

Pointer to store the operation status of the API process.

This API sets and controls the data width types for CRC computation using the provided CRC parameters.

Returns

  • Status code:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_set_fifo_thresholds#

sl_status_t sl_si91x_crc_set_fifo_thresholds (sl_crc_params_t * pCRCParams, uint32_t * oper_status)

To set the FIFO threshold levels for CRC computation.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure containing the FIFO thresholds (aempty and afull).

uint32_t *[out]oper_status

Pointer to store the operation status of the API process.

This API sets the FIFO threshold levels for CRC computation. The maximum value for both thresholds is 15.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_write_data#

sl_status_t sl_si91x_crc_write_data (sl_crc_params_t * pCRCParams, uint32_t data, uint32_t * oper_status)

To set the input data for CRC calculation.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure.

uint32_t[in]data

Input data for CRC calculation.

uint32_t *[out]oper_status

Pointer to store the status of the operation.

This API sets the input data for CRC calculation using the provided CRC parameters.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_monitor_crc_calc#

sl_status_t sl_si91x_crc_monitor_crc_calc (sl_crc_params_t * pCRCParams, uint32_t * crc)

To monitor the CRC calculation status and return the CRC value.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure.

uint32_t *[out]crc

Pointer to store the calculated CRC value.

This API monitors the CRC calculation status and returns the calculated CRC value.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_lfsr_dynamic_write#

sl_status_t sl_si91x_crc_lfsr_dynamic_write (sl_crc_params_t * pCRCParams)

To write the LFSR state directly for dynamic operation.

Parameters
TypeDirectionArgument NameDescription
sl_crc_params_t *[in]pCRCParams

Pointer to the CRC parameters structure containing the LFSR state.

This API writes the Linear Feedback Shift Register (LFSR) state directly for dynamic operation.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_reset_fifo#

sl_status_t sl_si91x_crc_reset_fifo (void )

To reset the FIFO pointer and clear the FIFO.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This API resets the FIFO pointer and clears the FIFO, ensuring that the FIFO is empty and ready for new data.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success

    • SL_STATUS_FAIL (0x0001) - Function failed

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_get_fifo_status#

sl_status_t sl_si91x_crc_get_fifo_status (uint32_t * reg_status)

To retrieve the FIFO status of the CRC occupancy.

Parameters
TypeDirectionArgument NameDescription
uint32_t *[out]reg_status

Pointer to store the FIFO status register value.

This API retrieves the FIFO status of the CRC occupancy and stores the status in the provided register.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_enable#

sl_status_t sl_si91x_crc_enable (void )

To enable the CRC peripheral by enabling its clock.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This API enables the CRC peripheral by enabling its clock, allowing CRC operations to be performed.

Returns

  • Status code indicating the result::

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_FAIL (0x0001) - Function failed.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_crc_disable#

sl_status_t sl_si91x_crc_disable (void )

To disable the CRC peripheral by disabling its clock.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This API disables the CRC peripheral by disabling its clock, preventing any further CRC operations.

Returns

  • Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_FAIL (0x0001) - Function failed.

For more information on status codes, see SL STATUS DOCUMENTATION.