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

Polynomial used for CRC calculation.

#define

Width of the polynomial.

#define

Initial LFSR value.

#define

Type of CRC.

#define

Width of the input data.

#define

Number of bytes to be written to the CRC.

#define

Empty threshold level.

#define

Full threshold level.

#define

Swap the input data.

#define

Use uDMA for CRC calculation.

#define

Swap the LFSR value.

Typedef Documentation#

sl_crc_params_t#

typedef RSI_CRC_PARAMS_T sl_crc_params_t

Renamed CRC param structure.


Definition at line 49 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
N/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 - Success.

    • SL_STATUS_INVALID_PARAMETER - Invalid parameter.

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


Definition at line 75 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[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 - Success.

    • SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.

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


Definition at line 91 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[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 - Success

    • SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.

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


Definition at line 109 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[in]pCRCParams

Pointer to the CRC parameters structure containing the polynomial width.

[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 - Success.

    • SL_STATUS_INVALID_PARAMETER - Invalid parameters.

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


Definition at line 127 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[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 - Success

    • SL_STATUS_INVALID_PARAMETER - Invalid parameters

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


Definition at line 146 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[in]pCRCParams

Pointer to the CRC parameters structure.

[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 - Success

    • SL_STATUS_INVALID_PARAMETER - Parameters are invalid.

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


Definition at line 167 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[in]pCRCParams

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

[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 - Success

    • SL_STATUS_INVALID_PARAMETER - Parameters are invalid.

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


Definition at line 184 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[in]pCRCParams

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

[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 - Success

    • SL_STATUS_INVALID_PARAMETER - Parameters are invalid.

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


Definition at line 201 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[in]pCRCParams

Pointer to the CRC parameters structure.

[in]data

Input data for CRC calculation.

[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 - Success

    • SL_STATUS_INVALID_PARAMETER - Parameters are invalid.

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


Definition at line 226 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[in]pCRCParams

Pointer to the CRC parameters structure.

[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 - Success

    • SL_STATUS_INVALID_PARAMETER - Parameters are invalid.

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


Definition at line 250 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[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 - Success

    • SL_STATUS_INVALID_PARAMETER - Parameters are invalid.

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


Definition at line 269 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

sl_si91x_crc_reset_fifo#

sl_status_t sl_si91x_crc_reset_fifo (void )

To reset the FIFO pointer and clear the FIFO.

Parameters
N/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 - Success

    • SL_STATUS_FAIL - Function failed

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


Definition at line 284 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

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
[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 - Success.

    • SL_STATUS_INVALID_PARAMETER - Parameters are invalid.

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


Definition at line 303 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

sl_si91x_crc_enable#

sl_status_t sl_si91x_crc_enable (void )

To enable the CRC peripheral by enabling its clock.

Parameters
N/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 - Success.

    • SL_STATUS_FAIL - Function failed.

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


Definition at line 317 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

sl_si91x_crc_disable#

sl_status_t sl_si91x_crc_disable (void )

To disable the CRC peripheral by disabling its clock.

Parameters
N/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 - Success.

    • SL_STATUS_FAIL - Function failed.

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


Definition at line 334 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

Macro Definition Documentation#

SL_CRC_POLYNOMIAL#

#define SL_CRC_POLYNOMIAL
Value:
0x04C11DB7

Polynomial used for CRC calculation.


Definition at line 50 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_POLY_WIDTH#

#define SL_CRC_POLY_WIDTH
Value:
31

Width of the polynomial.


Definition at line 51 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_LFSR_VAL#

#define SL_CRC_LFSR_VAL
Value:
0x0000

Initial LFSR value.


Definition at line 52 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_WIDTH_TYPE#

#define SL_CRC_WIDTH_TYPE
Value:
0

Type of CRC.


Definition at line 53 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_DIN_WIDTH#

#define SL_CRC_DIN_WIDTH
Value:
31

Width of the input data.


Definition at line 54 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_NUM_BYTES#

#define SL_CRC_NUM_BYTES
Value:
3

Number of bytes to be written to the CRC.


Definition at line 55 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_AEMPTY#

#define SL_CRC_AEMPTY
Value:
6

Empty threshold level.


Definition at line 56 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_AFULL#

#define SL_CRC_AFULL
Value:
2

Full threshold level.


Definition at line 57 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_SWAP_DIN#

#define SL_CRC_SWAP_DIN
Value:
0

Swap the input data.


Definition at line 58 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_USE_UDMA#

#define SL_CRC_USE_UDMA
Value:
1

Use uDMA for CRC calculation.


Definition at line 59 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h

SL_CRC_SWAP_LFSR#

#define SL_CRC_SWAP_LFSR
Value:
1

Swap the LFSR value.


Definition at line 60 of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_crc.h