mbed library sources. Supersedes mbed-src.

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

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
184:08ed48f1de7f
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**
<> 149:156823d33999 2 ******************************************************************************
<> 149:156823d33999 3 * @file stm32l1xx_hal_crc.c
<> 149:156823d33999 4 * @author MCD Application Team
<> 149:156823d33999 5 * @brief CRC HAL module driver.
<> 149:156823d33999 6 * This file provides firmware functions to manage the following
<> 149:156823d33999 7 * functionalities of the Cyclic Redundancy Check (CRC) peripheral:
<> 149:156823d33999 8 * + Initialization and de-initialization functions
<> 149:156823d33999 9 * + Peripheral Control functions
<> 149:156823d33999 10 * + Peripheral State functions
<> 149:156823d33999 11 *
<> 149:156823d33999 12 @verbatim
<> 149:156823d33999 13 ==============================================================================
<> 149:156823d33999 14 ##### How to use this driver #####
<> 149:156823d33999 15 ==============================================================================
<> 149:156823d33999 16 [..]
<> 149:156823d33999 17 The CRC HAL driver can be used as follows:
<> 149:156823d33999 18
<> 149:156823d33999 19 (#) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
<> 149:156823d33999 20
<> 149:156823d33999 21 (#) Use HAL_CRC_Accumulate() function to compute the CRC value of
<> 149:156823d33999 22 a 32-bit data buffer using combination of the previous CRC value
<> 149:156823d33999 23 and the new one.
<> 149:156823d33999 24
<> 149:156823d33999 25 (#) Use HAL_CRC_Calculate() function to compute the CRC Value of
<> 149:156823d33999 26 a new 32-bit data buffer. This function resets the CRC computation
<> 149:156823d33999 27 unit before starting the computation to avoid getting wrong CRC values.
<> 149:156823d33999 28
<> 149:156823d33999 29 @endverbatim
<> 149:156823d33999 30 ******************************************************************************
<> 149:156823d33999 31 * @attention
<> 149:156823d33999 32 *
AnnaBridge 184:08ed48f1de7f 33 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
<> 149:156823d33999 34 *
<> 149:156823d33999 35 * Redistribution and use in source and binary forms, with or without modification,
<> 149:156823d33999 36 * are permitted provided that the following conditions are met:
<> 149:156823d33999 37 * 1. Redistributions of source code must retain the above copyright notice,
<> 149:156823d33999 38 * this list of conditions and the following disclaimer.
<> 149:156823d33999 39 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 149:156823d33999 40 * this list of conditions and the following disclaimer in the documentation
<> 149:156823d33999 41 * and/or other materials provided with the distribution.
<> 149:156823d33999 42 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 149:156823d33999 43 * may be used to endorse or promote products derived from this software
<> 149:156823d33999 44 * without specific prior written permission.
<> 149:156823d33999 45 *
<> 149:156823d33999 46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 149:156823d33999 47 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 149:156823d33999 48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 149:156823d33999 49 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 149:156823d33999 50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 149:156823d33999 51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 149:156823d33999 52 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 149:156823d33999 53 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 149:156823d33999 54 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 149:156823d33999 55 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 149:156823d33999 56 *
<> 149:156823d33999 57 ******************************************************************************
<> 149:156823d33999 58 */
<> 149:156823d33999 59
<> 149:156823d33999 60 /* Includes ------------------------------------------------------------------*/
<> 149:156823d33999 61 #include "stm32l1xx_hal.h"
<> 149:156823d33999 62
<> 149:156823d33999 63 /** @addtogroup STM32L1xx_HAL_Driver
<> 149:156823d33999 64 * @{
<> 149:156823d33999 65 */
<> 149:156823d33999 66
<> 149:156823d33999 67 /** @defgroup CRC CRC
<> 149:156823d33999 68 * @brief CRC HAL module driver.
<> 149:156823d33999 69 * @{
<> 149:156823d33999 70 */
<> 149:156823d33999 71
<> 149:156823d33999 72 #ifdef HAL_CRC_MODULE_ENABLED
<> 149:156823d33999 73
<> 149:156823d33999 74 /* Private typedef -----------------------------------------------------------*/
<> 149:156823d33999 75 /* Private define ------------------------------------------------------------*/
<> 149:156823d33999 76 /* Private macro -------------------------------------------------------------*/
<> 149:156823d33999 77 /* Private variables ---------------------------------------------------------*/
<> 149:156823d33999 78 /* Private function prototypes -----------------------------------------------*/
<> 149:156823d33999 79 /* Private functions ---------------------------------------------------------*/
<> 149:156823d33999 80
<> 149:156823d33999 81 /** @defgroup CRC_Exported_Functions CRC Exported Functions
<> 149:156823d33999 82 * @{
<> 149:156823d33999 83 */
<> 149:156823d33999 84
<> 149:156823d33999 85 /** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
<> 149:156823d33999 86 * @brief Initialization and Configuration functions.
<> 149:156823d33999 87 *
<> 149:156823d33999 88 @verbatim
<> 149:156823d33999 89 ==============================================================================
<> 149:156823d33999 90 ##### Initialization and de-initialization functions #####
<> 149:156823d33999 91 ==============================================================================
<> 149:156823d33999 92 [..] This section provides functions allowing to:
<> 149:156823d33999 93 (+) Initialize the CRC according to the specified parameters
<> 149:156823d33999 94 in the CRC_InitTypeDef and create the associated handle
<> 149:156823d33999 95 (+) DeInitialize the CRC peripheral
<> 149:156823d33999 96 (+) Initialize the CRC MSP
<> 149:156823d33999 97 (+) DeInitialize CRC MSP
<> 149:156823d33999 98
<> 149:156823d33999 99 @endverbatim
<> 149:156823d33999 100 * @{
<> 149:156823d33999 101 */
<> 149:156823d33999 102
<> 149:156823d33999 103 /**
<> 149:156823d33999 104 * @brief Initializes the CRC according to the specified
<> 149:156823d33999 105 * parameters in the CRC_InitTypeDef and creates the associated handle.
<> 149:156823d33999 106 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
<> 149:156823d33999 107 * the configuration information for CRC
<> 149:156823d33999 108 * @retval HAL status
<> 149:156823d33999 109 */
<> 149:156823d33999 110 HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
<> 149:156823d33999 111 {
<> 149:156823d33999 112 /* Check the CRC handle allocation */
<> 149:156823d33999 113 if(hcrc == NULL)
<> 149:156823d33999 114 {
<> 149:156823d33999 115 return HAL_ERROR;
<> 149:156823d33999 116 }
<> 149:156823d33999 117
<> 149:156823d33999 118 /* Check the parameters */
<> 149:156823d33999 119 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
<> 149:156823d33999 120
<> 149:156823d33999 121 if(hcrc->State == HAL_CRC_STATE_RESET)
<> 149:156823d33999 122 {
<> 149:156823d33999 123 /* Allocate lock resource and initialize it */
<> 149:156823d33999 124 hcrc->Lock = HAL_UNLOCKED;
<> 149:156823d33999 125
<> 149:156823d33999 126 /* Init the low level hardware */
<> 149:156823d33999 127 HAL_CRC_MspInit(hcrc);
<> 149:156823d33999 128 }
<> 149:156823d33999 129
<> 149:156823d33999 130 /* Change CRC peripheral state */
<> 149:156823d33999 131 hcrc->State = HAL_CRC_STATE_BUSY;
<> 149:156823d33999 132
<> 149:156823d33999 133 /* Change CRC peripheral state */
<> 149:156823d33999 134 hcrc->State = HAL_CRC_STATE_READY;
<> 149:156823d33999 135
<> 149:156823d33999 136 /* Return function status */
<> 149:156823d33999 137 return HAL_OK;
<> 149:156823d33999 138 }
<> 149:156823d33999 139
<> 149:156823d33999 140 /**
<> 149:156823d33999 141 * @brief DeInitializes the CRC peripheral.
<> 149:156823d33999 142 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
<> 149:156823d33999 143 * the configuration information for CRC
<> 149:156823d33999 144 * @retval HAL status
<> 149:156823d33999 145 */
<> 149:156823d33999 146 HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
<> 149:156823d33999 147 {
<> 149:156823d33999 148 /* Check the CRC handle allocation */
<> 149:156823d33999 149 if(hcrc == NULL)
<> 149:156823d33999 150 {
<> 149:156823d33999 151 return HAL_ERROR;
<> 149:156823d33999 152 }
<> 149:156823d33999 153
<> 149:156823d33999 154 /* Check the parameters */
<> 149:156823d33999 155 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
<> 149:156823d33999 156
<> 149:156823d33999 157 /* Change CRC peripheral state */
<> 149:156823d33999 158 hcrc->State = HAL_CRC_STATE_BUSY;
<> 149:156823d33999 159
<> 149:156823d33999 160 /* Reset IDR register content */
<> 149:156823d33999 161 CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR) ;
<> 149:156823d33999 162
<> 149:156823d33999 163 /* DeInit the low level hardware */
<> 149:156823d33999 164 HAL_CRC_MspDeInit(hcrc);
<> 149:156823d33999 165
<> 149:156823d33999 166 /* Change CRC peripheral state */
<> 149:156823d33999 167 hcrc->State = HAL_CRC_STATE_RESET;
<> 149:156823d33999 168
<> 149:156823d33999 169 /* Release Lock */
<> 149:156823d33999 170 __HAL_UNLOCK(hcrc);
<> 149:156823d33999 171
<> 149:156823d33999 172 /* Return function status */
<> 149:156823d33999 173 return HAL_OK;
<> 149:156823d33999 174 }
<> 149:156823d33999 175
<> 149:156823d33999 176 /**
<> 149:156823d33999 177 * @brief Initializes the CRC MSP.
<> 149:156823d33999 178 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
<> 149:156823d33999 179 * the configuration information for CRC
<> 149:156823d33999 180 * @retval None
<> 149:156823d33999 181 */
<> 149:156823d33999 182 __weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
<> 149:156823d33999 183 {
<> 149:156823d33999 184 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 185 UNUSED(hcrc);
<> 149:156823d33999 186
<> 149:156823d33999 187 /* NOTE : This function Should not be modified, when the callback is needed,
<> 149:156823d33999 188 the HAL_CRC_MspInit could be implemented in the user file
<> 149:156823d33999 189 */
<> 149:156823d33999 190 }
<> 149:156823d33999 191
<> 149:156823d33999 192 /**
<> 149:156823d33999 193 * @brief DeInitializes the CRC MSP.
<> 149:156823d33999 194 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
<> 149:156823d33999 195 * the configuration information for CRC
<> 149:156823d33999 196 * @retval None
<> 149:156823d33999 197 */
<> 149:156823d33999 198 __weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
<> 149:156823d33999 199 {
<> 149:156823d33999 200 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 201 UNUSED(hcrc);
<> 149:156823d33999 202
<> 149:156823d33999 203 /* NOTE : This function Should not be modified, when the callback is needed,
<> 149:156823d33999 204 the HAL_CRC_MspDeInit could be implemented in the user file
<> 149:156823d33999 205 */
<> 149:156823d33999 206 }
<> 149:156823d33999 207
<> 149:156823d33999 208 /**
<> 149:156823d33999 209 * @}
<> 149:156823d33999 210 */
<> 149:156823d33999 211
<> 149:156823d33999 212 /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
<> 149:156823d33999 213 * @brief management functions.
<> 149:156823d33999 214 *
<> 149:156823d33999 215 @verbatim
<> 149:156823d33999 216 ==============================================================================
<> 149:156823d33999 217 ##### Peripheral Control functions #####
<> 149:156823d33999 218 ==============================================================================
<> 149:156823d33999 219 [..] This section provides functions allowing to:
<> 149:156823d33999 220 (+) Compute the 32-bit CRC value of 32-bit data buffer,
<> 149:156823d33999 221 using combination of the previous CRC value and the new one.
<> 149:156823d33999 222 (+) Compute the 32-bit CRC value of 32-bit data buffer,
<> 149:156823d33999 223 independently of the previous CRC value.
<> 149:156823d33999 224
<> 149:156823d33999 225 @endverbatim
<> 149:156823d33999 226 * @{
<> 149:156823d33999 227 */
<> 149:156823d33999 228
<> 149:156823d33999 229 /**
<> 149:156823d33999 230 * @brief Computes the 32-bit CRC of 32-bit data buffer using combination
<> 149:156823d33999 231 * of the previous CRC value and the new one.
<> 149:156823d33999 232 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
<> 149:156823d33999 233 * the configuration information for CRC
<> 149:156823d33999 234 * @param pBuffer: pointer to the buffer containing the data to be computed
<> 149:156823d33999 235 * @param BufferLength: length of the buffer to be computed (defined in word, 4 bytes)
<> 149:156823d33999 236 * @retval 32-bit CRC
<> 149:156823d33999 237 */
<> 149:156823d33999 238 uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
<> 149:156823d33999 239 {
<> 149:156823d33999 240 uint32_t index = 0;
<> 149:156823d33999 241
<> 149:156823d33999 242 /* Process Locked */
<> 149:156823d33999 243 __HAL_LOCK(hcrc);
<> 149:156823d33999 244
<> 149:156823d33999 245 /* Change CRC peripheral state */
<> 149:156823d33999 246 hcrc->State = HAL_CRC_STATE_BUSY;
<> 149:156823d33999 247
<> 149:156823d33999 248 /* Enter Data to the CRC calculator */
<> 149:156823d33999 249 for(index = 0; index < BufferLength; index++)
<> 149:156823d33999 250 {
<> 149:156823d33999 251 hcrc->Instance->DR = pBuffer[index];
<> 149:156823d33999 252 }
<> 149:156823d33999 253
<> 149:156823d33999 254 /* Change CRC peripheral state */
<> 149:156823d33999 255 hcrc->State = HAL_CRC_STATE_READY;
<> 149:156823d33999 256
<> 149:156823d33999 257 /* Process Unlocked */
<> 149:156823d33999 258 __HAL_UNLOCK(hcrc);
<> 149:156823d33999 259
<> 149:156823d33999 260 /* Return the CRC computed value */
<> 149:156823d33999 261 return hcrc->Instance->DR;
<> 149:156823d33999 262 }
<> 149:156823d33999 263
<> 149:156823d33999 264 /**
<> 149:156823d33999 265 * @brief Computes the 32-bit CRC of 32-bit data buffer independently
<> 149:156823d33999 266 * of the previous CRC value.
<> 149:156823d33999 267 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
<> 149:156823d33999 268 * the configuration information for CRC
<> 149:156823d33999 269 * @param pBuffer: Pointer to the buffer containing the data to be computed
<> 149:156823d33999 270 * @param BufferLength: Length of the buffer to be computed (defined in word, 4 bytes)
<> 149:156823d33999 271 * @retval 32-bit CRC
<> 149:156823d33999 272 */
<> 149:156823d33999 273 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
<> 149:156823d33999 274 {
<> 149:156823d33999 275 uint32_t index = 0;
<> 149:156823d33999 276
<> 149:156823d33999 277 /* Process Locked */
<> 149:156823d33999 278 __HAL_LOCK(hcrc);
<> 149:156823d33999 279
<> 149:156823d33999 280 /* Change CRC peripheral state */
<> 149:156823d33999 281 hcrc->State = HAL_CRC_STATE_BUSY;
<> 149:156823d33999 282
<> 149:156823d33999 283 /* Reset CRC Calculation Unit */
<> 149:156823d33999 284 __HAL_CRC_DR_RESET(hcrc);
<> 149:156823d33999 285
<> 149:156823d33999 286 /* Enter Data to the CRC calculator */
<> 149:156823d33999 287 for(index = 0; index < BufferLength; index++)
<> 149:156823d33999 288 {
<> 149:156823d33999 289 hcrc->Instance->DR = pBuffer[index];
<> 149:156823d33999 290 }
<> 149:156823d33999 291
<> 149:156823d33999 292 /* Change CRC peripheral state */
<> 149:156823d33999 293 hcrc->State = HAL_CRC_STATE_READY;
<> 149:156823d33999 294
<> 149:156823d33999 295 /* Process Unlocked */
<> 149:156823d33999 296 __HAL_UNLOCK(hcrc);
<> 149:156823d33999 297
<> 149:156823d33999 298 /* Return the CRC computed value */
<> 149:156823d33999 299 return hcrc->Instance->DR;
<> 149:156823d33999 300 }
<> 149:156823d33999 301
<> 149:156823d33999 302 /**
<> 149:156823d33999 303 * @}
<> 149:156823d33999 304 */
<> 149:156823d33999 305
<> 149:156823d33999 306 /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
<> 149:156823d33999 307 * @brief Peripheral State functions.
<> 149:156823d33999 308 *
<> 149:156823d33999 309 @verbatim
<> 149:156823d33999 310 ==============================================================================
<> 149:156823d33999 311 ##### Peripheral State functions #####
<> 149:156823d33999 312 ==============================================================================
<> 149:156823d33999 313 [..]
<> 149:156823d33999 314 This subsection permits to get in run-time the status of the peripheral
<> 149:156823d33999 315 and the data flow.
<> 149:156823d33999 316
<> 149:156823d33999 317 @endverbatim
<> 149:156823d33999 318 * @{
<> 149:156823d33999 319 */
<> 149:156823d33999 320
<> 149:156823d33999 321 /**
<> 149:156823d33999 322 * @brief Returns the CRC state.
<> 149:156823d33999 323 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
<> 149:156823d33999 324 * the configuration information for CRC
<> 149:156823d33999 325 * @retval HAL state
<> 149:156823d33999 326 */
<> 149:156823d33999 327 HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
<> 149:156823d33999 328 {
<> 149:156823d33999 329 return hcrc->State;
<> 149:156823d33999 330 }
<> 149:156823d33999 331
<> 149:156823d33999 332 /**
<> 149:156823d33999 333 * @}
<> 149:156823d33999 334 */
<> 149:156823d33999 335
<> 149:156823d33999 336 /**
<> 149:156823d33999 337 * @}
<> 149:156823d33999 338 */
<> 149:156823d33999 339
<> 149:156823d33999 340 #endif /* HAL_CRC_MODULE_ENABLED */
<> 149:156823d33999 341 /**
<> 149:156823d33999 342 * @}
<> 149:156823d33999 343 */
<> 149:156823d33999 344
<> 149:156823d33999 345 /**
<> 149:156823d33999 346 * @}
<> 149:156823d33999 347 */
<> 149:156823d33999 348
<> 149:156823d33999 349 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/