Initial commit
mbed-dev-master/targets/TARGET_STM/mbed_crc_api.c@0:bb348c97df44, 2020-09-16 (annotated)
- Committer:
- lypinator
- Date:
- Wed Sep 16 01:11:49 2020 +0000
- Revision:
- 0:bb348c97df44
Added PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lypinator | 0:bb348c97df44 | 1 | #include "crc_api.h" |
lypinator | 0:bb348c97df44 | 2 | #include "device.h" |
lypinator | 0:bb348c97df44 | 3 | |
lypinator | 0:bb348c97df44 | 4 | #include "platform/mbed_assert.h" |
lypinator | 0:bb348c97df44 | 5 | |
lypinator | 0:bb348c97df44 | 6 | #ifdef DEVICE_CRC |
lypinator | 0:bb348c97df44 | 7 | |
lypinator | 0:bb348c97df44 | 8 | static CRC_HandleTypeDef current_state; |
lypinator | 0:bb348c97df44 | 9 | static uint32_t final_xor; |
lypinator | 0:bb348c97df44 | 10 | |
lypinator | 0:bb348c97df44 | 11 | bool hal_crc_is_supported(const crc_mbed_config_t *config) |
lypinator | 0:bb348c97df44 | 12 | { |
lypinator | 0:bb348c97df44 | 13 | if (config == NULL) { |
lypinator | 0:bb348c97df44 | 14 | return false; |
lypinator | 0:bb348c97df44 | 15 | } |
lypinator | 0:bb348c97df44 | 16 | |
lypinator | 0:bb348c97df44 | 17 | if (config->polynomial != POLY_32BIT_ANSI) { |
lypinator | 0:bb348c97df44 | 18 | return false; |
lypinator | 0:bb348c97df44 | 19 | } |
lypinator | 0:bb348c97df44 | 20 | |
lypinator | 0:bb348c97df44 | 21 | if (config->width != 32) { |
lypinator | 0:bb348c97df44 | 22 | return false; |
lypinator | 0:bb348c97df44 | 23 | } |
lypinator | 0:bb348c97df44 | 24 | |
lypinator | 0:bb348c97df44 | 25 | if ((config->final_xor != 0xFFFFFFFFU) && (config->final_xor != 0)) { |
lypinator | 0:bb348c97df44 | 26 | return false; |
lypinator | 0:bb348c97df44 | 27 | } |
lypinator | 0:bb348c97df44 | 28 | |
lypinator | 0:bb348c97df44 | 29 | return true; |
lypinator | 0:bb348c97df44 | 30 | } |
lypinator | 0:bb348c97df44 | 31 | |
lypinator | 0:bb348c97df44 | 32 | void hal_crc_compute_partial_start(const crc_mbed_config_t *config) |
lypinator | 0:bb348c97df44 | 33 | { |
lypinator | 0:bb348c97df44 | 34 | MBED_ASSERT(hal_crc_is_supported(config)); |
lypinator | 0:bb348c97df44 | 35 | |
lypinator | 0:bb348c97df44 | 36 | __HAL_RCC_CRC_CLK_ENABLE(); |
lypinator | 0:bb348c97df44 | 37 | |
lypinator | 0:bb348c97df44 | 38 | final_xor = config->final_xor; |
lypinator | 0:bb348c97df44 | 39 | |
lypinator | 0:bb348c97df44 | 40 | current_state.Instance = CRC; |
lypinator | 0:bb348c97df44 | 41 | current_state.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; |
lypinator | 0:bb348c97df44 | 42 | current_state.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; |
lypinator | 0:bb348c97df44 | 43 | current_state.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE; |
lypinator | 0:bb348c97df44 | 44 | current_state.Init.InitValue = config->initial_xor; |
lypinator | 0:bb348c97df44 | 45 | current_state.Init.CRCLength = CRC_POLYLENGTH_32B; |
lypinator | 0:bb348c97df44 | 46 | current_state.Init.InputDataInversionMode = |
lypinator | 0:bb348c97df44 | 47 | config->reflect_in ? CRC_INPUTDATA_INVERSION_BYTE |
lypinator | 0:bb348c97df44 | 48 | : CRC_INPUTDATA_INVERSION_NONE; |
lypinator | 0:bb348c97df44 | 49 | current_state.Init.OutputDataInversionMode = |
lypinator | 0:bb348c97df44 | 50 | config->reflect_out ? CRC_OUTPUTDATA_INVERSION_ENABLE |
lypinator | 0:bb348c97df44 | 51 | : CRC_OUTPUTDATA_INVERSION_DISABLE; |
lypinator | 0:bb348c97df44 | 52 | |
lypinator | 0:bb348c97df44 | 53 | HAL_CRC_Init(¤t_state); |
lypinator | 0:bb348c97df44 | 54 | } |
lypinator | 0:bb348c97df44 | 55 | |
lypinator | 0:bb348c97df44 | 56 | void hal_crc_compute_partial(const uint8_t *data, const size_t size) |
lypinator | 0:bb348c97df44 | 57 | { |
lypinator | 0:bb348c97df44 | 58 | if (data && size) { |
lypinator | 0:bb348c97df44 | 59 | HAL_CRC_Accumulate(¤t_state, (uint32_t *)data, size); |
lypinator | 0:bb348c97df44 | 60 | } |
lypinator | 0:bb348c97df44 | 61 | } |
lypinator | 0:bb348c97df44 | 62 | |
lypinator | 0:bb348c97df44 | 63 | uint32_t hal_crc_get_result(void) |
lypinator | 0:bb348c97df44 | 64 | { |
lypinator | 0:bb348c97df44 | 65 | const uint32_t result = current_state.Instance->DR; |
lypinator | 0:bb348c97df44 | 66 | |
lypinator | 0:bb348c97df44 | 67 | return (final_xor == 0xFFFFFFFFU) ? ~result : result; |
lypinator | 0:bb348c97df44 | 68 | } |
lypinator | 0:bb348c97df44 | 69 | |
lypinator | 0:bb348c97df44 | 70 | #endif // DEVICE_CRC |