Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32F1 / Drivers / STM32F1xx_HAL_Driver / Src / stm32f1xx_hal_crc.c
blob70b001c19ffae1fe71d6e27894bb4b6e93e6325c
1 /**
2 ******************************************************************************
3 * @file stm32f1xx_hal_crc.c
4 * @author MCD Application Team
5 * @version V1.1.1
6 * @date 12-May-2017
7 * @brief CRC HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Cyclic Redundancy Check (CRC) peripheral:
10 * + Initialization and de-initialization functions
11 * + Peripheral Control functions
12 * + Peripheral State functions
14 @verbatim
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
18 [..]
19 The CRC HAL driver can be used as follows:
21 (#) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
23 (#) Use HAL_CRC_Accumulate() function to compute the CRC value of
24 a 32-bit data buffer using combination of the previous CRC value
25 and the new one.
27 (#) Use HAL_CRC_Calculate() function to compute the CRC Value of
28 a new 32-bit data buffer. This function resets the CRC computation
29 unit before starting the computation to avoid getting wrong CRC values.
31 @endverbatim
32 ******************************************************************************
33 * @attention
35 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
37 * Redistribution and use in source and binary forms, with or without modification,
38 * are permitted provided that the following conditions are met:
39 * 1. Redistributions of source code must retain the above copyright notice,
40 * this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright notice,
42 * this list of conditions and the following disclaimer in the documentation
43 * and/or other materials provided with the distribution.
44 * 3. Neither the name of STMicroelectronics nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
51 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
54 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
55 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 ******************************************************************************
62 /* Includes ------------------------------------------------------------------*/
63 #include "stm32f1xx_hal.h"
65 /** @addtogroup STM32F1xx_HAL_Driver
66 * @{
69 /** @defgroup CRC CRC
70 * @brief CRC HAL module driver.
71 * @{
74 #ifdef HAL_CRC_MODULE_ENABLED
76 /* Private typedef -----------------------------------------------------------*/
77 /* Private define ------------------------------------------------------------*/
78 /* Private macro -------------------------------------------------------------*/
79 /* Private variables ---------------------------------------------------------*/
80 /* Private function prototypes -----------------------------------------------*/
81 /* Private functions ---------------------------------------------------------*/
83 /** @defgroup CRC_Exported_Functions CRC Exported Functions
84 * @{
87 /** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
88 * @brief Initialization and Configuration functions.
90 @verbatim
91 ==============================================================================
92 ##### Initialization and de-initialization functions #####
93 ==============================================================================
94 [..] This section provides functions allowing to:
95 (+) Initialize the CRC according to the specified parameters
96 in the CRC_InitTypeDef and create the associated handle
97 (+) DeInitialize the CRC peripheral
98 (+) Initialize the CRC MSP
99 (+) DeInitialize CRC MSP
101 @endverbatim
102 * @{
106 * @brief Initializes the CRC according to the specified
107 * parameters in the CRC_InitTypeDef and creates the associated handle.
108 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
109 * the configuration information for CRC
110 * @retval HAL status
112 HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
114 /* Check the CRC handle allocation */
115 if(hcrc == NULL)
117 return HAL_ERROR;
120 /* Check the parameters */
121 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
123 if(hcrc->State == HAL_CRC_STATE_RESET)
125 /* Allocate lock resource and initialize it */
126 hcrc->Lock = HAL_UNLOCKED;
128 /* Init the low level hardware */
129 HAL_CRC_MspInit(hcrc);
132 /* Change CRC peripheral state */
133 hcrc->State = HAL_CRC_STATE_READY;
135 /* Return function status */
136 return HAL_OK;
140 * @brief DeInitializes the CRC peripheral.
141 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
142 * the configuration information for CRC
143 * @retval HAL status
145 HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
147 /* Check the CRC handle allocation */
148 if(hcrc == NULL)
150 return HAL_ERROR;
153 /* Check the parameters */
154 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
156 /* Change CRC peripheral state */
157 hcrc->State = HAL_CRC_STATE_BUSY;
159 /* DeInit the low level hardware */
160 HAL_CRC_MspDeInit(hcrc);
162 /* Resets the CRC calculation unit and sets the data register to 0xFFFF FFFF */
163 __HAL_CRC_DR_RESET(hcrc);
165 /* Reset IDR register content */
166 CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR);
168 /* Change CRC peripheral state */
169 hcrc->State = HAL_CRC_STATE_RESET;
171 /* Release Lock */
172 __HAL_UNLOCK(hcrc);
174 /* Return function status */
175 return HAL_OK;
179 * @brief Initializes the CRC MSP.
180 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
181 * the configuration information for CRC
182 * @retval None
184 __weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
186 /* Prevent unused argument(s) compilation warning */
187 UNUSED(hcrc);
188 /* NOTE : This function Should not be modified, when the callback is needed,
189 the HAL_CRC_MspInit could be implemented in the user file
194 * @brief DeInitializes the CRC MSP.
195 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
196 * the configuration information for CRC
197 * @retval None
199 __weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
201 /* Prevent unused argument(s) compilation warning */
202 UNUSED(hcrc);
203 /* NOTE : This function Should not be modified, when the callback is needed,
204 the HAL_CRC_MspDeInit could be implemented in the user file
209 * @}
212 /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
213 * @brief management functions.
215 @verbatim
216 ==============================================================================
217 ##### Peripheral Control functions #####
218 ==============================================================================
219 [..] This section provides functions allowing to:
220 (+) Compute the 32-bit CRC value of 32-bit data buffer,
221 using combination of the previous CRC value and the new one.
222 (+) Compute the 32-bit CRC value of 32-bit data buffer,
223 independently of the previous CRC value.
225 @endverbatim
226 * @{
230 * @brief Computes the 32-bit CRC of 32-bit data buffer using combination
231 * of the previous CRC value and the new one.
232 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
233 * the configuration information for CRC
234 * @param pBuffer: pointer to the buffer containing the data to be computed
235 * @param BufferLength: length of the buffer to be computed (defined in word, 4 bytes)
236 * @retval 32-bit CRC
238 uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
240 uint32_t index = 0U;
242 /* Process Locked */
243 __HAL_LOCK(hcrc);
245 /* Change CRC peripheral state */
246 hcrc->State = HAL_CRC_STATE_BUSY;
248 /* Enter Data to the CRC calculator */
249 for(index = 0U; index < BufferLength; index++)
251 hcrc->Instance->DR = pBuffer[index];
254 /* Change CRC peripheral state */
255 hcrc->State = HAL_CRC_STATE_READY;
257 /* Process Unlocked */
258 __HAL_UNLOCK(hcrc);
260 /* Return the CRC computed value */
261 return hcrc->Instance->DR;
265 * @brief Computes the 32-bit CRC of 32-bit data buffer independently
266 * of the previous CRC value.
267 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
268 * the configuration information for CRC
269 * @param pBuffer: Pointer to the buffer containing the data to be computed
270 * @param BufferLength: Length of the buffer to be computed (defined in word, 4 bytes)
271 * @retval 32-bit CRC
273 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
275 uint32_t index = 0U;
277 /* Process Locked */
278 __HAL_LOCK(hcrc);
280 /* Change CRC peripheral state */
281 hcrc->State = HAL_CRC_STATE_BUSY;
283 /* Reset CRC Calculation Unit */
284 __HAL_CRC_DR_RESET(hcrc);
286 /* Enter Data to the CRC calculator */
287 for(index = 0U; index < BufferLength; index++)
289 hcrc->Instance->DR = pBuffer[index];
292 /* Change CRC peripheral state */
293 hcrc->State = HAL_CRC_STATE_READY;
295 /* Process Unlocked */
296 __HAL_UNLOCK(hcrc);
298 /* Return the CRC computed value */
299 return hcrc->Instance->DR;
303 * @}
306 /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
307 * @brief Peripheral State functions.
309 @verbatim
310 ==============================================================================
311 ##### Peripheral State functions #####
312 ==============================================================================
313 [..]
314 This subsection permits to get in run-time the status of the peripheral.
316 @endverbatim
317 * @{
321 * @brief Returns the CRC state.
322 * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
323 * the configuration information for CRC
324 * @retval HAL state
326 HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
328 return hcrc->State;
332 * @}
336 * @}
339 #endif /* HAL_CRC_MODULE_ENABLED */
341 * @}
345 * @}
348 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/