mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

Hardware CRC

Hardware CRC
[Hal]

The Hardware CRC HAL API provides a low-level interface to the Hardware CRC module of a target platform. More...

Modules

 crc hal tests
 

The crc HAL tests ensure driver conformance to defined behaviour.


Functions

bool hal_crc_is_supported (const crc_mbed_config_t *config)
 Determine if the current platform supports hardware CRC for given polynomial.
void hal_crc_compute_partial_start (const crc_mbed_config_t *config)
 Initialize the hardware CRC module with the given polynomial.
void hal_crc_compute_partial (const uint8_t *data, const size_t size)
 Writes data to the current CRC module.

Detailed Description

The Hardware CRC HAL API provides a low-level interface to the Hardware CRC module of a target platform.

# Defined behaviour

* Function hal_crc_is_supported() returns true if platform supports hardware CRC for the given polynomial/width - verified by test crc_is_supported_test. * Function hal_crc_is_supported() returns false if platform does not support hardware CRC for the given polynomial/width - verified by test crc_is_supported_test. * Function hal_crc_is_supported() returns false if given pointer to configuration structure is undefined (NULL) - verified by test crc_is_supported_invalid_param_test. * If CRC module does not support one of the following settings: initial_xor, final_xor reflect_in, reflect_out, then these operations should be handled by the driver

  • Verified by test crc_calc_single_test. * Platform which supports hardware CRC must be able to handle at least one of the predefined polynomial/width configurations that can be constructed in the MbedCRC class: POLY_8BIT_CCITT, POLY_7BIT_SD, POLY_16BIT_CCITT, POLY_16BIT_IBM, POLY_32BIT_ANSI
  • verified by test crc_is_supported_test, crc_calc_single_test. * Function hal_crc_compute_partial_start() configures CRC module with the given configuration
  • Verified by test crc_calc_single_test. * Calling hal_crc_compute_partial_start() without finalising the CRC calculation overrides the current configuration - Verified by test crc_reconfigure_test. * Function hal_crc_compute_partial() writes data to the CRC module - verified by test crc_calc_single_test. * Function hal_crc_compute_partial() can be call multiple times in succession in order to provide additional data to CRC module - verified by test crc_calc_multi_test. * Function hal_crc_compute_partial() does nothing if pointer to buffer is undefined or data length is equal to 0 - verified by test crc_compute_partial_invalid_param_test. * Function hal_crc_get_result() returns the checksum result from the CRC module
  • verified by tests crc_calc_single_test, crc_calc_multi_test, crc_reconfigure_test.

# Undefined behaviour

* Calling hal_crc_compute_partial_start() function with invalid (unsupported) polynomial. * Calling hal_crc_compute_partial() or hal_crc_get_result() functions before hal_crc_compute_partial_start(). * Calling hal_crc_get_result() function multiple times.

# Non-functional requirements

* CRC configuration provides the following settings: * polynomial - CRC Polynomial, * width - CRC bit width, * initial_xor - seed value for the computation, * final_xor - final xor value for the computation, * reflect_in - reflect bits on input, * reflect_out - reflect bits in final result before returning.

# Potential bugs


Function Documentation

void hal_crc_compute_partial ( const uint8_t *  data,
const size_t  size 
)

Writes data to the current CRC module.

Writes input data buffer bytes to the CRC data register. The CRC module must interpret the data as an array of bytes.

The final transformations are not applied to the data; the CRC module must retain the intermediate result so that additional calls to this function can be made, appending the additional data to the calculation.

To obtain the final result of the CRC calculation, hal_crc_get_result() is called to apply the final transformations to the data.

If the function is passed an undefined pointer, or the size of the buffer is specified to be 0, this function does nothing and returns.

This function can be called multiple times in succession. This can be used to calculate the CRC result of streamed data.

This function is not thread safe. There is only one instance of the CRC module active at a time. Calling this function from multiple contexts appends different data to the same, single instance of the module, which causes an erroneous value to be calculated.

Parameters:
dataInput data stream to be written into the CRC calculation
sizeSize of the data stream in bytes
void hal_crc_compute_partial_start ( const crc_mbed_config_t *  config )

Initialize the hardware CRC module with the given polynomial.

After calling this function, the CRC HAL module is ready to receive data using the hal_crc_compute_partial() function. The CRC module on the board is configured internally with the specified configuration and is ready to receive data.

The platform configures itself based on the default configuration parameters of the input polynomial.

This function must be called before calling hal_crc_compute_partial().

This function must be called with a valid polynomial supported by the platform. The polynomial must be checked for support using the hal_crc_is_supported() function.

Calling hal_crc_compute_partial_start() multiple times without finalizing the CRC calculation with hal_crc_get_result() overrides the current configuration and state, and the intermediate result of the computation is lost.

This function is not thread safe. A CRC calculation must not be started from two different threads or contexts at the same time; calling this function from two different contexts may lead to configurations being overwritten and results being lost.

Parameters:
configContains CRC configuration parameters for initializing the hardware CRC module. For example, polynomial and initial seed values.
bool hal_crc_is_supported ( const crc_mbed_config_t *  config )

Determine if the current platform supports hardware CRC for given polynomial.

The purpose of this function is to inform the CRC Platform API whether the current platform has a hardware CRC module and that it can support the requested polynomial.

Supported polynomials are restricted to the named polynomials that can be constructed in the MbedCRC class, POLY_8BIT_CCITT, POLY_7BIT_SD, POLY_16BIT_CCITT, POLY_16BIT_IBM and POLY_32BIT_ANSI.

The current platform must support the given polynomials default parameters in order to return a true response. These include: reflect in, reflect out, initial xor and final xor. For example, POLY_32BIT_ANSI requires an initial and final xor of 0xFFFFFFFF, and reflection of both input and output. If any of these settings cannot be configured, the polynomial is not supported.

This function is thread safe; it safe to call from multiple contexts if required.

Parameters:
configContains CRC configuration parameters for initializing the hardware CRC module. For example, polynomial and initial seed values.
Returns:
True if running if the polynomial is supported, false if not.