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