1 /**
2 ******************************************************************************
3 * @file stm32h5xx_ll_cordic.h
4 * @author MCD Application Team
5 * @brief Header file of CORDIC LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2022 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32H5xx_LL_CORDIC_H
21 #define STM32H5xx_LL_CORDIC_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h5xx.h"
29
30 /** @addtogroup STM32H5xx_LL_Driver
31 * @{
32 */
33
34 #if defined(CORDIC)
35
36 /** @defgroup CORDIC_LL CORDIC
37 * @{
38 */
39
40 /* Private variables ---------------------------------------------------------*/
41
42 /* Private constants ---------------------------------------------------------*/
43
44 /* Private macros ------------------------------------------------------------*/
45
46 /* Exported types ------------------------------------------------------------*/
47
48 /* Exported constants --------------------------------------------------------*/
49 /** @defgroup CORDIC_LL_Exported_Constants CORDIC Exported Constants
50 * @{
51 */
52
53 /** @defgroup CORDIC_LL_EC_GET_FLAG Get Flags Defines
54 * @brief Flags defines which can be used with LL_CORDIC_ReadReg function.
55 * @{
56 */
57 #define LL_CORDIC_FLAG_RRDY CORDIC_CSR_RRDY
58 /**
59 * @}
60 */
61
62 /** @defgroup CORDIC_LL_EC_IT IT Defines
63 * @brief IT defines which can be used with LL_CORDIC_ReadReg and LL_CORDIC_WriteReg functions.
64 * @{
65 */
66 #define LL_CORDIC_IT_IEN CORDIC_CSR_IEN /*!< Result Ready interrupt enable */
67 /**
68 * @}
69 */
70
71 /** @defgroup CORDIC_LL_EC_FUNCTION FUNCTION
72 * @{
73 */
74 #define LL_CORDIC_FUNCTION_COSINE (0x00000000U) /*!< Cosine */
75 #define LL_CORDIC_FUNCTION_SINE ((uint32_t)(CORDIC_CSR_FUNC_0)) /*!< Sine */
76 #define LL_CORDIC_FUNCTION_PHASE ((uint32_t)(CORDIC_CSR_FUNC_1)) /*!< Phase */
77 #define LL_CORDIC_FUNCTION_MODULUS ((uint32_t)(CORDIC_CSR_FUNC_1 | CORDIC_CSR_FUNC_0)) /*!< Modulus */
78 #define LL_CORDIC_FUNCTION_ARCTANGENT ((uint32_t)(CORDIC_CSR_FUNC_2)) /*!< Arctangent */
79 #define LL_CORDIC_FUNCTION_HCOSINE ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_0)) /*!< Hyperbolic Cosine */
80 #define LL_CORDIC_FUNCTION_HSINE ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_1)) /*!< Hyperbolic Sine */
81 #define LL_CORDIC_FUNCTION_HARCTANGENT ((uint32_t)(CORDIC_CSR_FUNC_2 | CORDIC_CSR_FUNC_1 | CORDIC_CSR_FUNC_0))/*!< Hyperbolic Arctangent */
82 #define LL_CORDIC_FUNCTION_NATURALLOG ((uint32_t)(CORDIC_CSR_FUNC_3)) /*!< Natural Logarithm */
83 #define LL_CORDIC_FUNCTION_SQUAREROOT ((uint32_t)(CORDIC_CSR_FUNC_3 | CORDIC_CSR_FUNC_0)) /*!< Square Root */
84 /**
85 * @}
86 */
87
88 /** @defgroup CORDIC_LL_EC_PRECISION PRECISION
89 * @{
90 */
91 #define LL_CORDIC_PRECISION_1CYCLE ((uint32_t)(CORDIC_CSR_PRECISION_0))
92 #define LL_CORDIC_PRECISION_2CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_1))
93 #define LL_CORDIC_PRECISION_3CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
94 #define LL_CORDIC_PRECISION_4CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_2))
95 #define LL_CORDIC_PRECISION_5CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_0))
96 #define LL_CORDIC_PRECISION_6CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1))
97 #define LL_CORDIC_PRECISION_7CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_2\
98 | CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
99 #define LL_CORDIC_PRECISION_8CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_3))
100 #define LL_CORDIC_PRECISION_9CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_0))
101 #define LL_CORDIC_PRECISION_10CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_1))
102 #define LL_CORDIC_PRECISION_11CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_3\
103 | CORDIC_CSR_PRECISION_1 | CORDIC_CSR_PRECISION_0))
104 #define LL_CORDIC_PRECISION_12CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_3 | CORDIC_CSR_PRECISION_2))
105 #define LL_CORDIC_PRECISION_13CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_3\
106 | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_0))
107 #define LL_CORDIC_PRECISION_14CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_3\
108 | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1))
109 #define LL_CORDIC_PRECISION_15CYCLES ((uint32_t)(CORDIC_CSR_PRECISION_3\
110 | CORDIC_CSR_PRECISION_2 | CORDIC_CSR_PRECISION_1\
111 | CORDIC_CSR_PRECISION_0))
112 /**
113 * @}
114 */
115
116 /** @defgroup CORDIC_LL_EC_SCALE SCALE
117 * @{
118 */
119 #define LL_CORDIC_SCALE_0 (0x00000000U)
120 #define LL_CORDIC_SCALE_1 ((uint32_t)(CORDIC_CSR_SCALE_0))
121 #define LL_CORDIC_SCALE_2 ((uint32_t)(CORDIC_CSR_SCALE_1))
122 #define LL_CORDIC_SCALE_3 ((uint32_t)(CORDIC_CSR_SCALE_1 | CORDIC_CSR_SCALE_0))
123 #define LL_CORDIC_SCALE_4 ((uint32_t)(CORDIC_CSR_SCALE_2))
124 #define LL_CORDIC_SCALE_5 ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_0))
125 #define LL_CORDIC_SCALE_6 ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_1))
126 #define LL_CORDIC_SCALE_7 ((uint32_t)(CORDIC_CSR_SCALE_2 | CORDIC_CSR_SCALE_1 | CORDIC_CSR_SCALE_0))
127 /**
128 * @}
129 */
130
131 /** @defgroup CORDIC_LL_EC_NBWRITE NBWRITE
132 * @{
133 */
134 #define LL_CORDIC_NBWRITE_1 (0x00000000U) /*!< One 32-bits write containing either only one
135 32-bit data input (Q1.31 format), or two
136 16-bit data input (Q1.15 format) packed
137 in one 32 bits Data */
138 #define LL_CORDIC_NBWRITE_2 CORDIC_CSR_NARGS /*!< Two 32-bit write containing two 32-bits data input
139 (Q1.31 format) */
140 /**
141 * @}
142 */
143
144 /** @defgroup CORDIC_LL_EC_NBREAD NBREAD
145 * @{
146 */
147 #define LL_CORDIC_NBREAD_1 (0x00000000U) /*!< One 32-bits read containing either only one
148 32-bit data output (Q1.31 format), or two
149 16-bit data output (Q1.15 format) packed
150 in one 32 bits Data */
151 #define LL_CORDIC_NBREAD_2 CORDIC_CSR_NRES /*!< Two 32-bit Data containing two 32-bits data output
152 (Q1.31 format) */
153 /**
154 * @}
155 */
156
157 /** @defgroup CORDIC_LL_EC_INSIZE INSIZE
158 * @{
159 */
160 #define LL_CORDIC_INSIZE_32BITS (0x00000000U) /*!< 32 bits input data size (Q1.31 format) */
161 #define LL_CORDIC_INSIZE_16BITS CORDIC_CSR_ARGSIZE /*!< 16 bits input data size (Q1.15 format) */
162 /**
163 * @}
164 */
165
166 /** @defgroup CORDIC_LL_EC_OUTSIZE OUTSIZE
167 * @{
168 */
169 #define LL_CORDIC_OUTSIZE_32BITS (0x00000000U) /*!< 32 bits output data size (Q1.31 format) */
170 #define LL_CORDIC_OUTSIZE_16BITS CORDIC_CSR_RESSIZE /*!< 16 bits output data size (Q1.15 format) */
171 /**
172 * @}
173 */
174
175 /** @defgroup CORDIC_LL_EC_DMA_REG_DATA DMA register data
176 * @{
177 */
178 #define LL_CORDIC_DMA_REG_DATA_IN (0x00000000U) /*!< Get address of input data register */
179 #define LL_CORDIC_DMA_REG_DATA_OUT (0x00000001U) /*!< Get address of output data register */
180 /**
181 * @}
182 */
183
184 /**
185 * @}
186 */
187
188 /* Exported macro ------------------------------------------------------------*/
189 /** @defgroup CORDIC_LL_Exported_Macros CORDIC Exported Macros
190 * @{
191 */
192
193 /** @defgroup CORDIC_LL_EM_WRITE_READ Common Write and read registers Macros
194 * @{
195 */
196
197 /**
198 * @brief Write a value in CORDIC register.
199 * @param __INSTANCE__ CORDIC Instance
200 * @param __REG__ Register to be written
201 * @param __VALUE__ Value to be written in the register
202 * @retval None
203 */
204 #define LL_CORDIC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
205
206 /**
207 * @brief Read a value in CORDIC register.
208 * @param __INSTANCE__ CORDIC Instance
209 * @param __REG__ Register to be read
210 * @retval Register value
211 */
212 #define LL_CORDIC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
213 /**
214 * @}
215 */
216
217 /**
218 * @}
219 */
220
221
222 /* Exported functions --------------------------------------------------------*/
223
224 /** @defgroup CORDIC_LL_Exported_Functions CORDIC Exported Functions
225 * @{
226 */
227
228 /** @defgroup CORDIC_LL_EF_Configuration CORDIC Configuration functions
229 * @{
230 */
231
232 /**
233 * @brief Configure the CORDIC processing.
234 * @note This function set all parameters of CORDIC processing.
235 * These parameters can also be set individually using
236 * dedicated functions:
237 * - @ref LL_CORDIC_SetFunction()
238 * - @ref LL_CORDIC_SetPrecision()
239 * - @ref LL_CORDIC_SetScale()
240 * - @ref LL_CORDIC_SetNbWrite()
241 * - @ref LL_CORDIC_SetNbRead()
242 * - @ref LL_CORDIC_SetInSize()
243 * - @ref LL_CORDIC_SetOutSize()
244 * @rmtoll CSR FUNC LL_CORDIC_Config\n
245 * CSR PRECISION LL_CORDIC_Config\n
246 * CSR SCALE LL_CORDIC_Config\n
247 * CSR NARGS LL_CORDIC_Config\n
248 * CSR NRES LL_CORDIC_Config\n
249 * CSR ARGSIZE LL_CORDIC_Config\n
250 * CSR RESIZE LL_CORDIC_Config
251 * @param CORDICx CORDIC instance
252 * @param Function parameter can be one of the following values:
253 * @arg @ref LL_CORDIC_FUNCTION_COSINE
254 * @arg @ref LL_CORDIC_FUNCTION_SINE
255 * @arg @ref LL_CORDIC_FUNCTION_PHASE
256 * @arg @ref LL_CORDIC_FUNCTION_MODULUS
257 * @arg @ref LL_CORDIC_FUNCTION_ARCTANGENT
258 * @arg @ref LL_CORDIC_FUNCTION_HCOSINE
259 * @arg @ref LL_CORDIC_FUNCTION_HSINE
260 * @arg @ref LL_CORDIC_FUNCTION_HARCTANGENT
261 * @arg @ref LL_CORDIC_FUNCTION_NATURALLOG
262 * @arg @ref LL_CORDIC_FUNCTION_SQUAREROOT
263 * @param Precision parameter can be one of the following values:
264 * @arg @ref LL_CORDIC_PRECISION_1CYCLE
265 * @arg @ref LL_CORDIC_PRECISION_2CYCLES
266 * @arg @ref LL_CORDIC_PRECISION_3CYCLES
267 * @arg @ref LL_CORDIC_PRECISION_4CYCLES
268 * @arg @ref LL_CORDIC_PRECISION_5CYCLES
269 * @arg @ref LL_CORDIC_PRECISION_6CYCLES
270 * @arg @ref LL_CORDIC_PRECISION_7CYCLES
271 * @arg @ref LL_CORDIC_PRECISION_8CYCLES
272 * @arg @ref LL_CORDIC_PRECISION_9CYCLES
273 * @arg @ref LL_CORDIC_PRECISION_10CYCLES
274 * @arg @ref LL_CORDIC_PRECISION_11CYCLES
275 * @arg @ref LL_CORDIC_PRECISION_12CYCLES
276 * @arg @ref LL_CORDIC_PRECISION_13CYCLES
277 * @arg @ref LL_CORDIC_PRECISION_14CYCLES
278 * @arg @ref LL_CORDIC_PRECISION_15CYCLES
279 * @param Scale parameter can be one of the following values:
280 * @arg @ref LL_CORDIC_SCALE_0
281 * @arg @ref LL_CORDIC_SCALE_1
282 * @arg @ref LL_CORDIC_SCALE_2
283 * @arg @ref LL_CORDIC_SCALE_3
284 * @arg @ref LL_CORDIC_SCALE_4
285 * @arg @ref LL_CORDIC_SCALE_5
286 * @arg @ref LL_CORDIC_SCALE_6
287 * @arg @ref LL_CORDIC_SCALE_7
288 * @param NbWrite parameter can be one of the following values:
289 * @arg @ref LL_CORDIC_NBWRITE_1
290 * @arg @ref LL_CORDIC_NBWRITE_2
291 * @param NbRead parameter can be one of the following values:
292 * @arg @ref LL_CORDIC_NBREAD_1
293 * @arg @ref LL_CORDIC_NBREAD_2
294 * @param InSize parameter can be one of the following values:
295 * @arg @ref LL_CORDIC_INSIZE_32BITS
296 * @arg @ref LL_CORDIC_INSIZE_16BITS
297 * @param OutSize parameter can be one of the following values:
298 * @arg @ref LL_CORDIC_OUTSIZE_32BITS
299 * @arg @ref LL_CORDIC_OUTSIZE_16BITS
300 * @retval None
301 */
LL_CORDIC_Config(CORDIC_TypeDef * CORDICx,uint32_t Function,uint32_t Precision,uint32_t Scale,uint32_t NbWrite,uint32_t NbRead,uint32_t InSize,uint32_t OutSize)302 __STATIC_INLINE void LL_CORDIC_Config(CORDIC_TypeDef *CORDICx, uint32_t Function, uint32_t Precision, uint32_t Scale,
303 uint32_t NbWrite, uint32_t NbRead, uint32_t InSize, uint32_t OutSize)
304 {
305 MODIFY_REG(CORDICx->CSR,
306 CORDIC_CSR_FUNC | CORDIC_CSR_PRECISION | CORDIC_CSR_SCALE |
307 CORDIC_CSR_NARGS | CORDIC_CSR_NRES | CORDIC_CSR_ARGSIZE | CORDIC_CSR_RESSIZE,
308 Function | Precision | Scale |
309 NbWrite | NbRead | InSize | OutSize);
310 }
311
312 /**
313 * @brief Configure function.
314 * @rmtoll CSR FUNC LL_CORDIC_SetFunction
315 * @param CORDICx CORDIC Instance
316 * @param Function parameter can be one of the following values:
317 * @arg @ref LL_CORDIC_FUNCTION_COSINE
318 * @arg @ref LL_CORDIC_FUNCTION_SINE
319 * @arg @ref LL_CORDIC_FUNCTION_PHASE
320 * @arg @ref LL_CORDIC_FUNCTION_MODULUS
321 * @arg @ref LL_CORDIC_FUNCTION_ARCTANGENT
322 * @arg @ref LL_CORDIC_FUNCTION_HCOSINE
323 * @arg @ref LL_CORDIC_FUNCTION_HSINE
324 * @arg @ref LL_CORDIC_FUNCTION_HARCTANGENT
325 * @arg @ref LL_CORDIC_FUNCTION_NATURALLOG
326 * @arg @ref LL_CORDIC_FUNCTION_SQUAREROOT
327 * @retval None
328 */
LL_CORDIC_SetFunction(CORDIC_TypeDef * CORDICx,uint32_t Function)329 __STATIC_INLINE void LL_CORDIC_SetFunction(CORDIC_TypeDef *CORDICx, uint32_t Function)
330 {
331 MODIFY_REG(CORDICx->CSR, CORDIC_CSR_FUNC, Function);
332 }
333
334 /**
335 * @brief Return function.
336 * @rmtoll CSR FUNC LL_CORDIC_GetFunction
337 * @param CORDICx CORDIC Instance
338 * @retval Returned value can be one of the following values:
339 * @arg @ref LL_CORDIC_FUNCTION_COSINE
340 * @arg @ref LL_CORDIC_FUNCTION_SINE
341 * @arg @ref LL_CORDIC_FUNCTION_PHASE
342 * @arg @ref LL_CORDIC_FUNCTION_MODULUS
343 * @arg @ref LL_CORDIC_FUNCTION_ARCTANGENT
344 * @arg @ref LL_CORDIC_FUNCTION_HCOSINE
345 * @arg @ref LL_CORDIC_FUNCTION_HSINE
346 * @arg @ref LL_CORDIC_FUNCTION_HARCTANGENT
347 * @arg @ref LL_CORDIC_FUNCTION_NATURALLOG
348 * @arg @ref LL_CORDIC_FUNCTION_SQUAREROOT
349 */
LL_CORDIC_GetFunction(const CORDIC_TypeDef * CORDICx)350 __STATIC_INLINE uint32_t LL_CORDIC_GetFunction(const CORDIC_TypeDef *CORDICx)
351 {
352 return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_FUNC));
353 }
354
355 /**
356 * @brief Configure precision in cycles number.
357 * @rmtoll CSR PRECISION LL_CORDIC_SetPrecision
358 * @param CORDICx CORDIC Instance
359 * @param Precision parameter can be one of the following values:
360 * @arg @ref LL_CORDIC_PRECISION_1CYCLE
361 * @arg @ref LL_CORDIC_PRECISION_2CYCLES
362 * @arg @ref LL_CORDIC_PRECISION_3CYCLES
363 * @arg @ref LL_CORDIC_PRECISION_4CYCLES
364 * @arg @ref LL_CORDIC_PRECISION_5CYCLES
365 * @arg @ref LL_CORDIC_PRECISION_6CYCLES
366 * @arg @ref LL_CORDIC_PRECISION_7CYCLES
367 * @arg @ref LL_CORDIC_PRECISION_8CYCLES
368 * @arg @ref LL_CORDIC_PRECISION_9CYCLES
369 * @arg @ref LL_CORDIC_PRECISION_10CYCLES
370 * @arg @ref LL_CORDIC_PRECISION_11CYCLES
371 * @arg @ref LL_CORDIC_PRECISION_12CYCLES
372 * @arg @ref LL_CORDIC_PRECISION_13CYCLES
373 * @arg @ref LL_CORDIC_PRECISION_14CYCLES
374 * @arg @ref LL_CORDIC_PRECISION_15CYCLES
375 * @retval None
376 */
LL_CORDIC_SetPrecision(CORDIC_TypeDef * CORDICx,uint32_t Precision)377 __STATIC_INLINE void LL_CORDIC_SetPrecision(CORDIC_TypeDef *CORDICx, uint32_t Precision)
378 {
379 MODIFY_REG(CORDICx->CSR, CORDIC_CSR_PRECISION, Precision);
380 }
381
382 /**
383 * @brief Return precision in cycles number.
384 * @rmtoll CSR PRECISION LL_CORDIC_GetPrecision
385 * @param CORDICx CORDIC Instance
386 * @retval Returned value can be one of the following values:
387 * @arg @ref LL_CORDIC_PRECISION_1CYCLE
388 * @arg @ref LL_CORDIC_PRECISION_2CYCLES
389 * @arg @ref LL_CORDIC_PRECISION_3CYCLES
390 * @arg @ref LL_CORDIC_PRECISION_4CYCLES
391 * @arg @ref LL_CORDIC_PRECISION_5CYCLES
392 * @arg @ref LL_CORDIC_PRECISION_6CYCLES
393 * @arg @ref LL_CORDIC_PRECISION_7CYCLES
394 * @arg @ref LL_CORDIC_PRECISION_8CYCLES
395 * @arg @ref LL_CORDIC_PRECISION_9CYCLES
396 * @arg @ref LL_CORDIC_PRECISION_10CYCLES
397 * @arg @ref LL_CORDIC_PRECISION_11CYCLES
398 * @arg @ref LL_CORDIC_PRECISION_12CYCLES
399 * @arg @ref LL_CORDIC_PRECISION_13CYCLES
400 * @arg @ref LL_CORDIC_PRECISION_14CYCLES
401 * @arg @ref LL_CORDIC_PRECISION_15CYCLES
402 */
LL_CORDIC_GetPrecision(const CORDIC_TypeDef * CORDICx)403 __STATIC_INLINE uint32_t LL_CORDIC_GetPrecision(const CORDIC_TypeDef *CORDICx)
404 {
405 return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_PRECISION));
406 }
407
408 /**
409 * @brief Configure scaling factor.
410 * @rmtoll CSR SCALE LL_CORDIC_SetScale
411 * @param CORDICx CORDIC Instance
412 * @param Scale parameter can be one of the following values:
413 * @arg @ref LL_CORDIC_SCALE_0
414 * @arg @ref LL_CORDIC_SCALE_1
415 * @arg @ref LL_CORDIC_SCALE_2
416 * @arg @ref LL_CORDIC_SCALE_3
417 * @arg @ref LL_CORDIC_SCALE_4
418 * @arg @ref LL_CORDIC_SCALE_5
419 * @arg @ref LL_CORDIC_SCALE_6
420 * @arg @ref LL_CORDIC_SCALE_7
421 * @retval None
422 */
LL_CORDIC_SetScale(CORDIC_TypeDef * CORDICx,uint32_t Scale)423 __STATIC_INLINE void LL_CORDIC_SetScale(CORDIC_TypeDef *CORDICx, uint32_t Scale)
424 {
425 MODIFY_REG(CORDICx->CSR, CORDIC_CSR_SCALE, Scale);
426 }
427
428 /**
429 * @brief Return scaling factor.
430 * @rmtoll CSR SCALE LL_CORDIC_GetScale
431 * @param CORDICx CORDIC Instance
432 * @retval Returned value can be one of the following values:
433 * @arg @ref LL_CORDIC_SCALE_0
434 * @arg @ref LL_CORDIC_SCALE_1
435 * @arg @ref LL_CORDIC_SCALE_2
436 * @arg @ref LL_CORDIC_SCALE_3
437 * @arg @ref LL_CORDIC_SCALE_4
438 * @arg @ref LL_CORDIC_SCALE_5
439 * @arg @ref LL_CORDIC_SCALE_6
440 * @arg @ref LL_CORDIC_SCALE_7
441 */
LL_CORDIC_GetScale(const CORDIC_TypeDef * CORDICx)442 __STATIC_INLINE uint32_t LL_CORDIC_GetScale(const CORDIC_TypeDef *CORDICx)
443 {
444 return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_SCALE));
445 }
446
447 /**
448 * @brief Configure number of 32-bit write expected for one calculation.
449 * @rmtoll CSR NARGS LL_CORDIC_SetNbWrite
450 * @param CORDICx CORDIC Instance
451 * @param NbWrite parameter can be one of the following values:
452 * @arg @ref LL_CORDIC_NBWRITE_1
453 * @arg @ref LL_CORDIC_NBWRITE_2
454 * @retval None
455 */
LL_CORDIC_SetNbWrite(CORDIC_TypeDef * CORDICx,uint32_t NbWrite)456 __STATIC_INLINE void LL_CORDIC_SetNbWrite(CORDIC_TypeDef *CORDICx, uint32_t NbWrite)
457 {
458 MODIFY_REG(CORDICx->CSR, CORDIC_CSR_NARGS, NbWrite);
459 }
460
461 /**
462 * @brief Return number of 32-bit write expected for one calculation.
463 * @rmtoll CSR NARGS LL_CORDIC_GetNbWrite
464 * @param CORDICx CORDIC Instance
465 * @retval Returned value can be one of the following values:
466 * @arg @ref LL_CORDIC_NBWRITE_1
467 * @arg @ref LL_CORDIC_NBWRITE_2
468 */
LL_CORDIC_GetNbWrite(const CORDIC_TypeDef * CORDICx)469 __STATIC_INLINE uint32_t LL_CORDIC_GetNbWrite(const CORDIC_TypeDef *CORDICx)
470 {
471 return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_NARGS));
472 }
473
474 /**
475 * @brief Configure number of 32-bit read expected after one calculation.
476 * @rmtoll CSR NRES LL_CORDIC_SetNbRead
477 * @param CORDICx CORDIC Instance
478 * @param NbRead parameter can be one of the following values:
479 * @arg @ref LL_CORDIC_NBREAD_1
480 * @arg @ref LL_CORDIC_NBREAD_2
481 * @retval None
482 */
LL_CORDIC_SetNbRead(CORDIC_TypeDef * CORDICx,uint32_t NbRead)483 __STATIC_INLINE void LL_CORDIC_SetNbRead(CORDIC_TypeDef *CORDICx, uint32_t NbRead)
484 {
485 MODIFY_REG(CORDICx->CSR, CORDIC_CSR_NRES, NbRead);
486 }
487
488 /**
489 * @brief Return number of 32-bit read expected after one calculation.
490 * @rmtoll CSR NRES LL_CORDIC_GetNbRead
491 * @param CORDICx CORDIC Instance
492 * @retval Returned value can be one of the following values:
493 * @arg @ref LL_CORDIC_NBREAD_1
494 * @arg @ref LL_CORDIC_NBREAD_2
495 */
LL_CORDIC_GetNbRead(const CORDIC_TypeDef * CORDICx)496 __STATIC_INLINE uint32_t LL_CORDIC_GetNbRead(const CORDIC_TypeDef *CORDICx)
497 {
498 return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_NRES));
499 }
500
501 /**
502 * @brief Configure width of input data.
503 * @rmtoll CSR ARGSIZE LL_CORDIC_SetInSize
504 * @param CORDICx CORDIC Instance
505 * @param InSize parameter can be one of the following values:
506 * @arg @ref LL_CORDIC_INSIZE_32BITS
507 * @arg @ref LL_CORDIC_INSIZE_16BITS
508 * @retval None
509 */
LL_CORDIC_SetInSize(CORDIC_TypeDef * CORDICx,uint32_t InSize)510 __STATIC_INLINE void LL_CORDIC_SetInSize(CORDIC_TypeDef *CORDICx, uint32_t InSize)
511 {
512 MODIFY_REG(CORDICx->CSR, CORDIC_CSR_ARGSIZE, InSize);
513 }
514
515 /**
516 * @brief Return width of input data.
517 * @rmtoll CSR ARGSIZE LL_CORDIC_GetInSize
518 * @param CORDICx CORDIC Instance
519 * @retval Returned value can be one of the following values:
520 * @arg @ref LL_CORDIC_INSIZE_32BITS
521 * @arg @ref LL_CORDIC_INSIZE_16BITS
522 */
LL_CORDIC_GetInSize(const CORDIC_TypeDef * CORDICx)523 __STATIC_INLINE uint32_t LL_CORDIC_GetInSize(const CORDIC_TypeDef *CORDICx)
524 {
525 return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_ARGSIZE));
526 }
527
528 /**
529 * @brief Configure width of output data.
530 * @rmtoll CSR RESIZE LL_CORDIC_SetOutSize
531 * @param CORDICx CORDIC Instance
532 * @param OutSize parameter can be one of the following values:
533 * @arg @ref LL_CORDIC_OUTSIZE_32BITS
534 * @arg @ref LL_CORDIC_OUTSIZE_16BITS
535 * @retval None
536 */
LL_CORDIC_SetOutSize(CORDIC_TypeDef * CORDICx,uint32_t OutSize)537 __STATIC_INLINE void LL_CORDIC_SetOutSize(CORDIC_TypeDef *CORDICx, uint32_t OutSize)
538 {
539 MODIFY_REG(CORDICx->CSR, CORDIC_CSR_RESSIZE, OutSize);
540 }
541
542 /**
543 * @brief Return width of output data.
544 * @rmtoll CSR RESIZE LL_CORDIC_GetOutSize
545 * @param CORDICx CORDIC Instance
546 * @retval Returned value can be one of the following values:
547 * @arg @ref LL_CORDIC_OUTSIZE_32BITS
548 * @arg @ref LL_CORDIC_OUTSIZE_16BITS
549 */
LL_CORDIC_GetOutSize(const CORDIC_TypeDef * CORDICx)550 __STATIC_INLINE uint32_t LL_CORDIC_GetOutSize(const CORDIC_TypeDef *CORDICx)
551 {
552 return (uint32_t)(READ_BIT(CORDICx->CSR, CORDIC_CSR_RESSIZE));
553 }
554
555 /**
556 * @}
557 */
558
559 /** @defgroup CORDIC_LL_EF_IT_Management IT_Management
560 * @{
561 */
562
563 /**
564 * @brief Enable CORDIC result ready interrupt
565 * @rmtoll CSR IEN LL_CORDIC_EnableIT
566 * @param CORDICx CORDIC Instance
567 * @retval None
568 */
LL_CORDIC_EnableIT(CORDIC_TypeDef * CORDICx)569 __STATIC_INLINE void LL_CORDIC_EnableIT(CORDIC_TypeDef *CORDICx)
570 {
571 SET_BIT(CORDICx->CSR, CORDIC_CSR_IEN);
572 }
573
574 /**
575 * @brief Disable CORDIC result ready interrupt
576 * @rmtoll CSR IEN LL_CORDIC_DisableIT
577 * @param CORDICx CORDIC Instance
578 * @retval None
579 */
LL_CORDIC_DisableIT(CORDIC_TypeDef * CORDICx)580 __STATIC_INLINE void LL_CORDIC_DisableIT(CORDIC_TypeDef *CORDICx)
581 {
582 CLEAR_BIT(CORDICx->CSR, CORDIC_CSR_IEN);
583 }
584
585 /**
586 * @brief Check CORDIC result ready interrupt state.
587 * @rmtoll CSR IEN LL_CORDIC_IsEnabledIT
588 * @param CORDICx CORDIC Instance
589 * @retval State of bit (1 or 0).
590 */
LL_CORDIC_IsEnabledIT(const CORDIC_TypeDef * CORDICx)591 __STATIC_INLINE uint32_t LL_CORDIC_IsEnabledIT(const CORDIC_TypeDef *CORDICx)
592 {
593 return ((READ_BIT(CORDICx->CSR, CORDIC_CSR_IEN) == (CORDIC_CSR_IEN)) ? 1U : 0U);
594 }
595
596 /**
597 * @}
598 */
599
600 /** @defgroup CORDIC_LL_EF_DMA_Management DMA_Management
601 * @{
602 */
603
604 /**
605 * @brief Enable CORDIC DMA read channel request.
606 * @rmtoll CSR DMAREN LL_CORDIC_EnableDMAReq_RD
607 * @param CORDICx CORDIC Instance
608 * @retval None
609 */
LL_CORDIC_EnableDMAReq_RD(CORDIC_TypeDef * CORDICx)610 __STATIC_INLINE void LL_CORDIC_EnableDMAReq_RD(CORDIC_TypeDef *CORDICx)
611 {
612 SET_BIT(CORDICx->CSR, CORDIC_CSR_DMAREN);
613 }
614
615 /**
616 * @brief Disable CORDIC DMA read channel request.
617 * @rmtoll CSR DMAREN LL_CORDIC_DisableDMAReq_RD
618 * @param CORDICx CORDIC Instance
619 * @retval None
620 */
LL_CORDIC_DisableDMAReq_RD(CORDIC_TypeDef * CORDICx)621 __STATIC_INLINE void LL_CORDIC_DisableDMAReq_RD(CORDIC_TypeDef *CORDICx)
622 {
623 CLEAR_BIT(CORDICx->CSR, CORDIC_CSR_DMAREN);
624 }
625
626 /**
627 * @brief Check CORDIC DMA read channel request state.
628 * @rmtoll CSR DMAREN LL_CORDIC_IsEnabledDMAReq_RD
629 * @param CORDICx CORDIC Instance
630 * @retval State of bit (1 or 0).
631 */
LL_CORDIC_IsEnabledDMAReq_RD(const CORDIC_TypeDef * CORDICx)632 __STATIC_INLINE uint32_t LL_CORDIC_IsEnabledDMAReq_RD(const CORDIC_TypeDef *CORDICx)
633 {
634 return ((READ_BIT(CORDICx->CSR, CORDIC_CSR_DMAREN) == (CORDIC_CSR_DMAREN)) ? 1U : 0U);
635 }
636
637 /**
638 * @brief Enable CORDIC DMA write channel request.
639 * @rmtoll CSR DMAWEN LL_CORDIC_EnableDMAReq_WR
640 * @param CORDICx CORDIC Instance
641 * @retval None
642 */
LL_CORDIC_EnableDMAReq_WR(CORDIC_TypeDef * CORDICx)643 __STATIC_INLINE void LL_CORDIC_EnableDMAReq_WR(CORDIC_TypeDef *CORDICx)
644 {
645 SET_BIT(CORDICx->CSR, CORDIC_CSR_DMAWEN);
646 }
647
648 /**
649 * @brief Disable CORDIC DMA write channel request.
650 * @rmtoll CSR DMAWEN LL_CORDIC_DisableDMAReq_WR
651 * @param CORDICx CORDIC Instance
652 * @retval None
653 */
LL_CORDIC_DisableDMAReq_WR(CORDIC_TypeDef * CORDICx)654 __STATIC_INLINE void LL_CORDIC_DisableDMAReq_WR(CORDIC_TypeDef *CORDICx)
655 {
656 CLEAR_BIT(CORDICx->CSR, CORDIC_CSR_DMAWEN);
657 }
658
659 /**
660 * @brief Check CORDIC DMA write channel request state.
661 * @rmtoll CSR DMAWEN LL_CORDIC_IsEnabledDMAReq_WR
662 * @param CORDICx CORDIC Instance
663 * @retval State of bit (1 or 0).
664 */
LL_CORDIC_IsEnabledDMAReq_WR(const CORDIC_TypeDef * CORDICx)665 __STATIC_INLINE uint32_t LL_CORDIC_IsEnabledDMAReq_WR(const CORDIC_TypeDef *CORDICx)
666 {
667 return ((READ_BIT(CORDICx->CSR, CORDIC_CSR_DMAWEN) == (CORDIC_CSR_DMAWEN)) ? 1U : 0U);
668 }
669
670 /**
671 * @brief Get the CORDIC data register address used for DMA transfer.
672 * @rmtoll RDATA RES LL_CORDIC_DMA_GetRegAddr\n
673 * @rmtoll WDATA ARG LL_CORDIC_DMA_GetRegAddr
674 * @param CORDICx CORDIC Instance
675 * @param Direction parameter can be one of the following values:
676 * @arg @ref LL_CORDIC_DMA_REG_DATA_IN
677 * @arg @ref LL_CORDIC_DMA_REG_DATA_OUT
678 * @retval Address of data register
679 */
LL_CORDIC_DMA_GetRegAddr(const CORDIC_TypeDef * CORDICx,uint32_t Direction)680 __STATIC_INLINE uint32_t LL_CORDIC_DMA_GetRegAddr(const CORDIC_TypeDef *CORDICx, uint32_t Direction)
681 {
682 uint32_t data_reg_addr;
683
684 if (Direction == LL_CORDIC_DMA_REG_DATA_OUT)
685 {
686 /* return address of RDATA register */
687 data_reg_addr = (uint32_t) &(CORDICx->RDATA);
688 }
689 else
690 {
691 /* return address of WDATA register */
692 data_reg_addr = (uint32_t) &(CORDICx->WDATA);
693 }
694
695 return data_reg_addr;
696 }
697
698 /**
699 * @}
700 */
701
702 /** @defgroup CORDIC_LL_EF_FLAG_Management FLAG_Management
703 * @{
704 */
705
706 /**
707 * @brief Check CORDIC result ready flag state.
708 * @rmtoll CSR RRDY LL_CORDIC_IsActiveFlag_RRDY
709 * @param CORDICx CORDIC Instance
710 * @retval State of bit (1 or 0).
711 */
LL_CORDIC_IsActiveFlag_RRDY(const CORDIC_TypeDef * CORDICx)712 __STATIC_INLINE uint32_t LL_CORDIC_IsActiveFlag_RRDY(const CORDIC_TypeDef *CORDICx)
713 {
714 return ((READ_BIT(CORDICx->CSR, CORDIC_CSR_RRDY) == (CORDIC_CSR_RRDY)) ? 1U : 0U);
715 }
716
717 /**
718 * @}
719 */
720
721 /** @defgroup CORDIC_LL_EF_Data_Management Data_Management
722 * @{
723 */
724
725 /**
726 * @brief Write 32-bit input data for the CORDIC processing.
727 * @rmtoll WDATA ARG LL_CORDIC_WriteData
728 * @param CORDICx CORDIC Instance
729 * @param InData 0 .. 0xFFFFFFFF : 32-bit value to be provided as input data for CORDIC processing.
730 * @retval None
731 */
LL_CORDIC_WriteData(CORDIC_TypeDef * CORDICx,uint32_t InData)732 __STATIC_INLINE void LL_CORDIC_WriteData(CORDIC_TypeDef *CORDICx, uint32_t InData)
733 {
734 WRITE_REG(CORDICx->WDATA, InData);
735 }
736
737 /**
738 * @brief Return 32-bit output data of CORDIC processing.
739 * @rmtoll RDATA RES LL_CORDIC_ReadData
740 * @param CORDICx CORDIC Instance
741 * @retval 32-bit output data of CORDIC processing.
742 */
LL_CORDIC_ReadData(const CORDIC_TypeDef * CORDICx)743 __STATIC_INLINE uint32_t LL_CORDIC_ReadData(const CORDIC_TypeDef *CORDICx)
744 {
745 return (uint32_t)(READ_REG(CORDICx->RDATA));
746 }
747
748 /**
749 * @}
750 */
751
752
753
754 #if defined(USE_FULL_LL_DRIVER)
755 /** @defgroup CORDIC_LL_EF_Init Initialization and de-initialization functions
756 * @{
757 */
758 ErrorStatus LL_CORDIC_DeInit(const CORDIC_TypeDef *CORDICx);
759
760 /**
761 * @}
762 */
763 #endif /* USE_FULL_LL_DRIVER */
764
765 /**
766 * @}
767 */
768
769 /**
770 * @}
771 */
772
773 #endif /* defined(CORDIC) */
774
775 /**
776 * @}
777 */
778
779 #ifdef __cplusplus
780 }
781 #endif
782
783 #endif /* STM32H5xx_LL_CORDIC_H */
784