comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_crc.c @ 128:c78bcbd5deda FlipDisplay

Added current STM32 standandard libraries in version independend folder structure
author Ideenmodellierer
date Sun, 17 Feb 2019 21:12:22 +0100
parents
children
comparison
equal deleted inserted replaced
127:1369f8660eaa 128:c78bcbd5deda
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_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>&copy; COPYRIGHT(c) 2017 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 "stm32f4xx_hal.h"
62
63 /** @addtogroup STM32F4xx_HAL_Driver
64 * @{
65 */
66
67 /** @addtogroup CRC
68 * @{
69 */
70
71 #ifdef HAL_CRC_MODULE_ENABLED
72
73 /* Private typedef -----------------------------------------------------------*/
74 /* Private define ------------------------------------------------------------*/
75 /* Private macro -------------------------------------------------------------*/
76 /* Private variables ---------------------------------------------------------*/
77 /* Private function prototypes -----------------------------------------------*/
78 /* Private functions ---------------------------------------------------------*/
79 /* Exported functions --------------------------------------------------------*/
80
81 /** @addtogroup CRC_Exported_Functions
82 * @{
83 */
84
85 /** @addtogroup CRC_Exported_Functions_Group1
86 * @brief Initialization and de-initialization 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 /* Init the low level hardware */
126 HAL_CRC_MspInit(hcrc);
127 }
128
129 /* Change CRC peripheral state */
130 hcrc->State = HAL_CRC_STATE_BUSY;
131
132 /* Change CRC peripheral state */
133 hcrc->State = HAL_CRC_STATE_READY;
134
135 /* Return function status */
136 return HAL_OK;
137 }
138
139 /**
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
144 */
145 HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
146 {
147 /* Check the CRC handle allocation */
148 if(hcrc == NULL)
149 {
150 return HAL_ERROR;
151 }
152
153 /* Check the parameters */
154 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
155
156 /* Change CRC peripheral state */
157 hcrc->State = HAL_CRC_STATE_BUSY;
158
159 /* DeInit the low level hardware */
160 HAL_CRC_MspDeInit(hcrc);
161
162 /* Change CRC peripheral state */
163 hcrc->State = HAL_CRC_STATE_RESET;
164
165 /* Release Lock */
166 __HAL_UNLOCK(hcrc);
167
168 /* Return function status */
169 return HAL_OK;
170 }
171
172 /**
173 * @brief Initializes the CRC MSP.
174 * @param hcrc pointer to a CRC_HandleTypeDef structure that contains
175 * the configuration information for CRC
176 * @retval None
177 */
178 __weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
179 {
180 /* Prevent unused argument(s) compilation warning */
181 UNUSED(hcrc);
182 /* NOTE : This function Should not be modified, when the callback is needed,
183 the HAL_CRC_MspInit could be implemented in the user file
184 */
185 }
186
187 /**
188 * @brief DeInitializes the CRC MSP.
189 * @param hcrc pointer to a CRC_HandleTypeDef structure that contains
190 * the configuration information for CRC
191 * @retval None
192 */
193 __weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
194 {
195 /* Prevent unused argument(s) compilation warning */
196 UNUSED(hcrc);
197 /* NOTE : This function Should not be modified, when the callback is needed,
198 the HAL_CRC_MspDeInit could be implemented in the user file
199 */
200 }
201
202 /**
203 * @}
204 */
205
206 /** @addtogroup CRC_Exported_Functions_Group2
207 * @brief Peripheral Control functions
208 *
209 @verbatim
210 ==============================================================================
211 ##### Peripheral Control functions #####
212 ==============================================================================
213 [..] This section provides functions allowing to:
214 (+) Compute the 32-bit CRC value of 32-bit data buffer,
215 using combination of the previous CRC value and the new one.
216 (+) Compute the 32-bit CRC value of 32-bit data buffer,
217 independently of the previous CRC value.
218
219 @endverbatim
220 * @{
221 */
222
223 /**
224 * @brief Computes the 32-bit CRC of 32-bit data buffer using combination
225 * of the previous CRC value and the new one.
226 * @param hcrc pointer to a CRC_HandleTypeDef structure that contains
227 * the configuration information for CRC
228 * @param pBuffer pointer to the buffer containing the data to be computed
229 * @param BufferLength length of the buffer to be computed
230 * @retval 32-bit CRC
231 */
232 uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
233 {
234 uint32_t index = 0U;
235
236 /* Process Locked */
237 __HAL_LOCK(hcrc);
238
239 /* Change CRC peripheral state */
240 hcrc->State = HAL_CRC_STATE_BUSY;
241
242 /* Enter Data to the CRC calculator */
243 for(index = 0U; index < BufferLength; index++)
244 {
245 hcrc->Instance->DR = pBuffer[index];
246 }
247
248 /* Change CRC peripheral state */
249 hcrc->State = HAL_CRC_STATE_READY;
250
251 /* Process Unlocked */
252 __HAL_UNLOCK(hcrc);
253
254 /* Return the CRC computed value */
255 return hcrc->Instance->DR;
256 }
257
258 /**
259 * @brief Computes the 32-bit CRC of 32-bit data buffer independently
260 * of the previous CRC value.
261 * @param hcrc pointer to a CRC_HandleTypeDef structure that contains
262 * the configuration information for CRC
263 * @param pBuffer Pointer to the buffer containing the data to be computed
264 * @param BufferLength Length of the buffer to be computed
265 * @retval 32-bit CRC
266 */
267 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
268 {
269 uint32_t index = 0U;
270
271 /* Process Locked */
272 __HAL_LOCK(hcrc);
273
274 /* Change CRC peripheral state */
275 hcrc->State = HAL_CRC_STATE_BUSY;
276
277 /* Reset CRC Calculation Unit */
278 __HAL_CRC_DR_RESET(hcrc);
279
280 /* Enter Data to the CRC calculator */
281 for(index = 0U; index < BufferLength; index++)
282 {
283 hcrc->Instance->DR = pBuffer[index];
284 }
285
286 /* Change CRC peripheral state */
287 hcrc->State = HAL_CRC_STATE_READY;
288
289 /* Process Unlocked */
290 __HAL_UNLOCK(hcrc);
291
292 /* Return the CRC computed value */
293 return hcrc->Instance->DR;
294 }
295
296 /**
297 * @}
298 */
299
300
301 /** @addtogroup CRC_Exported_Functions_Group3
302 * @brief Peripheral State functions
303 *
304 @verbatim
305 ==============================================================================
306 ##### Peripheral State functions #####
307 ==============================================================================
308 [..]
309 This subsection permits to get in run-time the status of the peripheral
310 and the data flow.
311
312 @endverbatim
313 * @{
314 */
315
316 /**
317 * @brief Returns the CRC state.
318 * @param hcrc pointer to a CRC_HandleTypeDef structure that contains
319 * the configuration information for CRC
320 * @retval HAL state
321 */
322 HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
323 {
324 return hcrc->State;
325 }
326
327 /**
328 * @}
329 */
330
331 /**
332 * @}
333 */
334
335 #endif /* HAL_CRC_MODULE_ENABLED */
336 /**
337 * @}
338 */
339
340 /**
341 * @}
342 */
343
344 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/