1 /**
2   ******************************************************************************
3   * @file    stm32h7xx_hal_cordic.h
4   * @author  MCD Application Team
5   * @brief   This file contains all the functions prototypes for the CORDIC firmware
6   *          library.
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2017 STMicroelectronics.
11   * All rights reserved.
12   *
13   * This software is licensed under terms that can be found in the LICENSE file
14   * in the root directory of this software component.
15   * If no LICENSE file comes with this software, it is provided AS-IS.
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32H7xx_HAL_CORDIC_H
22 #define STM32H7xx_HAL_CORDIC_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx_hal_def.h"
30 
31 #if defined(CORDIC)
32 /** @addtogroup STM32H7xx_HAL_Driver
33   * @{
34   */
35 
36 /** @addtogroup CORDIC
37   * @{
38   */
39 
40 /* Exported types ------------------------------------------------------------*/
41 /** @defgroup CORDIC_Exported_Types CORDIC Exported Types
42   * @{
43   */
44 
45 /**
46   * @brief  CORDIC HAL State Structure definition
47   */
48 typedef enum
49 {
50   HAL_CORDIC_STATE_RESET     = 0x00U,  /*!< CORDIC not yet initialized or disabled */
51   HAL_CORDIC_STATE_READY     = 0x01U,  /*!< CORDIC initialized and ready for use   */
52   HAL_CORDIC_STATE_BUSY      = 0x02U,  /*!< CORDIC internal process is ongoing     */
53   HAL_CORDIC_STATE_ERROR     = 0x03U   /*!< CORDIC error state                     */
54 } HAL_CORDIC_StateTypeDef;
55 
56 /**
57   * @brief  CORDIC Handle Structure definition
58   */
59 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
60 typedef struct __CORDIC_HandleTypeDef
61 #else
62 typedef struct
63 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
64 {
65   CORDIC_TypeDef                *Instance;   /*!< Register base address */
66 
67   const int32_t                 *pInBuff;    /*!< Pointer to CORDIC input data buffer */
68 
69   int32_t                       *pOutBuff;   /*!< Pointer to CORDIC output data buffer */
70 
71   uint32_t                      NbCalcToOrder; /*!< Remaining number of calculation to order */
72 
73   uint32_t                      NbCalcToGet; /*!< Remaining number of calculation result to get */
74 
75   uint32_t                      DMADirection; /*!< Direction of CORDIC DMA transfers */
76 
77   DMA_HandleTypeDef             *hdmaIn;     /*!< CORDIC peripheral input data DMA handle parameters */
78 
79   DMA_HandleTypeDef             *hdmaOut;    /*!< CORDIC peripheral output data DMA handle parameters */
80 
81   HAL_LockTypeDef               Lock;        /*!< CORDIC locking object */
82 
83   __IO HAL_CORDIC_StateTypeDef  State;       /*!< CORDIC state */
84 
85   __IO uint32_t                 ErrorCode;   /*!< CORDIC peripheral error code
86                                                   This parameter can be a value of @ref CORDIC_Error_Code */
87 
88 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
89   void (* ErrorCallback)(struct __CORDIC_HandleTypeDef *hcordic);          /*!< CORDIC error callback */
90   void (* CalculateCpltCallback)(struct __CORDIC_HandleTypeDef *hcordic);  /*!< CORDIC calculate complete callback */
91 
92   void (* MspInitCallback)(struct __CORDIC_HandleTypeDef *hcordic);        /*!< CORDIC Msp Init callback */
93   void (* MspDeInitCallback)(struct __CORDIC_HandleTypeDef *hcordic);      /*!< CORDIC Msp DeInit callback */
94 
95 #endif /* (USE_HAL_CORDIC_REGISTER_CALLBACKS) */
96 
97 } CORDIC_HandleTypeDef;
98 
99 /**
100   * @brief  CORDIC Config Structure definition
101   */
102 typedef struct
103 {
104   uint32_t   Function;     /*!< Function
105                                 This parameter can be a value of @ref CORDIC_Function */
106 
107   uint32_t   Scale;        /*!< Scaling factor
108                                 This parameter can be a value of @ref CORDIC_Scale */
109 
110   uint32_t   InSize;       /*!< Width of input data
111                                 This parameter can be a value of @ref CORDIC_In_Size */
112 
113   uint32_t   OutSize;      /*!< Width of output data
114                                 This parameter can be a value of @ref CORDIC_Out_Size */
115 
116   uint32_t   NbWrite;      /*!< Number of 32-bit write expected for one calculation
117                                 This parameter can be a value of @ref CORDIC_Nb_Write */
118 
119   uint32_t   NbRead;       /*!< Number of 32-bit read expected after one calculation
120                                 This parameter can be a value of @ref CORDIC_Nb_Read */
121 
122   uint32_t   Precision;    /*!< Number of cycles for calculation
123                                 This parameter can be a value of @ref CORDIC_Precision_In_Cycles_Number */
124 
125 } CORDIC_ConfigTypeDef;
126 
127 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
128 /**
129   * @brief  HAL CORDIC Callback ID enumeration definition
130   */
131 typedef enum
132 {
133   HAL_CORDIC_ERROR_CB_ID             = 0x00U,    /*!< CORDIC error callback ID */
134   HAL_CORDIC_CALCULATE_CPLT_CB_ID    = 0x01U,    /*!< CORDIC calculate complete callback ID */
135 
136   HAL_CORDIC_MSPINIT_CB_ID           = 0x02U,    /*!< CORDIC MspInit callback ID */
137   HAL_CORDIC_MSPDEINIT_CB_ID         = 0x03U,    /*!< CORDIC MspDeInit callback ID */
138 
139 } HAL_CORDIC_CallbackIDTypeDef;
140 
141 /**
142   * @brief  HAL CORDIC Callback pointer definition
143   */
144 typedef  void (*pCORDIC_CallbackTypeDef)(CORDIC_HandleTypeDef *hcordic);  /*!< pointer to a CORDIC callback function */
145 
146 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
147 
148 /**
149   * @}
150   */
151 
152 
153 /* Exported constants --------------------------------------------------------*/
154 /** @defgroup CORDIC_Exported_Constants CORDIC Exported Constants
155   * @{
156   */
157 
158 /** @defgroup CORDIC_Error_Code CORDIC Error code
159   * @{
160   */
161 #define HAL_CORDIC_ERROR_NONE              ((uint32_t)0x00000000U)   /*!< No error                */
162 #define HAL_CORDIC_ERROR_PARAM             ((uint32_t)0x00000001U)   /*!< Wrong parameter error   */
163 #define HAL_CORDIC_ERROR_NOT_READY         ((uint32_t)0x00000002U)   /*!< Peripheral not ready    */
164 #define HAL_CORDIC_ERROR_TIMEOUT           ((uint32_t)0x00000004U)   /*!< Timeout error           */
165 #define HAL_CORDIC_ERROR_DMA               ((uint32_t)0x00000008U)   /*!< DMA error               */
166 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
167 #define HAL_CORDIC_ERROR_INVALID_CALLBACK  ((uint32_t)0x00000010U)   /*!< Invalid Callback error  */
168 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
169 /**
170   * @}
171   */
172 
173 /** @defgroup CORDIC_Function CORDIC Function
174   * @{
175   */
176 #define CORDIC_FUNCTION_COSINE      (0x00000000U)                                                          /*!< Cosine */
177 #define CORDIC_FUNCTION_SINE        ((uint32_t)(CORDIC_CSR_FUNC_0))                                        /*!< Sine */
178 #define CORDIC_FUNCTION_PHASE       ((uint32_t)(CORDIC_CSR_FUNC_1))                                        /*!< Phase */
179 #define CORDIC_FUNCTION_MODULUS     ((uint32_t)(CORDIC_CSR_FUNC_1 | CORDIC_CSR_FUNC_0))                    /*!< Modulus */
180 #define CORDIC_FUNCTION_ARCTANGENT  ((uint32_t)(CORDIC_CSR_FUNC_2))                                        /*!< Arctangent */
181 #define CORDIC_FUNCTION_HCOSINE     ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_0))                    /*!< Hyperbolic Cosine */
182 #define CORDIC_FUNCTION_HSINE       ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_1))                    /*!< Hyperbolic Sine */
183 #define CORDIC_FUNCTION_HARCTANGENT ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_1 | CORDIC_CSR_FUNC_0))/*!< Hyperbolic Arctangent */
184 #define CORDIC_FUNCTION_NATURALLOG  ((uint32_t)(CORDIC_CSR_FUNC_3))                                        /*!< Natural Logarithm */
185 #define CORDIC_FUNCTION_SQUAREROOT  ((uint32_t)(CORDIC_CSR_FUNC_3 | CORDIC_CSR_FUNC_0))                    /*!< Square Root */
186 /**
187   * @}
188   */
189 
190 /** @defgroup CORDIC_Precision_In_Cycles_Number CORDIC Precision in Cycles Number
191   * @{
192   */
193 /* Note: 1 cycle corresponds to 4 algorithm iterations */
194 #define CORDIC_PRECISION_1CYCLE     ((uint32_t)(CORDIC_CSR_PRECISION_0))
195 #define CORDIC_PRECISION_2CYCLES    ((uint32_t)(CORDIC_CSR_PRECISION_1))
196 #define CORDIC_PRECISION_3CYCLES    ((uint32_t)(CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
197 #define CORDIC_PRECISION_4CYCLES    ((uint32_t)(CORDIC_CSR_PRECISION_2))
198 #define CORDIC_PRECISION_5CYCLES    ((uint32_t)(CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_0))
199 #define CORDIC_PRECISION_6CYCLES    ((uint32_t)(CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1))
200 #define CORDIC_PRECISION_7CYCLES    ((uint32_t)(CORDIC_CSR_PRECISION_2\
201                                                 | CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
202 #define CORDIC_PRECISION_8CYCLES    ((uint32_t)(CORDIC_CSR_PRECISION_3))
203 #define CORDIC_PRECISION_9CYCLES    ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_0))
204 #define CORDIC_PRECISION_10CYCLES   ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_1))
205 #define CORDIC_PRECISION_11CYCLES   ((uint32_t)(CORDIC_CSR_PRECISION_3\
206                                                 | CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
207 #define CORDIC_PRECISION_12CYCLES   ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_2))
208 #define CORDIC_PRECISION_13CYCLES   ((uint32_t)(CORDIC_CSR_PRECISION_3\
209                                                 | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_0))
210 #define CORDIC_PRECISION_14CYCLES   ((uint32_t)(CORDIC_CSR_PRECISION_3\
211                                                 | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1))
212 #define CORDIC_PRECISION_15CYCLES   ((uint32_t)(CORDIC_CSR_PRECISION_3\
213                                                 | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1\
214                                                 |CORDIC_CSR_PRECISION_0))
215 /**
216   * @}
217   */
218 
219 /** @defgroup CORDIC_Scale CORDIC Scaling factor
220   * @{
221   */
222 /* Scale factor value 'n' implies that the input data have been multiplied
223    by a factor 2exp(-n), and/or the output data need to be multiplied by 2exp(n). */
224 #define CORDIC_SCALE_0              (0x00000000U)
225 #define CORDIC_SCALE_1              ((uint32_t)(CORDIC_CSR_SCALE_0))
226 #define CORDIC_SCALE_2              ((uint32_t)(CORDIC_CSR_SCALE_1))
227 #define CORDIC_SCALE_3              ((uint32_t)(CORDIC_CSR_SCALE_1 | CORDIC_CSR_SCALE_0))
228 #define CORDIC_SCALE_4              ((uint32_t)(CORDIC_CSR_SCALE_2))
229 #define CORDIC_SCALE_5              ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_0))
230 #define CORDIC_SCALE_6              ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_1))
231 #define CORDIC_SCALE_7              ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_1 | CORDIC_CSR_SCALE_0))
232 /**
233   * @}
234   */
235 
236 /** @defgroup CORDIC_Interrupts_Enable CORDIC Interrupts Enable bit
237   * @{
238   */
239 #define CORDIC_IT_IEN              CORDIC_CSR_IEN            /*!< Result ready interrupt enable */
240 /**
241   * @}
242   */
243 
244 /** @defgroup CORDIC_DMAR DMA Read Request Enable bit
245   * @{
246   */
247 #define CORDIC_DMA_REN             CORDIC_CSR_DMAREN         /*!< DMA Read requests enable */
248 /**
249   * @}
250   */
251 
252 /** @defgroup CORDIC_DMAW DMA Write Request Enable bit
253   * @{
254   */
255 #define CORDIC_DMA_WEN             CORDIC_CSR_DMAWEN         /*!< DMA Write channel enable */
256 /**
257   * @}
258   */
259 
260 /** @defgroup CORDIC_Nb_Write CORDIC Number of 32-bit write required for one calculation
261   * @{
262   */
263 #define CORDIC_NBWRITE_1           (0x00000000U)             /*!< One 32-bits write containing either only one
264                                                                   32-bit data input (Q1.31 format), or two 16-bit
265                                                                   data input (Q1.15 format) packed in one 32 bits
266                                                                   Data */
267 #define CORDIC_NBWRITE_2           CORDIC_CSR_NARGS          /*!< Two 32-bit write containing two 32-bits data input
268                                                                   (Q1.31 format) */
269 /**
270   * @}
271   */
272 
273 /** @defgroup CORDIC_Nb_Read CORDIC Number of 32-bit read required after one calculation
274   * @{
275   */
276 #define CORDIC_NBREAD_1            (0x00000000U)             /*!< One 32-bits read containing either only one
277                                                                   32-bit data output (Q1.31 format), or two 16-bit
278                                                                   data output (Q1.15 format) packed in one 32 bits
279                                                                   Data */
280 #define CORDIC_NBREAD_2            CORDIC_CSR_NRES           /*!< Two 32-bit Data containing two 32-bits data output
281                                                                   (Q1.31 format) */
282 /**
283   * @}
284   */
285 
286 /** @defgroup CORDIC_In_Size CORDIC input data size
287   * @{
288   */
289 #define CORDIC_INSIZE_32BITS       (0x00000000U)             /*!< 32 bits input data size (Q1.31 format) */
290 #define CORDIC_INSIZE_16BITS       CORDIC_CSR_ARGSIZE        /*!< 16 bits input data size (Q1.15 format) */
291 /**
292   * @}
293   */
294 
295 /** @defgroup CORDIC_Out_Size CORDIC Results Size
296   * @{
297   */
298 #define CORDIC_OUTSIZE_32BITS      (0x00000000U)             /*!< 32 bits output data size (Q1.31 format) */
299 #define CORDIC_OUTSIZE_16BITS      CORDIC_CSR_RESSIZE        /*!< 16 bits output data size (Q1.15 format) */
300 /**
301   * @}
302   */
303 
304 /** @defgroup CORDIC_Flags  CORDIC status flags
305   * @{
306   */
307 #define CORDIC_FLAG_RRDY           CORDIC_CSR_RRDY           /*!< Result Ready Flag */
308 /**
309   * @}
310   */
311 
312 /** @defgroup CORDIC_DMA_Direction CORDIC DMA direction
313   * @{
314   */
315 #define CORDIC_DMA_DIR_NONE        ((uint32_t)0x00000000U)   /*!< DMA direction : none */
316 #define CORDIC_DMA_DIR_IN          ((uint32_t)0x00000001U)   /*!< DMA direction : Input of CORDIC */
317 #define CORDIC_DMA_DIR_OUT         ((uint32_t)0x00000002U)   /*!< DMA direction : Output of CORDIC */
318 #define CORDIC_DMA_DIR_IN_OUT      ((uint32_t)0x00000003U)   /*!< DMA direction : Input and Output of CORDIC */
319 /**
320   * @}
321   */
322 
323 /**
324   * @}
325   */
326 
327 
328 /* Exported macro ------------------------------------------------------------*/
329 /** @defgroup CORDIC_Exported_Macros CORDIC Exported Macros
330   * @{
331   */
332 
333 /** @brief  Reset CORDIC handle state.
334   * @param  __HANDLE__ CORDIC handle
335   * @retval None
336   */
337 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
338 #define __HAL_CORDIC_RESET_HANDLE_STATE(__HANDLE__) do{                                                \
339                                                         (__HANDLE__)->State = HAL_CORDIC_STATE_RESET;   \
340                                                         (__HANDLE__)->MspInitCallback = NULL;           \
341                                                         (__HANDLE__)->MspDeInitCallback = NULL;         \
342                                                       } while(0)
343 #else
344 #define __HAL_CORDIC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CORDIC_STATE_RESET)
345 #endif /*USE_HAL_CORDIC_REGISTER_CALLBACKS */
346 
347 /**
348   * @brief  Enable the CORDIC interrupt when result is ready
349   * @param  __HANDLE__ CORDIC handle.
350   * @param  __INTERRUPT__ CORDIC Interrupt.
351   *         This parameter can be one of the following values:
352   *            @arg @ref CORDIC_IT_IEN Enable Interrupt
353   * @retval None
354   */
355 #define __HAL_CORDIC_ENABLE_IT(__HANDLE__, __INTERRUPT__)                     \
356   (((__HANDLE__)->Instance->CSR) |= (__INTERRUPT__))
357 
358 /**
359   * @brief  Disable the CORDIC interrupt
360   * @param  __HANDLE__ CORDIC handle.
361   * @param  __INTERRUPT__ CORDIC Interrupt.
362   *         This parameter can be one of the following values:
363   *            @arg @ref CORDIC_IT_IEN Enable Interrupt
364   * @retval None
365   */
366 #define __HAL_CORDIC_DISABLE_IT(__HANDLE__, __INTERRUPT__)                    \
367   (((__HANDLE__)->Instance->CSR) &= ~(__INTERRUPT__))
368 
369 /** @brief  Check whether the specified CORDIC interrupt occurred or not.
370             Dummy macro as no interrupt status flag.
371   * @param  __HANDLE__ CORDIC handle.
372   * @param  __INTERRUPT__ CORDIC interrupt to check
373   * @retval SET (interrupt occurred) or RESET (interrupt did not occurred)
374   */
375 #define __HAL_CORDIC_GET_IT(__HANDLE__, __INTERRUPT__)     /* Dummy macro */
376 
377 /** @brief  Clear specified CORDIC interrupt status. Dummy macro as no
378             interrupt status flag.
379   * @param  __HANDLE__ CORDIC handle.
380   * @param  __INTERRUPT__ CORDIC interrupt to clear
381   * @retval None
382   */
383 #define __HAL_CORDIC_CLEAR_IT(__HANDLE__, __INTERRUPT__)   /* Dummy macro */
384 
385 /** @brief  Check whether the specified CORDIC status flag is set or not.
386   * @param  __HANDLE__ CORDIC handle.
387   * @param  __FLAG__ CORDIC flag to check
388   *         This parameter can be one of the following values:
389   *            @arg @ref CORDIC_FLAG_RRDY Result Ready Flag
390   * @retval SET (flag is set) or RESET (flag is reset)
391   */
392 #define __HAL_CORDIC_GET_FLAG(__HANDLE__, __FLAG__)                           \
393   ((((__HANDLE__)->Instance->CSR) & (__FLAG__)) == (__FLAG__))
394 
395 /** @brief  Clear specified CORDIC status flag. Dummy macro as no
396             flag can be cleared.
397   * @param  __HANDLE__ CORDIC handle.
398   * @param  __FLAG__ CORDIC flag to clear
399   *         This parameter can be one of the following values:
400   *            @arg @ref CORDIC_FLAG_RRDY Result Ready Flag
401   * @retval None
402   */
403 #define __HAL_CORDIC_CLEAR_FLAG(__HANDLE__, __FLAG__)     /* Dummy macro */
404 
405 /** @brief  Check whether the specified CORDIC interrupt is enabled or not.
406   * @param  __HANDLE__ CORDIC handle.
407   * @param  __INTERRUPT__ CORDIC interrupt to check
408   *         This parameter can be one of the following values:
409   *            @arg @ref CORDIC_IT_IEN Enable Interrupt
410   * @retval FlagStatus
411   */
412 #define __HAL_CORDIC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)                 \
413   (((__HANDLE__)->Instance->CSR) & (__INTERRUPT__))
414 
415 /**
416   * @}
417   */
418 
419 /* Private macros --------------------------------------------------------*/
420 /** @defgroup  CORDIC_Private_Macros   CORDIC Private Macros
421   * @{
422   */
423 
424 /**
425   * @brief  Verify the CORDIC function.
426   * @param  __FUNCTION__ Name of the function.
427   * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
428   */
429 #define IS_CORDIC_FUNCTION(__FUNCTION__) (((__FUNCTION__) == CORDIC_FUNCTION_COSINE)       || \
430                                           ((__FUNCTION__) == CORDIC_FUNCTION_SINE)         || \
431                                           ((__FUNCTION__) == CORDIC_FUNCTION_PHASE)        || \
432                                           ((__FUNCTION__) == CORDIC_FUNCTION_MODULUS)      || \
433                                           ((__FUNCTION__) == CORDIC_FUNCTION_ARCTANGENT)   || \
434                                           ((__FUNCTION__) == CORDIC_FUNCTION_HCOSINE)      || \
435                                           ((__FUNCTION__) == CORDIC_FUNCTION_HSINE)        || \
436                                           ((__FUNCTION__) == CORDIC_FUNCTION_HARCTANGENT)  || \
437                                           ((__FUNCTION__) == CORDIC_FUNCTION_NATURALLOG)   || \
438                                           ((__FUNCTION__) == CORDIC_FUNCTION_SQUAREROOT))
439 
440 
441 /**
442   * @brief  Verify the CORDIC precision.
443   * @param  __PRECISION__ CORDIC Precision in Cycles Number.
444   * @retval SET (__PRECISION__ is a valid value) or RESET (__PRECISION__ is invalid)
445   */
446 #define IS_CORDIC_PRECISION(__PRECISION__) (((__PRECISION__) == CORDIC_PRECISION_1CYCLE)   || \
447                                             ((__PRECISION__) == CORDIC_PRECISION_2CYCLES)  || \
448                                             ((__PRECISION__) == CORDIC_PRECISION_3CYCLES)  || \
449                                             ((__PRECISION__) == CORDIC_PRECISION_4CYCLES)  || \
450                                             ((__PRECISION__) == CORDIC_PRECISION_5CYCLES)  || \
451                                             ((__PRECISION__) == CORDIC_PRECISION_6CYCLES)  || \
452                                             ((__PRECISION__) == CORDIC_PRECISION_7CYCLES)  || \
453                                             ((__PRECISION__) == CORDIC_PRECISION_8CYCLES)  || \
454                                             ((__PRECISION__) == CORDIC_PRECISION_9CYCLES)  || \
455                                             ((__PRECISION__) == CORDIC_PRECISION_10CYCLES) || \
456                                             ((__PRECISION__) == CORDIC_PRECISION_11CYCLES) || \
457                                             ((__PRECISION__) == CORDIC_PRECISION_12CYCLES) || \
458                                             ((__PRECISION__) == CORDIC_PRECISION_13CYCLES) || \
459                                             ((__PRECISION__) == CORDIC_PRECISION_14CYCLES) || \
460                                             ((__PRECISION__) == CORDIC_PRECISION_15CYCLES))
461 
462 /**
463   * @brief  Verify the CORDIC scaling factor.
464   * @param  __SCALE__ Number of cycles for calculation, 1 cycle corresponding to 4 algorithm iterations.
465   * @retval SET (__SCALE__ is a valid value) or RESET (__SCALE__ is invalid)
466   */
467 #define IS_CORDIC_SCALE(__SCALE__) (((__SCALE__) == CORDIC_SCALE_0)  || \
468                                     ((__SCALE__) == CORDIC_SCALE_1)  || \
469                                     ((__SCALE__) == CORDIC_SCALE_2)  || \
470                                     ((__SCALE__) == CORDIC_SCALE_3)  || \
471                                     ((__SCALE__) == CORDIC_SCALE_4)  || \
472                                     ((__SCALE__) == CORDIC_SCALE_5)  || \
473                                     ((__SCALE__) == CORDIC_SCALE_6)  || \
474                                     ((__SCALE__) == CORDIC_SCALE_7))
475 
476 /**
477   * @brief  Verify the CORDIC number of 32-bits write expected for one calculation.
478   * @param  __NBWRITE__ Number of 32-bits write expected for one calculation.
479   * @retval SET (__NBWRITE__ is a valid value) or RESET (__NBWRITE__ is invalid)
480   */
481 #define IS_CORDIC_NBWRITE(__NBWRITE__) (((__NBWRITE__) == CORDIC_NBWRITE_1)  || \
482                                         ((__NBWRITE__) == CORDIC_NBWRITE_2))
483 
484 /**
485   * @brief  Verify the CORDIC number of 32-bits read expected after one calculation.
486   * @param  __NBREAD__ Number of 32-bits read expected after one calculation.
487   * @retval SET (__NBREAD__ is a valid value) or RESET (__NBREAD__ is invalid)
488   */
489 #define IS_CORDIC_NBREAD(__NBREAD__) (((__NBREAD__) == CORDIC_NBREAD_1)  || \
490                                       ((__NBREAD__) == CORDIC_NBREAD_2))
491 
492 /**
493   * @brief  Verify the CORDIC input data size for one calculation.
494   * @param  __INSIZE__ input data size for one calculation.
495   * @retval SET (__INSIZE__ is a valid value) or RESET (__INSIZE__ is invalid)
496   */
497 #define IS_CORDIC_INSIZE(__INSIZE__) (((__INSIZE__) == CORDIC_INSIZE_32BITS)  || \
498                                       ((__INSIZE__) == CORDIC_INSIZE_16BITS))
499 
500 /**
501   * @brief  Verify the CORDIC output data size for one calculation.
502   * @param  __OUTSIZE__ output data size for one calculation.
503   * @retval SET (__OUTSIZE__ is a valid value) or RESET (__OUTSIZE__ is invalid)
504   */
505 #define IS_CORDIC_OUTSIZE(__OUTSIZE__) (((__OUTSIZE__) == CORDIC_OUTSIZE_32BITS)  || \
506                                         ((__OUTSIZE__) == CORDIC_OUTSIZE_16BITS))
507 
508 /**
509   * @brief  Verify the CORDIC DMA transfer Direction.
510   * @param  __DMADIR__ DMA transfer direction.
511   * @retval SET (__DMADIR__ is a valid value) or RESET (__DMADIR__ is invalid)
512   */
513 #define IS_CORDIC_DMA_DIRECTION(__DMADIR__) (((__DMADIR__) == CORDIC_DMA_DIR_IN)  || \
514                                              ((__DMADIR__) == CORDIC_DMA_DIR_OUT) || \
515                                              ((__DMADIR__) == CORDIC_DMA_DIR_IN_OUT))
516 
517 /**
518   * @}
519   */
520 
521 /** @addtogroup CORDIC_Exported_Functions
522   * @{
523   */
524 /* Exported functions ------------------------------------------------------- */
525 
526 /** @addtogroup CORDIC_Exported_Functions_Group1
527   * @{
528   */
529 /* Initialization and de-initialization functions ******************************/
530 HAL_StatusTypeDef HAL_CORDIC_Init(CORDIC_HandleTypeDef *hcordic);
531 HAL_StatusTypeDef HAL_CORDIC_DeInit(CORDIC_HandleTypeDef *hcordic);
532 void HAL_CORDIC_MspInit(CORDIC_HandleTypeDef *hcordic);
533 void HAL_CORDIC_MspDeInit(CORDIC_HandleTypeDef *hcordic);
534 
535 #if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
536 /* Callbacks Register/UnRegister functions  ***********************************/
537 HAL_StatusTypeDef HAL_CORDIC_RegisterCallback(CORDIC_HandleTypeDef *hcordic, HAL_CORDIC_CallbackIDTypeDef CallbackID,
538                                               pCORDIC_CallbackTypeDef pCallback);
539 HAL_StatusTypeDef HAL_CORDIC_UnRegisterCallback(CORDIC_HandleTypeDef *hcordic, HAL_CORDIC_CallbackIDTypeDef CallbackID);
540 /**
541   * @}
542   */
543 
544 /** @addtogroup CORDIC_Exported_Functions_Group2
545   * @{
546   */
547 #endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
548 /* Peripheral Control functions ***********************************************/
549 HAL_StatusTypeDef HAL_CORDIC_Configure(CORDIC_HandleTypeDef *hcordic, const CORDIC_ConfigTypeDef *sConfig);
550 HAL_StatusTypeDef HAL_CORDIC_Calculate(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
551                                        uint32_t NbCalc, uint32_t Timeout);
552 HAL_StatusTypeDef HAL_CORDIC_CalculateZO(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
553                                          uint32_t NbCalc, uint32_t Timeout);
554 HAL_StatusTypeDef HAL_CORDIC_Calculate_IT(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
555                                           uint32_t NbCalc);
556 HAL_StatusTypeDef HAL_CORDIC_Calculate_DMA(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
557                                            uint32_t NbCalc, uint32_t DMADirection);
558 /**
559   * @}
560   */
561 
562 /** @addtogroup CORDIC_Exported_Functions_Group3
563   * @{
564   */
565 /* Callback functions *********************************************************/
566 void HAL_CORDIC_ErrorCallback(CORDIC_HandleTypeDef *hcordic);
567 void HAL_CORDIC_CalculateCpltCallback(CORDIC_HandleTypeDef *hcordic);
568 /**
569   * @}
570   */
571 
572 /** @addtogroup CORDIC_Exported_Functions_Group4
573   * @{
574   */
575 /* IRQ handler management *****************************************************/
576 void HAL_CORDIC_IRQHandler(CORDIC_HandleTypeDef *hcordic);
577 /**
578   * @}
579   */
580 
581 /** @addtogroup CORDIC_Exported_Functions_Group5
582   * @{
583   */
584 /* Peripheral State functions *************************************************/
585 HAL_CORDIC_StateTypeDef HAL_CORDIC_GetState(const CORDIC_HandleTypeDef *hcordic);
586 uint32_t HAL_CORDIC_GetError(const CORDIC_HandleTypeDef *hcordic);
587 /**
588   * @}
589   */
590 
591 /**
592   * @}
593   */
594 
595 /**
596   * @}
597   */
598 
599 /**
600   * @}
601   */
602 
603 #endif /* CORDIC */
604 
605 #ifdef __cplusplus
606 }
607 #endif
608 
609 #endif /* STM32H7xx_HAL_CORDIC_H */
610