SilentSensors / mbed-dev

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 02 15:07:44 2016 +0100
Revision:
144:ef7eb2e8f9f7
Parent:
83:a036322b8637
This updates the lib to the mbed lib v125

Who changed what in which revision?

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