|
| 1 | +## Hardware CRC |
| 2 | + |
| 3 | +The hardware CRC HAL API provides a low-level interface to the hardware CRC module of a target platform. Implementing the hardware CRC API allows you to gain the performance benefits of using hardware acceleration for CRC calculations. For platforms without hardware CRC capabilities, the API falls back to using the table and bitwise CRC implementations. |
| 4 | + |
| 5 | +<span class="notes">**Note:** The hardware CRC APIs are not thread safe.</span> |
| 6 | + |
| 7 | +#### Assumptions |
| 8 | + |
| 9 | +##### Defined behavior |
| 10 | + |
| 11 | +- Calling `hal_crc_compute_partial_start()` multiple times overrides the current CRC configuration and calculation. |
| 12 | +- The current intermediate calculation is lost if the module is reconfigured with `hal_crc_compute_partial_start()`. |
| 13 | +- `hal_crc_compute_partial()` does nothing if either the buffer is undefined or the size is equal to 0. |
| 14 | +- `hal_crc_compute_partial()` is safe to call multiple times. The new data is appended to the current calculation. |
| 15 | +- `hal_crc_is_supported` must return false if the the platform cannot support the initial or final values or data reflection in or out that the input polynomial requires. |
| 16 | + |
| 17 | +##### Undefined behavior |
| 18 | + |
| 19 | +- Calling the `hal_crc_get_result()` function multiple times is undefined. The contents of the result register after it has been read is platform-specific. The HAL API makes no assumptions about what the register contains, so it is not safe to call this multiple times. |
| 20 | +- Calling the `hal_crc_partial_start()` function with a polynomial unsupported by the current platform is undefined. Polynomial support should be checked before this function is called. |
| 21 | +- Calling the `hal_crc_get_result()` function before calling `hal_crc_partial_start()` is undefined. The module must be initialized before the get result function can return meaningful values. |
| 22 | +- Calling the `hal_crc_compute_partial()` function before calling `hal_crc_partial_start()` is undefined. The hardware CRC module must be configured correctly using the start function before writing data to it. |
| 23 | + |
| 24 | +#### Dependency |
| 25 | + |
| 26 | +The hardware CRC module in the MCU that supports at least one of the following defined polynomials: `POLY_8BIT_CCITT, POLY_7BIT_SD, POLY_16BIT_CCITT, POLY_16BIT_IBM, POLY_32BIT_ANSI ` |
| 27 | + |
| 28 | +#### Implementing the CRC API |
| 29 | + |
| 30 | +You can find the API and specification for the hardware CRC API in the following header file: |
| 31 | + |
| 32 | +[](http://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/group__hal__crc.html) |
| 33 | + |
| 34 | +To enable hardware CRC support in Mbed OS, add the `CRC` label in the `device_has` option of the target's section in the `targets.json` file. |
0 commit comments