mbed library sources. Supersedes mbed-src.

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

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
Parent:
targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_crc.c@144:ef7eb2e8f9f7
Child:
156:95d6b41a828b
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /**
<> 144:ef7eb2e8f9f7 2 ******************************************************************************
<> 144:ef7eb2e8f9f7 3 * @file stm32f0xx_hal_crc.c
<> 144:ef7eb2e8f9f7 4 * @author MCD Application Team
<> 144:ef7eb2e8f9f7 5 * @version V1.4.0
<> 144:ef7eb2e8f9f7 6 * @date 27-May-2016
<> 144:ef7eb2e8f9f7 7 * @brief CRC HAL module driver.
<> 144:ef7eb2e8f9f7 8 * This file provides firmware functions to manage the following
<> 144:ef7eb2e8f9f7 9 * functionalities of the Cyclic Redundancy Check (CRC) peripheral:
<> 144:ef7eb2e8f9f7 10 * + Initialization and de-initialization functions
<> 144:ef7eb2e8f9f7 11 * + Peripheral Control functions
<> 144:ef7eb2e8f9f7 12 * + Peripheral State functions
<> 144:ef7eb2e8f9f7 13 *
<> 144:ef7eb2e8f9f7 14 @verbatim
<> 144:ef7eb2e8f9f7 15 ===============================================================================
<> 144:ef7eb2e8f9f7 16 ##### How to use this driver #####
<> 144:ef7eb2e8f9f7 17 ===============================================================================
<> 144:ef7eb2e8f9f7 18 [..]
<> 144:ef7eb2e8f9f7 19 (#) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
<> 144:ef7eb2e8f9f7 20 (#) Initialize CRC calculator
<> 144:ef7eb2e8f9f7 21 (++)specify generating polynomial (IP default or non-default one)
<> 144:ef7eb2e8f9f7 22 (++)specify initialization value (IP default or non-default one)
<> 144:ef7eb2e8f9f7 23 (++)specify input data format
<> 144:ef7eb2e8f9f7 24 (++)specify input or output data inversion mode if any
<> 144:ef7eb2e8f9f7 25 (#) Use HAL_CRC_Accumulate() function to compute the CRC value of the
<> 144:ef7eb2e8f9f7 26 input data buffer starting with the previously computed CRC as
<> 144:ef7eb2e8f9f7 27 initialization value
<> 144:ef7eb2e8f9f7 28 (#) Use HAL_CRC_Calculate() function to compute the CRC value of the
<> 144:ef7eb2e8f9f7 29 input data buffer starting with the defined initialization value
<> 144:ef7eb2e8f9f7 30 (default or non-default) to initiate CRC calculation
<> 144:ef7eb2e8f9f7 31
<> 144:ef7eb2e8f9f7 32 @endverbatim
<> 144:ef7eb2e8f9f7 33 ******************************************************************************
<> 144:ef7eb2e8f9f7 34 * @attention
<> 144:ef7eb2e8f9f7 35 *
<> 144:ef7eb2e8f9f7 36 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
<> 144:ef7eb2e8f9f7 37 *
<> 144:ef7eb2e8f9f7 38 * Redistribution and use in source and binary forms, with or without modification,
<> 144:ef7eb2e8f9f7 39 * are permitted provided that the following conditions are met:
<> 144:ef7eb2e8f9f7 40 * 1. Redistributions of source code must retain the above copyright notice,
<> 144:ef7eb2e8f9f7 41 * this list of conditions and the following disclaimer.
<> 144:ef7eb2e8f9f7 42 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 144:ef7eb2e8f9f7 43 * this list of conditions and the following disclaimer in the documentation
<> 144:ef7eb2e8f9f7 44 * and/or other materials provided with the distribution.
<> 144:ef7eb2e8f9f7 45 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 144:ef7eb2e8f9f7 46 * may be used to endorse or promote products derived from this software
<> 144:ef7eb2e8f9f7 47 * without specific prior written permission.
<> 144:ef7eb2e8f9f7 48 *
<> 144:ef7eb2e8f9f7 49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 144:ef7eb2e8f9f7 50 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 144:ef7eb2e8f9f7 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 144:ef7eb2e8f9f7 52 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 144:ef7eb2e8f9f7 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 144:ef7eb2e8f9f7 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 144:ef7eb2e8f9f7 55 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 144:ef7eb2e8f9f7 56 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 144:ef7eb2e8f9f7 57 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 144:ef7eb2e8f9f7 58 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 144:ef7eb2e8f9f7 59 *
<> 144:ef7eb2e8f9f7 60 ******************************************************************************
<> 144:ef7eb2e8f9f7 61 */
<> 144:ef7eb2e8f9f7 62
<> 144:ef7eb2e8f9f7 63 /* Includes ------------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 64 #include "stm32f0xx_hal.h"
<> 144:ef7eb2e8f9f7 65
<> 144:ef7eb2e8f9f7 66 /** @addtogroup STM32F0xx_HAL_Driver
<> 144:ef7eb2e8f9f7 67 * @{
<> 144:ef7eb2e8f9f7 68 */
<> 144:ef7eb2e8f9f7 69
<> 144:ef7eb2e8f9f7 70 /** @defgroup CRC CRC
<> 144:ef7eb2e8f9f7 71 * @brief CRC HAL module driver.
<> 144:ef7eb2e8f9f7 72 * @{
<> 144:ef7eb2e8f9f7 73 */
<> 144:ef7eb2e8f9f7 74
<> 144:ef7eb2e8f9f7 75 #ifdef HAL_CRC_MODULE_ENABLED
<> 144:ef7eb2e8f9f7 76
<> 144:ef7eb2e8f9f7 77 /* Private typedef -----------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 78 /* Private define ------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 79 /* Private macro -------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 80 /* Private variables ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 81 /* Private function prototypes -----------------------------------------------*/
<> 144:ef7eb2e8f9f7 82 /** @defgroup CRC_Private_Functions CRC Private Functions
<> 144:ef7eb2e8f9f7 83 * @{
<> 144:ef7eb2e8f9f7 84 */
<> 144:ef7eb2e8f9f7 85 static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength);
<> 144:ef7eb2e8f9f7 86 static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength);
<> 144:ef7eb2e8f9f7 87 /**
<> 144:ef7eb2e8f9f7 88 * @}
<> 144:ef7eb2e8f9f7 89 */
<> 144:ef7eb2e8f9f7 90
<> 144:ef7eb2e8f9f7 91 /* Exported functions ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 92 /** @defgroup CRC_Exported_Functions CRC Exported Functions
<> 144:ef7eb2e8f9f7 93 * @{
<> 144:ef7eb2e8f9f7 94 */
<> 144:ef7eb2e8f9f7 95
<> 144:ef7eb2e8f9f7 96 /** @defgroup CRC_Exported_Functions_Group1 Initialization/de-initialization functions
<> 144:ef7eb2e8f9f7 97 * @brief Initialization and Configuration functions.
<> 144:ef7eb2e8f9f7 98 *
<> 144:ef7eb2e8f9f7 99 @verbatim
<> 144:ef7eb2e8f9f7 100 ===============================================================================
<> 144:ef7eb2e8f9f7 101 ##### Initialization and Configuration functions #####
<> 144:ef7eb2e8f9f7 102 ===============================================================================
<> 144:ef7eb2e8f9f7 103 [..] This section provides functions allowing to:
<> 144:ef7eb2e8f9f7 104 (+) Initialize the CRC according to the specified parameters
<> 144:ef7eb2e8f9f7 105 in the CRC_InitTypeDef and create the associated handle
<> 144:ef7eb2e8f9f7 106 (+) DeInitialize the CRC peripheral
<> 144:ef7eb2e8f9f7 107 (+) Initialize the CRC MSP
<> 144:ef7eb2e8f9f7 108 (+) DeInitialize CRC MSP
<> 144:ef7eb2e8f9f7 109
<> 144:ef7eb2e8f9f7 110 @endverbatim
<> 144:ef7eb2e8f9f7 111 * @{
<> 144:ef7eb2e8f9f7 112 */
<> 144:ef7eb2e8f9f7 113
<> 144:ef7eb2e8f9f7 114 /**
<> 144:ef7eb2e8f9f7 115 * @brief Initializes the CRC according to the specified
<> 144:ef7eb2e8f9f7 116 * parameters in the CRC_InitTypeDef and creates the associated handle.
<> 144:ef7eb2e8f9f7 117 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 118 * @retval HAL status
<> 144:ef7eb2e8f9f7 119 */
<> 144:ef7eb2e8f9f7 120 HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 121 {
<> 144:ef7eb2e8f9f7 122 /* Check the CRC handle allocation */
<> 144:ef7eb2e8f9f7 123 if(hcrc == NULL)
<> 144:ef7eb2e8f9f7 124 {
<> 144:ef7eb2e8f9f7 125 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 126 }
<> 144:ef7eb2e8f9f7 127
<> 144:ef7eb2e8f9f7 128 /* Check the parameters */
<> 144:ef7eb2e8f9f7 129 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
<> 144:ef7eb2e8f9f7 130
<> 144:ef7eb2e8f9f7 131 if(hcrc->State == HAL_CRC_STATE_RESET)
<> 144:ef7eb2e8f9f7 132 {
<> 144:ef7eb2e8f9f7 133 /* Allocate lock resource and initialize it */
<> 144:ef7eb2e8f9f7 134 hcrc->Lock = HAL_UNLOCKED;
<> 144:ef7eb2e8f9f7 135 /* Init the low level hardware */
<> 144:ef7eb2e8f9f7 136 HAL_CRC_MspInit(hcrc);
<> 144:ef7eb2e8f9f7 137 }
<> 144:ef7eb2e8f9f7 138
<> 144:ef7eb2e8f9f7 139 hcrc->State = HAL_CRC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 140
<> 144:ef7eb2e8f9f7 141 /* Extended initialization: if programmable polynomial feature is
<> 144:ef7eb2e8f9f7 142 applicable to device, set default or non-default generating
<> 144:ef7eb2e8f9f7 143 polynomial according to hcrc->Init parameters.
<> 144:ef7eb2e8f9f7 144 If feature is non-applicable to device in use, HAL_CRCEx_Init straight
<> 144:ef7eb2e8f9f7 145 away reports HAL_OK. */
<> 144:ef7eb2e8f9f7 146 if (HAL_CRCEx_Init(hcrc) != HAL_OK)
<> 144:ef7eb2e8f9f7 147 {
<> 144:ef7eb2e8f9f7 148 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 149 }
<> 144:ef7eb2e8f9f7 150
<> 144:ef7eb2e8f9f7 151 /* check whether or not non-default CRC initial value has been
<> 144:ef7eb2e8f9f7 152 * picked up by user */
<> 144:ef7eb2e8f9f7 153 assert_param(IS_DEFAULT_INIT_VALUE(hcrc->Init.DefaultInitValueUse));
<> 144:ef7eb2e8f9f7 154 if (hcrc->Init.DefaultInitValueUse == DEFAULT_INIT_VALUE_ENABLE)
<> 144:ef7eb2e8f9f7 155 {
<> 144:ef7eb2e8f9f7 156 WRITE_REG(hcrc->Instance->INIT, DEFAULT_CRC_INITVALUE);
<> 144:ef7eb2e8f9f7 157 }
<> 144:ef7eb2e8f9f7 158 else
<> 144:ef7eb2e8f9f7 159 {
<> 144:ef7eb2e8f9f7 160 WRITE_REG(hcrc->Instance->INIT, hcrc->Init.InitValue);
<> 144:ef7eb2e8f9f7 161 }
<> 144:ef7eb2e8f9f7 162
<> 144:ef7eb2e8f9f7 163
<> 144:ef7eb2e8f9f7 164 /* set input data inversion mode */
<> 144:ef7eb2e8f9f7 165 assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(hcrc->Init.InputDataInversionMode));
<> 144:ef7eb2e8f9f7 166 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, hcrc->Init.InputDataInversionMode);
<> 144:ef7eb2e8f9f7 167
<> 144:ef7eb2e8f9f7 168 /* set output data inversion mode */
<> 144:ef7eb2e8f9f7 169 assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(hcrc->Init.OutputDataInversionMode));
<> 144:ef7eb2e8f9f7 170 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, hcrc->Init.OutputDataInversionMode);
<> 144:ef7eb2e8f9f7 171
<> 144:ef7eb2e8f9f7 172 /* makes sure the input data format (bytes, halfwords or words stream)
<> 144:ef7eb2e8f9f7 173 * is properly specified by user */
<> 144:ef7eb2e8f9f7 174 assert_param(IS_CRC_INPUTDATA_FORMAT(hcrc->InputDataFormat));
<> 144:ef7eb2e8f9f7 175
<> 144:ef7eb2e8f9f7 176 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 177 hcrc->State = HAL_CRC_STATE_READY;
<> 144:ef7eb2e8f9f7 178
<> 144:ef7eb2e8f9f7 179 /* Return function status */
<> 144:ef7eb2e8f9f7 180 return HAL_OK;
<> 144:ef7eb2e8f9f7 181 }
<> 144:ef7eb2e8f9f7 182
<> 144:ef7eb2e8f9f7 183 /**
<> 144:ef7eb2e8f9f7 184 * @brief DeInitializes the CRC peripheral.
<> 144:ef7eb2e8f9f7 185 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 186 * @retval HAL status
<> 144:ef7eb2e8f9f7 187 */
<> 144:ef7eb2e8f9f7 188 HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 189 {
<> 144:ef7eb2e8f9f7 190 /* Check the CRC handle allocation */
<> 144:ef7eb2e8f9f7 191 if(hcrc == NULL)
<> 144:ef7eb2e8f9f7 192 {
<> 144:ef7eb2e8f9f7 193 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 194 }
<> 144:ef7eb2e8f9f7 195
<> 144:ef7eb2e8f9f7 196 /* Check the parameters */
<> 144:ef7eb2e8f9f7 197 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
<> 144:ef7eb2e8f9f7 198
<> 144:ef7eb2e8f9f7 199 /* Check the CRC peripheral state */
<> 144:ef7eb2e8f9f7 200 if(hcrc->State == HAL_CRC_STATE_BUSY)
<> 144:ef7eb2e8f9f7 201 {
<> 144:ef7eb2e8f9f7 202 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 203 }
<> 144:ef7eb2e8f9f7 204
<> 144:ef7eb2e8f9f7 205 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 206 hcrc->State = HAL_CRC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 207
<> 144:ef7eb2e8f9f7 208 /* Reset IDR register content */
<> 144:ef7eb2e8f9f7 209 CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR) ;
<> 144:ef7eb2e8f9f7 210
<> 144:ef7eb2e8f9f7 211 /* DeInit the low level hardware */
<> 144:ef7eb2e8f9f7 212 HAL_CRC_MspDeInit(hcrc);
<> 144:ef7eb2e8f9f7 213
<> 144:ef7eb2e8f9f7 214 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 215 hcrc->State = HAL_CRC_STATE_RESET;
<> 144:ef7eb2e8f9f7 216
<> 144:ef7eb2e8f9f7 217 /* Process unlocked */
<> 144:ef7eb2e8f9f7 218 __HAL_UNLOCK(hcrc);
<> 144:ef7eb2e8f9f7 219
<> 144:ef7eb2e8f9f7 220 /* Return function status */
<> 144:ef7eb2e8f9f7 221 return HAL_OK;
<> 144:ef7eb2e8f9f7 222 }
<> 144:ef7eb2e8f9f7 223
<> 144:ef7eb2e8f9f7 224 /**
<> 144:ef7eb2e8f9f7 225 * @brief Initializes the CRC MSP.
<> 144:ef7eb2e8f9f7 226 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 227 * @retval None
<> 144:ef7eb2e8f9f7 228 */
<> 144:ef7eb2e8f9f7 229 __weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 230 {
<> 144:ef7eb2e8f9f7 231 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 232 UNUSED(hcrc);
<> 144:ef7eb2e8f9f7 233
<> 144:ef7eb2e8f9f7 234 /* NOTE : This function should not be modified, when the callback is needed,
<> 144:ef7eb2e8f9f7 235 the HAL_CRC_MspInit can be implemented in the user file
<> 144:ef7eb2e8f9f7 236 */
<> 144:ef7eb2e8f9f7 237 }
<> 144:ef7eb2e8f9f7 238
<> 144:ef7eb2e8f9f7 239 /**
<> 144:ef7eb2e8f9f7 240 * @brief DeInitializes the CRC MSP.
<> 144:ef7eb2e8f9f7 241 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 242 * @retval None
<> 144:ef7eb2e8f9f7 243 */
<> 144:ef7eb2e8f9f7 244 __weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 245 {
<> 144:ef7eb2e8f9f7 246 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 247 UNUSED(hcrc);
<> 144:ef7eb2e8f9f7 248
<> 144:ef7eb2e8f9f7 249 /* NOTE : This function should not be modified, when the callback is needed,
<> 144:ef7eb2e8f9f7 250 the HAL_CRC_MspDeInit can be implemented in the user file
<> 144:ef7eb2e8f9f7 251 */
<> 144:ef7eb2e8f9f7 252 }
<> 144:ef7eb2e8f9f7 253
<> 144:ef7eb2e8f9f7 254 /**
<> 144:ef7eb2e8f9f7 255 * @}
<> 144:ef7eb2e8f9f7 256 */
<> 144:ef7eb2e8f9f7 257
<> 144:ef7eb2e8f9f7 258 /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
<> 144:ef7eb2e8f9f7 259 * @brief management functions.
<> 144:ef7eb2e8f9f7 260 *
<> 144:ef7eb2e8f9f7 261 @verbatim
<> 144:ef7eb2e8f9f7 262 ===============================================================================
<> 144:ef7eb2e8f9f7 263 ##### Peripheral Control functions #####
<> 144:ef7eb2e8f9f7 264 ===============================================================================
<> 144:ef7eb2e8f9f7 265 [..] This section provides functions allowing to:
<> 144:ef7eb2e8f9f7 266 (+) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
<> 144:ef7eb2e8f9f7 267 using combination of the previous CRC value and the new one.
<> 144:ef7eb2e8f9f7 268
<> 144:ef7eb2e8f9f7 269 or
<> 144:ef7eb2e8f9f7 270
<> 144:ef7eb2e8f9f7 271 (+) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
<> 144:ef7eb2e8f9f7 272 independently of the previous CRC value.
<> 144:ef7eb2e8f9f7 273
<> 144:ef7eb2e8f9f7 274 @endverbatim
<> 144:ef7eb2e8f9f7 275 * @{
<> 144:ef7eb2e8f9f7 276 */
<> 144:ef7eb2e8f9f7 277
<> 144:ef7eb2e8f9f7 278 /**
<> 144:ef7eb2e8f9f7 279 * @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
<> 144:ef7eb2e8f9f7 280 * starting with the previously computed CRC as initialization value.
<> 144:ef7eb2e8f9f7 281 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 282 * @param pBuffer: pointer to the input data buffer, exact input data format is
<> 144:ef7eb2e8f9f7 283 * provided by hcrc->InputDataFormat.
<> 144:ef7eb2e8f9f7 284 * @param BufferLength: input data buffer length (number of bytes if pBuffer
<> 144:ef7eb2e8f9f7 285 * type is * uint8_t, number of half-words if pBuffer type is * uint16_t,
<> 144:ef7eb2e8f9f7 286 * number of words if pBuffer type is * uint32_t).
<> 144:ef7eb2e8f9f7 287 * @note By default, the API expects a uint32_t pointer as input buffer parameter.
<> 144:ef7eb2e8f9f7 288 * Input buffer pointers with other types simply need to be cast in uint32_t
<> 144:ef7eb2e8f9f7 289 * and the API will internally adjust its input data processing based on the
<> 144:ef7eb2e8f9f7 290 * handle field hcrc->InputDataFormat.
<> 144:ef7eb2e8f9f7 291 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
<> 144:ef7eb2e8f9f7 292 */
<> 144:ef7eb2e8f9f7 293 uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
<> 144:ef7eb2e8f9f7 294 {
<> 144:ef7eb2e8f9f7 295 uint32_t index = 0; /* CRC input data buffer index */
<> 144:ef7eb2e8f9f7 296 uint32_t temp = 0; /* CRC output (read from hcrc->Instance->DR register) */
<> 144:ef7eb2e8f9f7 297
<> 144:ef7eb2e8f9f7 298 /* Process locked */
<> 144:ef7eb2e8f9f7 299 __HAL_LOCK(hcrc);
<> 144:ef7eb2e8f9f7 300
<> 144:ef7eb2e8f9f7 301 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 302 hcrc->State = HAL_CRC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 303
<> 144:ef7eb2e8f9f7 304 switch (hcrc->InputDataFormat)
<> 144:ef7eb2e8f9f7 305 {
<> 144:ef7eb2e8f9f7 306 case CRC_INPUTDATA_FORMAT_WORDS:
<> 144:ef7eb2e8f9f7 307 /* Enter Data to the CRC calculator */
<> 144:ef7eb2e8f9f7 308 for(index = 0; index < BufferLength; index++)
<> 144:ef7eb2e8f9f7 309 {
<> 144:ef7eb2e8f9f7 310 hcrc->Instance->DR = pBuffer[index];
<> 144:ef7eb2e8f9f7 311 }
<> 144:ef7eb2e8f9f7 312 temp = hcrc->Instance->DR;
<> 144:ef7eb2e8f9f7 313 break;
<> 144:ef7eb2e8f9f7 314
<> 144:ef7eb2e8f9f7 315 case CRC_INPUTDATA_FORMAT_BYTES:
<> 144:ef7eb2e8f9f7 316 temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);
<> 144:ef7eb2e8f9f7 317 break;
<> 144:ef7eb2e8f9f7 318
<> 144:ef7eb2e8f9f7 319 case CRC_INPUTDATA_FORMAT_HALFWORDS:
<> 144:ef7eb2e8f9f7 320 temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);
<> 144:ef7eb2e8f9f7 321 break;
<> 144:ef7eb2e8f9f7 322
<> 144:ef7eb2e8f9f7 323 default:
<> 144:ef7eb2e8f9f7 324 break;
<> 144:ef7eb2e8f9f7 325 }
<> 144:ef7eb2e8f9f7 326
<> 144:ef7eb2e8f9f7 327 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 328 hcrc->State = HAL_CRC_STATE_READY;
<> 144:ef7eb2e8f9f7 329
<> 144:ef7eb2e8f9f7 330 /* Process unlocked */
<> 144:ef7eb2e8f9f7 331 __HAL_UNLOCK(hcrc);
<> 144:ef7eb2e8f9f7 332
<> 144:ef7eb2e8f9f7 333 /* Return the CRC computed value */
<> 144:ef7eb2e8f9f7 334 return temp;
<> 144:ef7eb2e8f9f7 335 }
<> 144:ef7eb2e8f9f7 336
<> 144:ef7eb2e8f9f7 337
<> 144:ef7eb2e8f9f7 338 /**
<> 144:ef7eb2e8f9f7 339 * @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
<> 144:ef7eb2e8f9f7 340 * starting with hcrc->Instance->INIT as initialization value.
<> 144:ef7eb2e8f9f7 341 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 342 * @param pBuffer: pointer to the input data buffer, exact input data format is
<> 144:ef7eb2e8f9f7 343 * provided by hcrc->InputDataFormat.
<> 144:ef7eb2e8f9f7 344 * @param BufferLength: input data buffer length (number of bytes if pBuffer
<> 144:ef7eb2e8f9f7 345 * type is * uint8_t, number of half-words if pBuffer type is * uint16_t,
<> 144:ef7eb2e8f9f7 346 * number of words if pBuffer type is * uint32_t).
<> 144:ef7eb2e8f9f7 347 * @note By default, the API expects a uint32_t pointer as input buffer parameter.
<> 144:ef7eb2e8f9f7 348 * Input buffer pointers with other types simply need to be cast in uint32_t
<> 144:ef7eb2e8f9f7 349 * and the API will internally adjust its input data processing based on the
<> 144:ef7eb2e8f9f7 350 * handle field hcrc->InputDataFormat.
<> 144:ef7eb2e8f9f7 351 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
<> 144:ef7eb2e8f9f7 352 */
<> 144:ef7eb2e8f9f7 353 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
<> 144:ef7eb2e8f9f7 354 {
<> 144:ef7eb2e8f9f7 355 uint32_t index = 0; /* CRC input data buffer index */
<> 144:ef7eb2e8f9f7 356 uint32_t temp = 0; /* CRC output (read from hcrc->Instance->DR register) */
<> 144:ef7eb2e8f9f7 357
<> 144:ef7eb2e8f9f7 358 /* Process locked */
<> 144:ef7eb2e8f9f7 359 __HAL_LOCK(hcrc);
<> 144:ef7eb2e8f9f7 360
<> 144:ef7eb2e8f9f7 361 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 362 hcrc->State = HAL_CRC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 363
<> 144:ef7eb2e8f9f7 364 /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
<> 144:ef7eb2e8f9f7 365 * written in hcrc->Instance->DR) */
<> 144:ef7eb2e8f9f7 366 __HAL_CRC_DR_RESET(hcrc);
<> 144:ef7eb2e8f9f7 367
<> 144:ef7eb2e8f9f7 368 switch (hcrc->InputDataFormat)
<> 144:ef7eb2e8f9f7 369 {
<> 144:ef7eb2e8f9f7 370 case CRC_INPUTDATA_FORMAT_WORDS:
<> 144:ef7eb2e8f9f7 371 /* Enter 32-bit input data to the CRC calculator */
<> 144:ef7eb2e8f9f7 372 for(index = 0; index < BufferLength; index++)
<> 144:ef7eb2e8f9f7 373 {
<> 144:ef7eb2e8f9f7 374 hcrc->Instance->DR = pBuffer[index];
<> 144:ef7eb2e8f9f7 375 }
<> 144:ef7eb2e8f9f7 376 temp = hcrc->Instance->DR;
<> 144:ef7eb2e8f9f7 377 break;
<> 144:ef7eb2e8f9f7 378
<> 144:ef7eb2e8f9f7 379 case CRC_INPUTDATA_FORMAT_BYTES:
<> 144:ef7eb2e8f9f7 380 /* Specific 8-bit input data handling */
<> 144:ef7eb2e8f9f7 381 temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);
<> 144:ef7eb2e8f9f7 382 break;
<> 144:ef7eb2e8f9f7 383
<> 144:ef7eb2e8f9f7 384 case CRC_INPUTDATA_FORMAT_HALFWORDS:
<> 144:ef7eb2e8f9f7 385 /* Specific 16-bit input data handling */
<> 144:ef7eb2e8f9f7 386 temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);
<> 144:ef7eb2e8f9f7 387 break;
<> 144:ef7eb2e8f9f7 388
<> 144:ef7eb2e8f9f7 389 default:
<> 144:ef7eb2e8f9f7 390 break;
<> 144:ef7eb2e8f9f7 391 }
<> 144:ef7eb2e8f9f7 392
<> 144:ef7eb2e8f9f7 393 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 394 hcrc->State = HAL_CRC_STATE_READY;
<> 144:ef7eb2e8f9f7 395
<> 144:ef7eb2e8f9f7 396 /* Process unlocked */
<> 144:ef7eb2e8f9f7 397 __HAL_UNLOCK(hcrc);
<> 144:ef7eb2e8f9f7 398
<> 144:ef7eb2e8f9f7 399 /* Return the CRC computed value */
<> 144:ef7eb2e8f9f7 400 return temp;
<> 144:ef7eb2e8f9f7 401 }
<> 144:ef7eb2e8f9f7 402 /**
<> 144:ef7eb2e8f9f7 403 * @}
<> 144:ef7eb2e8f9f7 404 */
<> 144:ef7eb2e8f9f7 405
<> 144:ef7eb2e8f9f7 406 /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
<> 144:ef7eb2e8f9f7 407 * @brief Peripheral State functions.
<> 144:ef7eb2e8f9f7 408 *
<> 144:ef7eb2e8f9f7 409 @verbatim
<> 144:ef7eb2e8f9f7 410 ===============================================================================
<> 144:ef7eb2e8f9f7 411 ##### Peripheral State functions #####
<> 144:ef7eb2e8f9f7 412 ===============================================================================
<> 144:ef7eb2e8f9f7 413 [..]
<> 144:ef7eb2e8f9f7 414 This subsection permits to get in run-time the status of the peripheral
<> 144:ef7eb2e8f9f7 415 and the data flow.
<> 144:ef7eb2e8f9f7 416
<> 144:ef7eb2e8f9f7 417 @endverbatim
<> 144:ef7eb2e8f9f7 418 * @{
<> 144:ef7eb2e8f9f7 419 */
<> 144:ef7eb2e8f9f7 420
<> 144:ef7eb2e8f9f7 421 /**
<> 144:ef7eb2e8f9f7 422 * @brief Returns the CRC state.
<> 144:ef7eb2e8f9f7 423 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 424 * @retval HAL state
<> 144:ef7eb2e8f9f7 425 */
<> 144:ef7eb2e8f9f7 426 HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 427 {
<> 144:ef7eb2e8f9f7 428 return hcrc->State;
<> 144:ef7eb2e8f9f7 429 }
<> 144:ef7eb2e8f9f7 430
<> 144:ef7eb2e8f9f7 431 /**
<> 144:ef7eb2e8f9f7 432 * @}
<> 144:ef7eb2e8f9f7 433 */
<> 144:ef7eb2e8f9f7 434
<> 144:ef7eb2e8f9f7 435 /**
<> 144:ef7eb2e8f9f7 436 * @}
<> 144:ef7eb2e8f9f7 437 */
<> 144:ef7eb2e8f9f7 438
<> 144:ef7eb2e8f9f7 439 /** @addtogroup CRC_Private_Functions CRC Private Functions
<> 144:ef7eb2e8f9f7 440 * @{
<> 144:ef7eb2e8f9f7 441 */
<> 144:ef7eb2e8f9f7 442 /**
<> 144:ef7eb2e8f9f7 443 * @brief Enter 8-bit input data to the CRC calculator.
<> 144:ef7eb2e8f9f7 444 * Specific data handling to optimize processing time.
<> 144:ef7eb2e8f9f7 445 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 446 * @param pBuffer: pointer to the input data buffer
<> 144:ef7eb2e8f9f7 447 * @param BufferLength: input data buffer length
<> 144:ef7eb2e8f9f7 448 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
<> 144:ef7eb2e8f9f7 449 */
<> 144:ef7eb2e8f9f7 450 static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)
<> 144:ef7eb2e8f9f7 451 {
<> 144:ef7eb2e8f9f7 452 uint32_t i = 0; /* input data buffer index */
<> 144:ef7eb2e8f9f7 453
<> 144:ef7eb2e8f9f7 454 /* Processing time optimization: 4 bytes are entered in a row with a single word write,
<> 144:ef7eb2e8f9f7 455 * last bytes must be carefully fed to the CRC calculator to ensure a correct type
<> 144:ef7eb2e8f9f7 456 * handling by the IP */
<> 144:ef7eb2e8f9f7 457 for(i = 0; i < (BufferLength/4); i++)
<> 144:ef7eb2e8f9f7 458 {
<> 144:ef7eb2e8f9f7 459 hcrc->Instance->DR = ((uint32_t)pBuffer[4*i]<<24) | ((uint32_t)pBuffer[4*i+1]<<16) | ((uint32_t)pBuffer[4*i+2]<<8) | (uint32_t)pBuffer[4*i+3];
<> 144:ef7eb2e8f9f7 460 }
<> 144:ef7eb2e8f9f7 461 /* last bytes specific handling */
<> 144:ef7eb2e8f9f7 462 if ((BufferLength%4) != 0)
<> 144:ef7eb2e8f9f7 463 {
<> 144:ef7eb2e8f9f7 464 if (BufferLength%4 == 1)
<> 144:ef7eb2e8f9f7 465 {
<> 144:ef7eb2e8f9f7 466 *(uint8_t*) (&hcrc->Instance->DR) = pBuffer[4*i];
<> 144:ef7eb2e8f9f7 467 }
<> 144:ef7eb2e8f9f7 468 if (BufferLength%4 == 2)
<> 144:ef7eb2e8f9f7 469 {
<> 144:ef7eb2e8f9f7 470 *(uint16_t*) (&hcrc->Instance->DR) = ((uint16_t)pBuffer[4*i]<<8) | (uint16_t)pBuffer[4*i+1];
<> 144:ef7eb2e8f9f7 471 }
<> 144:ef7eb2e8f9f7 472 if (BufferLength%4 == 3)
<> 144:ef7eb2e8f9f7 473 {
<> 144:ef7eb2e8f9f7 474 *(uint16_t*) (&hcrc->Instance->DR) = ((uint16_t)pBuffer[4*i]<<8) | (uint16_t)pBuffer[4*i+1];
<> 144:ef7eb2e8f9f7 475 *(uint8_t*) (&hcrc->Instance->DR) = pBuffer[4*i+2];
<> 144:ef7eb2e8f9f7 476 }
<> 144:ef7eb2e8f9f7 477 }
<> 144:ef7eb2e8f9f7 478
<> 144:ef7eb2e8f9f7 479 /* Return the CRC computed value */
<> 144:ef7eb2e8f9f7 480 return hcrc->Instance->DR;
<> 144:ef7eb2e8f9f7 481 }
<> 144:ef7eb2e8f9f7 482
<> 144:ef7eb2e8f9f7 483
<> 144:ef7eb2e8f9f7 484
<> 144:ef7eb2e8f9f7 485 /**
<> 144:ef7eb2e8f9f7 486 * @brief Enter 16-bit input data to the CRC calculator.
<> 144:ef7eb2e8f9f7 487 * Specific data handling to optimize processing time.
<> 144:ef7eb2e8f9f7 488 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 489 * @param pBuffer: pointer to the input data buffer
<> 144:ef7eb2e8f9f7 490 * @param BufferLength: input data buffer length
<> 144:ef7eb2e8f9f7 491 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
<> 144:ef7eb2e8f9f7 492 */
<> 144:ef7eb2e8f9f7 493 static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength)
<> 144:ef7eb2e8f9f7 494 {
<> 144:ef7eb2e8f9f7 495 uint32_t i = 0; /* input data buffer index */
<> 144:ef7eb2e8f9f7 496
<> 144:ef7eb2e8f9f7 497 /* Processing time optimization: 2 HalfWords are entered in a row with a single word write,
<> 144:ef7eb2e8f9f7 498 * in case of odd length, last HalfWord must be carefully fed to the CRC calculator to ensure
<> 144:ef7eb2e8f9f7 499 * a correct type handling by the IP */
<> 144:ef7eb2e8f9f7 500 for(i = 0; i < (BufferLength/2); i++)
<> 144:ef7eb2e8f9f7 501 {
<> 144:ef7eb2e8f9f7 502 hcrc->Instance->DR = (pBuffer[2*i]<<16) | pBuffer[2*i+1];
<> 144:ef7eb2e8f9f7 503 }
<> 144:ef7eb2e8f9f7 504 if ((BufferLength%2) != 0)
<> 144:ef7eb2e8f9f7 505 {
<> 144:ef7eb2e8f9f7 506 *(uint16_t*) (&hcrc->Instance->DR) = pBuffer[2*i];
<> 144:ef7eb2e8f9f7 507 }
<> 144:ef7eb2e8f9f7 508
<> 144:ef7eb2e8f9f7 509 /* Return the CRC computed value */
<> 144:ef7eb2e8f9f7 510 return hcrc->Instance->DR;
<> 144:ef7eb2e8f9f7 511 }
<> 144:ef7eb2e8f9f7 512 /**
<> 144:ef7eb2e8f9f7 513 * @}
<> 144:ef7eb2e8f9f7 514 */
<> 144:ef7eb2e8f9f7 515
<> 144:ef7eb2e8f9f7 516 /**
<> 144:ef7eb2e8f9f7 517 * @}
<> 144:ef7eb2e8f9f7 518 */
<> 144:ef7eb2e8f9f7 519
<> 144:ef7eb2e8f9f7 520 #endif /* HAL_CRC_MODULE_ENABLED */
<> 144:ef7eb2e8f9f7 521 /**
<> 144:ef7eb2e8f9f7 522 * @}
<> 144:ef7eb2e8f9f7 523 */
<> 144:ef7eb2e8f9f7 524
<> 144:ef7eb2e8f9f7 525 /**
<> 144:ef7eb2e8f9f7 526 * @}
<> 144:ef7eb2e8f9f7 527 */
<> 144:ef7eb2e8f9f7 528
<> 144:ef7eb2e8f9f7 529 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/