XMC Math
XMC Math
XMC Math
2 * @file xmc_math.h
3 * @date 2015-06-20
4 *
5 * @cond
6 **********************************************************************************
7 * XMClib v2.0.0 - XMC Peripheral Driver Library
8 *
9 * Copyright (c) 2015, Infineon Technologies AG
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification,are permitted provided that the following conditions are met:
14 *
15 * Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 *
18 * Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 *
22 * Neither the name of the copyright holders nor the names of its contributors
23 * may be used to endorse or promote products derived from this software without
24 * specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 * To improve the quality of the software, users are encouraged to share
39 * modifications, enhancements or bug fixes with Infineon Technologies AG
40 * [email protected]).
41 **********************************************************************************
42 *
43 * Change History
44 * --------------
45 *
46 * 2015-06-20:
47 * - Removed version macros and declaration of GetDriverVersion API <br>
48 * - Updated copyright and change history section.
49 *
50 * @endcond
51 *
52 */
53
54 #ifndef XMC_MATH_H
55 #define XMC_MATH_H
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 /*************************************************************************************
********************************
62 * HEADER FILES
63
*************************************************************************************
*******************************/
64 #include <xmc_common.h>
65 #include <xmc_scu.h>
66
67 #if defined(MATH)
68
69 /**
70 * @addtogroup XMClib
71 * @{
72 */
73
74 /**
75 * @addtogroup MATH
76 * @{
77 * @brief MATH Coprocessor (MATH) driver for the XMC1302 microcontroller family <br>
78 *
79 * The MATH Coprocessor (MATH) module comprises of two independent sub-blocks to
support the CPU in math-intensive
80 * computations: a Divider Unit (DIV) for signed and unsigned 32-bit division
operations and a CORDIC
81 * (COrdinate Rotation DIgital Computer) Coprocessor for computation of
trigonometric, linear or hyperbolic functions.<br>
82 *
83 * MATH driver features:
84 * -# CORDIC Coprocessor is used for computation of trigonometric and hyperbolic
functions
85 * -# Supports result chaining between the Divider Unit and CORDIC Coprocessor
86 * -# All MATH APIs are available in <B>Blocking</B> and <B>non-blocking</B> modes.
Non-blocking APIs are suffixed with <B>NB</B>.
87 * -# 32bit signed and unsigned division implementations available for
__aeabi_uidiv(), __aeabi_idiv(), __aeabi_uidivmod(), __aeabi_idivmod()
88 * -# Divider and CORDIC unit busy status can be checked by XMC_MATH_DIV_IsBusy() and
XMC_MATH_CORDIC_IsBusy()
89 * -# Individual APIs available to return the result of each non-blocking MATH
function
90 *
91 * <B>Note:</B> <br>
92 * All non-blocking MATH APIs are not atomic and hence occurence of interrupts during
the normal execution of
93 * these APIs may lead to erroneous results. User has to exercise caution while using
these APIs.
94 *
95 * Example:
96 * Execution of divide instruction (/) in an ISR during the normal execution of
non-blocking APIs may give erroneous results.
97 *
98 */
99
100
101 /*************************************************************************************
********************************
102 * TYPE DEFINITIONS
103
*************************************************************************************
*******************************/
104 /**
105 * @brief This typedef is used for Input and Output Data representation in blocking &
non-blocking functions.
106 * XMC_MATH_Q0_23_t => 1 Signed bit, 0 Integer bits, 23 fraction bits.
107 */
108 typedef int32_t XMC_MATH_Q0_23_t;
109
110 /**
111 * @brief This typedef is used for Input Data representation in blocking &
non-blocking functions.
112 * XMC_MATH_Q8_15_t => 1 Signed bit, 8 Integer bits, 15 fraction bits.
113 */
114 typedef int32_t XMC_MATH_Q8_15_t;
115
116 /**
117 * @brief This typedef is used for Output Data representation in blocking &
non-blocking functions.
118 * XMC_MATH_Q1_22_t => 1 Signed bit, 1 Integer bits, 22 fraction bits.
119 */
120 typedef int32_t XMC_MATH_Q1_22_t;
121
122 /**
123 * @brief This typedef is used for Output Data representation in blocking &
non-blocking functions.
124 * XMC_MATH_Q0_11_t => 1 Signed bit, 0 Integer bits, 11 fraction bits.
125 */
126 typedef int32_t XMC_MATH_Q0_11_t;
127
128 /*************************************************************************************
********************************
129 * MACROS
130
*************************************************************************************
*******************************/
131 /* Utility macros */
132 #define XMC_MATH_Q0_23(x) ((XMC_MATH_Q0_23_t)(((x) >= 0) ? ((x) * (1 << 23) + 0.5) :
((x) * (1 << 23) - 0.5))) /**< Converts the given number to XMC_MATH_Q0_23_t format */
133 #define XMC_MATH_Q0_11(x) ((XMC_MATH_Q0_11_t)(((x) >= 0) ? ((x) * (1 << 11) + 0.5) :
((x) * (1 << 11) - 0.5))) /**< Converts the given number to XMC_MATH_Q0_11_t format */
134
135 /*************************************************************************************
********************************
136 * ENUMS
137
*************************************************************************************
*******************************/
138
139 /**
140 * @brief Service request events for the DIV and CORDIC modules
141 */
142 typedef enum XMC_MATH_EVENT
143 {
144 XMC_MATH_EVENT_DIV_END_OF_CALC = 1U, /**< Divider end of calculation event */
145 XMC_MATH_EVENT_DIV_ERROR = 2U, /**< Divider error event */
146 XMC_MATH_EVENT_CORDIC_END_OF_CALC = 4U, /**< CORDIC end of calculation event */
147 XMC_MATH_EVENT_CORDIC_ERROR = 8U /**< CORDIC error event */
148 } XMC_MATH_EVENT_t;
149
150 /**
151 * @brief Dividend Register Result Chaining
152 */
153 typedef enum XMC_MATH_DIV_DVDRC
154 {
155 XMC_MATH_DIV_DVDRC_DISABLED = 0U << MATH_GLBCON_DVDRC_Pos, /**< No result
chaining is selected */
156 XMC_MATH_DIV_DVDRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_DVDRC_Pos, /**< QUOT
register is the selected source */
157 XMC_MATH_DIV_DVDRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_DVDRC_Pos, /**< RMD register
is the selected source */
158 XMC_MATH_DIV_DVDRC_CORRX_IS_SOURCE = 3U << MATH_GLBCON_DVDRC_Pos, /**< CORRX is the
selected source */
159 XMC_MATH_DIV_DVDRC_CORRY_IS_SOURCE = 4U << MATH_GLBCON_DVDRC_Pos, /**< CORRY is the
selected source */
160 XMC_MATH_DIV_DVDRC_CORRZ_IS_SOURCE = 5U << MATH_GLBCON_DVDRC_Pos /**< CORRZ is the
selected source */
161 } XMC_MATH_DIV_DVDRC_t;
162
163 /**
164 * @brief Divisor Register Result Chaining
165 */
166 typedef enum XMC_MATH_DIV_DVSRC
167 {
168 XMC_MATH_DIV_DVSRC_DISABLED = 0U << MATH_GLBCON_DVSRC_Pos, /**< No result
chaining is selected */
169 XMC_MATH_DIV_DVSRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_DVSRC_Pos, /**< QUOT
register is the selected source */
170 XMC_MATH_DIV_DVSRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_DVSRC_Pos, /**< RMD register
is the selected source */
171 XMC_MATH_DIV_DVSRC_CORRX_IS_SOURCE = 3U << MATH_GLBCON_DVSRC_Pos, /**< CORRX is the
selected source */
172 XMC_MATH_DIV_DVSRC_CORRY_IS_SOURCE = 4U << MATH_GLBCON_DVSRC_Pos, /**< CORRY is the
selected source */
173 XMC_MATH_DIV_DVSRC_CORRZ_IS_SOURCE = 5U << MATH_GLBCON_DVSRC_Pos /**< CORRZ is the
selected source */
174 } XMC_MATH_DIV_DVSRC_t;
175
176 /**
177 * @brief CORDX Register Result Chaining
178 */
179 typedef enum XMC_MATH_CORDIC_CORDXRC
180 {
181 XMC_MATH_CORDIC_CORDXRC_DISABLED = 0U << MATH_GLBCON_CORDXRC_Pos, /**< No
result chaining is selected */
182 XMC_MATH_CORDIC_CORDXRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_CORDXRC_Pos, /**< QUOT
register is the selected source */
183 XMC_MATH_CORDIC_CORDXRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_CORDXRC_Pos /**< RMD
register is the selected source */
184 } XMC_MATH_CORDIC_CORDXRC_t;
185
186 /**
187 * @brief CORDY Register Result Chaining
188 */
189 typedef enum XMC_MATH_CORDIC_CORDYRC
190 {
191 XMC_MATH_CORDIC_CORDYRC_DISABLED = 0U << MATH_GLBCON_CORDYRC_Pos, /**< No
result chaining is selected */
192 XMC_MATH_CORDIC_CORDYRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_CORDYRC_Pos, /**< QUOT
register is the selected source */
193 XMC_MATH_CORDIC_CORDYRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_CORDYRC_Pos /**< RMD
register is the selected source */
194 } XMC_MATH_CORDIC_CORDYRC_t;
195
196 /**
197 * @brief CORDZ Register Result Chaining
198 */
199 typedef enum XMC_MATH_CORDIC_CORDZRC
200 {
201 XMC_MATH_CORDIC_CORDZRC_DISABLED = 0U << MATH_GLBCON_CORDZRC_Pos, /**< No
result chaining is selected */
202 XMC_MATH_CORDIC_CORDZRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_CORDZRC_Pos, /**< QUOT
register is the selected source */
203 XMC_MATH_CORDIC_CORDZRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_CORDZRC_Pos /**< RMD
register is the selected source */
204 } XMC_MATH_CORDIC_CORDZRC_t;
205 /**
206 * @brief CORDIC operating mode
207 */
208 typedef enum XMC_MATH_CORDIC_OPERATING_MODE
209 {
210 XMC_MATH_CORDIC_OPERATING_MODE_LINEAR = 0U << MATH_CON_MODE_Pos, /**< Linear
mode */
211 XMC_MATH_CORDIC_OPERATING_MODE_CIRCULAR = 1U << MATH_CON_MODE_Pos, /**<
Circular mode */
212 XMC_MATH_CORDIC_OPERATING_MODE_HYPERBOLIC = 3U << MATH_CON_MODE_Pos /**<
Hyperbolic mode */
213 } XMC_MATH_CORDIC_OPERATING_MODE_t;
214
215 /**
216 * @brief Rotation vectoring selection
217 */
218 typedef enum XMC_MATH_CORDIC_ROTVEC_MODE
219 {
220 XMC_MATH_CORDIC_ROTVEC_MODE_VECTORING = 0U << MATH_CON_ROTVEC_Pos, /**<
Vectoring mode */
221 XMC_MATH_CORDIC_ROTVEC_MODE_ROTATION = 1U << MATH_CON_ROTVEC_Pos /**<
Rotation mode */
222 } XMC_MATH_CORDIC_ROTVEC_MODE_t;
223
224 /**
225 * @brief Calculated value of CORRX and CORRY are each divided by this factor to
yield the result.
226 */
227 typedef enum XMC_MATH_CORDIC_MAGNITUDE
228 {
229 XMC_MATH_CORDIC_MAGNITUDE_DIVBY1 = 0U << MATH_CON_MPS_Pos, /**< Divide
by 1 */
230 XMC_MATH_CORDIC_MAGNITUDE_DIVBY2 = 1U << MATH_CON_MPS_Pos, /**< Divide
by 2 */
231 XMC_MATH_CORDIC_MAGNITUDE_DIVBY4 = 2U << MATH_CON_MPS_Pos, /**< Divide
by 4 */
232 } XMC_MATH_CORDIC_MAGNITUDE_t;
233
234 /*************************************************************************************
********************************
235 * DATA STRUCTURES
236
*************************************************************************************
*******************************/
237
238 /*************************************************************************************
********************************
239 * API Prototypes - General
240
*************************************************************************************
*******************************/
241
242 /**
243 *
244 * @return None
245 *
246 * \par<b>Description:</b><br>
247 * Enables the Math module by un-gating the clock.
248 *
249 * \par
250 * MATH coprocessor's clock is enabled by setting \a MATH bit of \a CGATCLR0 register.
251 *
252 * \par<b>Related APIs:</b><BR>
253 * XMC_MATH_Disable()\n\n\n
254 *
255 */
256 __STATIC_INLINE void XMC_MATH_Enable(void)
257 {
258 /* Un-gates clock to the MATH kernel */
259 XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_MATH);
260 }
261
262 /**
263 *
264 * @return None
265 *
266 * \par<b>Description:</b><br>
267 * Disables the Math module by gating the clock.
268 *
269 * \par
270 * MATH coprocessor's clock is disabled by setting \a MATH bit of \a CGATSET0
register.
271 *
272 * \par<b>Related APIs:</b><BR>
273 * XMC_MATH_Disable()\n\n\n
274 *
275 */
276 __STATIC_INLINE void XMC_MATH_Disable(void)
277 {
278 /* Gates clock to the MATH kernel */
279 XMC_SCU_CLOCK_GatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_MATH);
280 }
281
282 /**
283 *
284 * @return bool \n
285 * true - if DIV unit is busy
286 * false - if DIV unit is not busy
287 *
288 * \par<b>Description:</b><br>
289 * Utility function to check if the DIV unit is busy.
290 *
291 * \par
292 * Divider unit status is determined by reading \a BSY bit of \a DIVST register.
293 *
294 */
295 bool XMC_MATH_DIV_IsBusy(void);
296
297 /**
298 *
299 * @return bool \n
300 * true - if CORDIC unit is busy\n
301 * false - if CORDIC unit is not busy
302 *
303 * \par<b>Description:</b><br>
304 * Utility function to check if the DIV unit is busy.
305 *
306 * \par
307 * CORDIC coprocessor's status is determined by reading \a BSY bit of \a STATC
register.
308 *
309 */
310 bool XMC_MATH_CORDIC_IsBusy(void);
311
312 /**
313 * @param event Event of type XMC_MATH_EVENT_t
314 *
315 * @return bool\n
316 * true - if status is set\n
317 * false - if status is not set
318 *
319 * \par<b>Description:</b><br>
320 * Returns the status of the requested event.
321 *
322 * \par
323 * Status of DIV & CORDIC unit's event (end of calculation & error) status is
determined by reading \a EVFR register.
324 *
325 * \par<b>Related APIs:</b><BR>
326 * XMC_MATH_EnableEvent(), XMC_MATH_DisableEvent(), XMC_MATH_SetEvent(),
XMC_MATH_ClearEvent()\n\n\n
327 *
328 */
329 bool XMC_MATH_GetEventStatus(const XMC_MATH_EVENT_t event);
330
331 /**
332 * @param event Event of type XMC_MATH_EVENT_t
333 *
334 * @return None
335 *
336 * \par<b>Description:</b><br>
337 * Enables the requested event.
338 *
339 * \par
340 * DIV & CORDIC unit's event (end of calculation & error) is enabled by setting
bit-fields of \a EVIER register.
341 *
342 * \par<b>Related APIs:</b><BR>
343 * XMC_MATH_GetEventStatus(), XMC_MATH_DisableEvent()\n\n\n
344 *
345 */
346 __STATIC_INLINE void XMC_MATH_EnableEvent(const XMC_MATH_EVENT_t event)
347 {
348 MATH->EVIER |= (uint32_t) event;
349 }
350
351 /**
352 * @param event Event of type XMC_MATH_EVENT_t
353 *
354 * @return None
355 *
356 * \par<b>Description:</b><br>
357 * Disables the requested event.
358 *
359 * \par
360 * DIV & CORDIC unit's event (end of calculation & error) is disabled by clearing
bit-fields of \a EVIER register.
361 *
362 * \par<b>Related APIs:</b><BR>
363 * XMC_MATH_GetEventStatus(), XMC_MATH_EnableEvent()\n\n\n
364 *
365 */
366 __STATIC_INLINE void XMC_MATH_DisableEvent(const XMC_MATH_EVENT_t event)
367 {
368 MATH->EVIER &= ~((uint32_t) event);
369 }
370
371 /**
372 * @param event Event of type XMC_MATH_EVENT_t
373 *
374 * @return None
375 *
376 * \par<b>Description:</b><br>
377 * Sets the requested event. This is a software setting for the event.
378 *
379 * \par
380 * DIV & CORDIC unit's event (end of calculation & error) is set by setting
bit-fields of \a EVFSR register.
381 *
382 * \par<b>Related APIs:</b><BR>
383 * XMC_MATH_ClearEvent()\n\n\n
384 *
385 */
386 __STATIC_INLINE void XMC_MATH_SetEvent(const XMC_MATH_EVENT_t event)
387 {
388 MATH->EVFSR |= (uint32_t) event;
389 }
390
391 /**
392 * @param event Event of type XMC_MATH_EVENT_t
393 *
394 * @return None
395 *
396 * \par<b>Description:</b><br>
397 * Clears the requested event.
398 *
399 * \par
400 * DIV & CORDIC unit's event (end of calculation & error) is cleared by setting
bit-fields of \a EVFCR register.
401 *
402 * \par<b>Related APIs:</b><BR>
403 * XMC_MATH_SetEvent()\n\n\n
404 *
405 */
406 __STATIC_INLINE void XMC_MATH_ClearEvent(const XMC_MATH_EVENT_t event)
407 {
408 MATH->EVFCR &= ~((uint32_t) event);
409 }
410
411 /**
412 * @return XMC_MATH_Q0_23_t
413 *
414 * \par<b>Description:</b><br>
415 * Returns result of a Cosine operation.
416 *
417 * \par
418 * Most significant 24 bits of \a CORRX register returns the result of Cosine
operation.
419 *
420 * \par<b>Related APIs:</b><BR>
421 * XMC_MATH_CORDIC_CosNB()\n\n\n
422 *
423 */
424 __STATIC_INLINE XMC_MATH_Q0_23_t XMC_MATH_CORDIC_GetCosResult(void)
425 {
426 return ((XMC_MATH_Q0_23_t) (MATH->CORRX >> MATH_CORRX_RESULT_Pos));
427 }
428
429 /**
430 * @return XMC_MATH_Q0_23_t
431 *
432 * \par<b>Description:</b><br>
433 * Returns result of a Sine operation.
434 *
435 * \par
436 * Most significant 24 bits of \a CORRY register returns the result of Sine operation.
437 *
438 * \par<b>Related APIs:</b><BR>
439 * XMC_MATH_CORDIC_SinNB()\n\n\n
440 *
441 */
442 __STATIC_INLINE XMC_MATH_Q0_23_t XMC_MATH_CORDIC_GetSinResult(void)
443 {
444 return ((XMC_MATH_Q0_23_t) (MATH->CORRY >> MATH_CORRY_RESULT_Pos));
445 }
446
447 /**
448 * @return XMC_MATH_Q0_11_t
449 *
450 * \par<b>Description:</b><br>
451 * Returns result of a Tangent operation.
452 *
453 * \par
454 * \a QUOT register returns the result of Tangent operation.
455 *
456 * \par<b>Related APIs:</b><BR>
457 * XMC_MATH_CORDIC_TanNB()\n\n\n
458 *
459 */
460 __STATIC_INLINE XMC_MATH_Q0_11_t XMC_MATH_CORDIC_GetTanResult(void)
461 {
462 return ((XMC_MATH_Q0_11_t) MATH->QUOT);
463 }
464
465 /**
466 * @return XMC_MATH_Q0_23_t
467 *
468 * \par<b>Description:</b><br>
469 * Returns result of a Arc Tangent operation.
470 *
471 * \par
472 * Most significant 24 bits of \a CORRZ register returns the result of Arc Tangent
operation.
473 *
474 * \par<b>Related APIs:</b><BR>
475 * XMC_MATH_CORDIC_ArcTanNB()\n\n\n
476 *
477 */
478 __STATIC_INLINE XMC_MATH_Q0_23_t XMC_MATH_CORDIC_GetArcTanResult(void)
479 {
480 return ((XMC_MATH_Q0_23_t) (MATH->CORRZ >> MATH_CORRZ_RESULT_Pos));
481 }
482
483 /**
484 * @return XMC_MATH_Q1_22_t
485 *
486 * \par<b>Description:</b><br>
487 * Returns result of a Hyperbolic Cosine operation.
488 *
489 * \par
490 * Most significant 24 bits of \a CORRX register returns the result of Hyperbolic
Cosine operation.
491 *
492 * \par<b>Related APIs:</b><BR>
493 * XMC_MATH_CORDIC_CoshNB()\n\n\n
494 *
495 */
496 __STATIC_INLINE XMC_MATH_Q1_22_t XMC_MATH_CORDIC_GetCoshResult(void)
497 {
498 return ((XMC_MATH_Q1_22_t) (MATH->CORRX >> MATH_CORRX_RESULT_Pos));
499 }
500
501 /**
502 * @return XMC_MATH_Q1_22_t
503 *
504 * \par<b>Description:</b><br>
505 * Returns result of a Hyperbolic Sine operation.
506 *
507 * \par
508 * Most significant 24 bits of \a CORRY register returns the result of Hyperbolic
Sine operation.
509 *
510 * \par<b>Related APIs:</b><BR>
511 * XMC_MATH_CORDIC_SinhNB()\n\n\n
512 *
513 */
514 __STATIC_INLINE XMC_MATH_Q1_22_t XMC_MATH_CORDIC_GetSinhResult(void)
515 {
516 return ((XMC_MATH_Q1_22_t) (MATH->CORRY >> MATH_CORRY_RESULT_Pos));
517 }
518
519 /**
520 * @return XMC_MATH_Q0_11_t
521 *
522 * \par<b>Description:</b><br>
523 * Returns result of a Hyperbolic Tangent operation.
524 *
525 * \par
526 * \a QUOT register returns the result of Hyperbolic Tangent operation.
527 *
528 * \par<b>Related APIs:</b><BR>
529 * XMC_MATH_CORDIC_TanhNB()\n\n\n
530 *
531 */
532 __STATIC_INLINE XMC_MATH_Q0_11_t XMC_MATH_CORDIC_GetTanhResult(void)
533 {
534 return ((XMC_MATH_Q0_11_t) MATH->QUOT);
535 }
536
537 /**
538 * @return uint32_t
539 *
540 * \par<b>Description:</b><br>
541 * Returns result of a Unsigned Division operation.
542 *
543 * \par
544 * \a QUOT register returns the result of Unsigned Division operation.
545 *
546 * \par<b>Related APIs:</b><BR>
547 * XMC_MATH_DIV_UnsignedDivNB()\n\n\n
548 *
549 */
550 __STATIC_INLINE uint32_t XMC_MATH_DIV_GetUnsignedDivResult(void)
551 {
552 return ((uint32_t) MATH->QUOT);
553 }
554
555 /**
556 * @return uint32_t
557 *
558 * \par<b>Description:</b><br>
559 * Returns result of a Unsigned Modulo operation.
560 *
561 * \par
562 * \a RMD register returns the result of Unsigned Modulo operation.
563 *
564 * \par<b>Related APIs:</b><BR>
565 * XMC_MATH_DIV_UnsignedModNB()\n\n\n
566 *
567 */
568 __STATIC_INLINE uint32_t XMC_MATH_DIV_GetUnsignedModResult(void)
569 {
570 return ((uint32_t) MATH->RMD);
571 }
572
573 /**
574 * @return int32_t
575 *
576 * \par<b>Description:</b><br>
577 * Returns result of a Signed Division operation.
578 *
579 * \par
580 * \a QUOT register returns the result of Signed Division operation.
581 *
582 * \par<b>Related APIs:</b><BR>
583 * XMC_MATH_DIV_SignedDivNB()\n\n\n
584 *
585 */
586 __STATIC_INLINE int32_t XMC_MATH_DIV_GetSignedDivResult(void)
587 {
588 return ((int32_t) MATH->QUOT);
589 }
590
591 /**
592 * @return int32_t
593 *
594 * \par<b>Description:</b><br>
595 * Returns result of a Signed Modulo operation.
596 *
597 * \par
598 * \a RMD register returns the result of Signed Modulo operation.
599 *
600 * \par<b>Related APIs:</b><BR>
601 * XMC_MATH_DIV_SignedModNB()\n\n\n
602 *
603 */
604 __STATIC_INLINE int32_t XMC_MATH_DIV_GetSignedModResult(void)
605 {
606 return ((int32_t) MATH->RMD);
607 }
608
609 /*************************************************************************************
**********************************
610 * API Prototypes - Blocking functions
611
*************************************************************************************
*********************************/
612 /**
613 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
614 *
615 * @return XMC_MATH_Q0_23_t <BR>
616 *
617 * \par<b>Description:</b><br>
618 * Computes the cosine for an angle in radians \e angle_in_radians.
619 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
620 *
621 * \par
622 * This function programs CORDIC to rotation & circular mode.
623 * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register
with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023.
624 * Most significant 24 bits of \a CORRX register returns the result of the operation.
625 *
626 * \par<b>Note:</b><br>
627 * Loading of \a CORDX register triggers the start of computation.
628 *
629 * \par<b>Related APIs:</b><BR>
630 * XMC_MATH_CORDIC_Sin(), XMC_MATH_CORDIC_Tan()\n\n\n
631 *
632 */
633 XMC_MATH_Q0_23_t XMC_MATH_CORDIC_Cos(XMC_MATH_Q0_23_t angle_in_radians);
634
635 /**
636 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
637 *
638 * @return XMC_MATH_Q0_23_t <BR>
639 *
640 * \par<b>Description:</b><br>
641 * Computes the sine for an angle in radians \e angle_in_radians.
642 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
643 *
644 * \par
645 * This function programs CORDIC to rotation & circular mode.
646 * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register
with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023.
647 * Most significant 24 bits of \a CORRY register returns the result of the operation.
648 *
649 * \par<b>Note:</b><br>
650 * Loading of \a CORDX register triggers the start of computation.
651 *
652 * \par<b>Related APIs:</b><BR>
653 * XMC_MATH_CORDIC_Cos(), XMC_MATH_CORDIC_Tan()\n\n\n
654 *
655 */
656 XMC_MATH_Q0_23_t XMC_MATH_CORDIC_Sin(XMC_MATH_Q0_23_t angle_in_radians);
657
658 /**
659 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
660 *
661 * @return XMC_MATH_Q0_11_t <BR>
662 *
663 * \par<b>Description:</b><br>
664 * Computes the tangent for an angle in radians \e angle_in_radians.
665 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
666 *
667 * \par
668 * This function programs CORDIC to rotation & circular mode.
669 * Chains the results of Cosine (\a CORRX) and Sine (\a CORRY) as a dividend and
divisor by configuring \a GLBCON register.
670 * \a CORDZ register is programmed with input \a angle_in_radians and \a CORDX
register with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023.
671 * Most significant 24 bits of \a CORRY register returns the result of the operation.
672 *
673 * \par<b>Note:</b><br>
674 * Loading of \a CORDX register triggers the start of computation.
675 *
676 * \par<b>Related APIs:</b><BR>
677 * XMC_MATH_CORDIC_Sin(), XMC_MATH_CORDIC_Cos()\n\n\n
678 *
679 */
680 XMC_MATH_Q0_11_t XMC_MATH_CORDIC_Tan(XMC_MATH_Q0_23_t angle_in_radians);
681
682 /**
683 *
684 * @param x Value representing the proportion of the x-coordinate (XMC_MATH_Q8_15_t
format)
685 * @param y Value representing the proportion of the y-coordinate (XMC_MATH_Q8_15_t
format)
686 *
687 * @return XMC_MATH_Q0_23_t <BR>
688 *
689 * \par<b>Description:</b><br>
690 * Computes the principal value arc tangent of an angle of y/x expressed in radians.
691 * The input radians must be in XMC_MATH_Q8_15_t format.
692 *
693 * \par
694 * This function programs CORDIC as circular mode.
695 * \a CORDY register is programmed with input \a y and \a CORDX register is
programmed with input \a x.
696 * Most significant 24 bits of \a CORRZ register returns the result of the operation.
697 *
698 * \par<b>Note:</b><br>
699 * Loading of \a CORDX register triggers the start of computation.
700 *
701 */
702 XMC_MATH_Q0_23_t XMC_MATH_CORDIC_ArcTan(XMC_MATH_Q8_15_t x, XMC_MATH_Q8_15_t y);
703
704 /**
705 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
706 *
707 * @return XMC_MATH_Q1_22_t <BR>
708 *
709 * \par<b>Description:</b><br>
710 * Computes the hyperbolic cosine for an angle in radians \e angle_in_radians.
711 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
712 *
713 * \par
714 * This function programs CORDIC to rotation & hyperbolic mode.
715 * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register
with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22.
716 * Most significant 24 bits of \a CORRX register returns the result of the operation.
717 *
718 * \par<b>Note:</b><br>
719 * Loading of \a CORDX register triggers the start of computation.
720 *
721 * \par<b>Related APIs:</b><BR>
722 * XMC_MATH_CORDIC_Sinh(), XMC_MATH_CORDIC_Tanh()\n\n\n
723 *
724 */
725 XMC_MATH_Q1_22_t XMC_MATH_CORDIC_Cosh(XMC_MATH_Q0_23_t angle_in_radians);
726
727 /**
728 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
729 *
730 * @return XMC_MATH_Q1_22_t <BR>
731 *
732 * \par<b>Description:</b><br>
733 * Computes the hyperbolic sine for an angle in radians \e angle_in_radians.
734 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
735 *
736 * \par
737 * This function programs CORDIC to rotation & hyperbolic mode.
738 * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register
with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22.
739 * Most significant 24 bits of \a CORRY register returns the result of the operation.
740 *
741 * \par<b>Note:</b><br>
742 * Loading of \a CORDX register triggers the start of computation.
743 *
744 * \par<b>Related APIs:</b><BR>
745 * XMC_MATH_CORDIC_Cosh(), XMC_MATH_CORDIC_Tanh()\n\n\n
746 *
747 */
748 XMC_MATH_Q1_22_t XMC_MATH_CORDIC_Sinh(XMC_MATH_Q0_23_t angle_in_radians);
749
750 /**
751 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
752 *
753 * @return XMC_MATH_Q0_11_t <BR>
754 *
755 * \par<b>Description:</b><br>
756 * Computes the hyperbolic tangent for an angle in radians \e angle_in_radians.
757 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
758 *
759 * \par
760 * This function programs CORDIC to rotation & hyperbolic mode.
761 * Chains the results of Cosine (\a CORRX) and Sine (\a CORRY) as a dividend and
divisor by configuring \a GLBCON register.
762 * \a CORDZ register is programmed with input \a angle_in_radians and \a CORDX
register with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22.
763 * \a QUOT register returns the result of the operation.
764 *
765 * \par<b>Note:</b><br>
766 * Loading of \a CORDX register triggers the start of computation.
767 *
768 * \par<b>Related APIs:</b><BR>
769 * XMC_MATH_CORDIC_Sinh(), XMC_MATH_CORDIC_Cosh()()\n\n\n
770 *
771 */
772 XMC_MATH_Q0_11_t XMC_MATH_CORDIC_Tanh(XMC_MATH_Q0_23_t angle_in_radians);
773
774 /*************************************************************************************
**********************************
775 * API Prototypes - Non blocking functions
776
*************************************************************************************
*********************************/
777 /**
778 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
779 *
780 * @return None <BR>
781 *
782 * \par<b>Description:</b><br>
783 * Computes the cosine for an angle in radians \e angle_in_radians.
784 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
785 * Call XMC_MATH_CORDIC_GetCosResult() API to get the result.
786 *
787 * \par
788 * This function programs CORDIC to rotation & circular mode.
789 * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register
with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023.
790 *
791 * \par<b>Note:</b><br>
792 * Loading of \a CORDX register triggers the start of computation.
793 *
794 * \par<b>Related APIs:</b><BR>
795 * XMC_MATH_CORDIC_GetCosResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(),
XMC_MATH_ClearEvent()\n\n\n
796 *
797 */
798 void XMC_MATH_CORDIC_CosNB(XMC_MATH_Q0_23_t angle_in_radians);
799
800 /**
801 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
802 *
803 * @return None <BR>
804 *
805 * \par<b>Description:</b><br>
806 * Computes the sine for an angle in radians \e angle_in_radians.
807 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
808 * Call XMC_MATH_CORDIC_GetSinResult() API to get the result.
809 *
810 * \par
811 * This function programs CORDIC to rotation & circular mode.
812 * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register
with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023.
813 *
814 * \par<b>Note:</b><br>
815 * Loading of \a CORDX register triggers the start of computation.
816 *
817 * \par<b>Related APIs:</b><BR>
818 * XMC_MATH_CORDIC_GetSinResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(),
XMC_MATH_ClearEvent()\n\n\n
819 *
820 */
821 void XMC_MATH_CORDIC_SinNB(XMC_MATH_Q0_23_t angle_in_radians);
822
823 /**
824 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
825 *
826 * @return None <BR>
827 *
828 * \par<b>Description:</b><br>
829 * Computes the tangent for an angle in radians \e angle_in_radians.
830 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
831 * Call XMC_MATH_CORDIC_GetTanResult() API to get the result.
832 *
833 * \par
834 * This function programs CORDIC to rotation & circular mode.
835 * Chains the results of Cosine (\a CORRX) and Sine (\a CORRY) as a dividend and
divisor by configuring \a GLBCON register.
836 * \a CORDZ register is programmed with input \a angle_in_radians and \a CORDX
register with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023.
837 *
838 * \par<b>Note:</b><br>
839 * Loading of \a CORDX register triggers the start of computation.
840 *
841 * \par<b>Related APIs:</b><BR>
842 * XMC_MATH_CORDIC_GetTanResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(),
XMC_MATH_ClearEvent()\n\n\n
843 *
844 */
845 void XMC_MATH_CORDIC_TanNB(XMC_MATH_Q0_23_t angle_in_radians);
846
847 /**
848 *
849 * @param x Value representing the proportion of the x-coordinate (XMC_MATH_Q8_15_t
format)
850 * @param y Value representing the proportion of the y-coordinate (XMC_MATH_Q8_15_t
format)
851 *
852 * @return None <BR>
853 *
854 * \par<b>Description:</b><br>
855 * Computes the principal value arc tangent of an angle of y/x expressed in radians.
856 * The input radians must be in XMC_MATH_Q8_15_t format.
857 * Call XMC_MATH_CORDIC_GetArcTanResult() API to get the result.
858 *
859 * \par
860 * This function programs CORDIC as circular mode.
861 * \a CORDY register is programmed with input \a y and \a CORDX register is
programmed with input \a x.
862 *
863 * \par<b>Note:</b><br>
864 * Loading of \a CORDX register triggers the start of computation.
865 *
866 * \par<b>Related APIs:</b><BR>
867 * XMC_MATH_CORDIC_GetArcTanResult(), XMC_MATH_EnableEvent(),
XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n
868 *
869 */
870 void XMC_MATH_CORDIC_ArcTanNB(XMC_MATH_Q8_15_t x, XMC_MATH_Q8_15_t y);
871
872 /**
873 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
874 *
875 * @return None <BR>
876 *
877 * \par<b>Description:</b><br>
878 * Computes the hyperbolic cosine for an angle in radians \e angle_in_radians.
879 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
880 * Call XMC_MATH_CORDIC_GetCoshResult() API to get the result.
881 *
882 * \par
883 * This function programs CORDIC to rotation & hyperbolic mode.
884 * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register
with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22.
885 *
886 * \par<b>Note:</b><br>
887 * Loading of \a CORDX register triggers the start of computation.
888 *
889 * \par<b>Related APIs:</b><BR>
890 * XMC_MATH_CORDIC_GetCoshResult(), XMC_MATH_EnableEvent(),
XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n
891 *
892 */
893 void XMC_MATH_CORDIC_CoshNB(XMC_MATH_Q0_23_t angle_in_radians);
894
895 /**
896 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
897 *
898 * @return None <BR>
899 *
900 * \par<b>Description:</b><br>
901 * Computes the hyperbolic sine for an angle in radians \e angle_in_radians.
902 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
903 * Call XMC_MATH_CORDIC_GetSinhResult() API to get the result.
904 *
905 * \par
906 * This function programs CORDIC to rotation & hyperbolic mode.
907 * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register
with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22.
908 *
909 * \par<b>Note:</b><br>
910 * Loading of \a CORDX register triggers the start of computation.
911 *
912 * \par<b>Related APIs:</b><BR>
913 * XMC_MATH_CORDIC_GetSinhResult(), XMC_MATH_EnableEvent(),
XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n
914 *
915 */
916 void XMC_MATH_CORDIC_SinhNB(XMC_MATH_Q0_23_t angle_in_radians);
917
918 /**
919 * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format)
920 *
921 * @return None <BR>
922 *
923 * \par<b>Description:</b><br>
924 * Computes the hyperbolic tangent for an angle in radians \e angle_in_radians.
925 * The input angle in radians must be in XMC_MATH_Q0_23_t format.
926 * Call XMC_MATH_CORDIC_GetTanhResult() API to get the result.
927 *
928 * \par
929 * This function programs CORDIC to rotation & hyperbolic mode.
930 * Chains the results of Cosine (\a CORRX) and Sine (\a CORRY) as a dividend and
divisor by configuring \a GLBCON register.
931 * \a CORDZ register is programmed with input \a angle_in_radians and \a CORDX
register with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22.
932 *
933 * \par<b>Note:</b><br>
934 * Loading of \a CORDX register triggers the start of computation.
935 *
936 * \par<b>Related APIs:</b><BR>
937 * XMC_MATH_CORDIC_GetTanhResult(), XMC_MATH_EnableEvent(),
XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n
938 *
939 */
940 void XMC_MATH_CORDIC_TanhNB(XMC_MATH_Q0_23_t angle_in_radians);
941
942 /**
943 * @param dividend - Dividend
944 * @param divisor - Divisor
945 *
946 * @return None <BR>
947 *
948 * \par<b>Description:</b><br>
949 * Performs unsigned integer division and computes quotient of the division.
950 * Call XMC_MATH_DIV_GetUnsignedDivResult() API to get the result.
951 *
952 * \par
953 * Divider unit is configured for unsigned division.
954 * \a DVD & \a DVS registers are programmed with \a dividend and \a divisor values.
955 * The division is started with the write to DVS register.
956 *
957 * \par<b>Note:</b><br>
958 * Ensure \e divisor is smaller than \e dividend.
959 *
960 * \par<b>Related APIs:</b><BR>
961 * XMC_MATH_DIV_GetUnsignedDivResult(), XMC_MATH_EnableEvent(),
XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n
962 *
963 */
964 void XMC_MATH_DIV_UnsignedDivNB(uint32_t dividend, uint32_t divisor);
965
966 /**
967 * @param dividend - Dividend
968 * @param divisor - Divisor
969 *
970 * @return None <BR>
971 *
972 * \par<b>Description:</b><br>
973 * Performs signed integer division and computes quotient of the division.
974 * Call XMC_MATH_DIV_GetSignedDivResult() API to get the result.
975 *
976 * \par
977 * Divider unit is configured for signed division.
978 * \a DVD & \a DVS registers are programmed with \a dividend and \a divisor values.
979 * The division is started with the write to DVS register.
980 *
981 * \par<b>Note:</b><br>
982 * Ensure \e divisor is smaller than \e dividend.
983 *
984 * \par<b>Related APIs:</b><BR>
985 * XMC_MATH_DIV_GetSignedDivResult(), XMC_MATH_EnableEvent(),
XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n
986 *
987 */
988 void XMC_MATH_DIV_SignedDivNB(int32_t dividend, int32_t divisor);
989
990 /**
991 * @param dividend - Dividend
992 * @param divisor - Divisor
993 *
994 * @return None <BR>
995 *
996 * \par<b>Description:</b><br>
997 * Performs unsigned modulo operation and computes remainder of the division.
998 * Call XMC_MATH_DIV_GetUnsignedModResult() API to get the result.
999 *
1000 * \par
1001 * Divider unit is configured for unsigned division.
1002 * \a DVD & \a DVS registers are programmed with \a dividend and \a divisor values.
1003 * The division is started with the write to DVS register.
1004 *
1005 * \par<b>Note:</b><br>
1006 * Ensure \e divisor is smaller than \e dividend.
1007 *
1008 * \par<b>Related APIs:</b><BR>
1009 * XMC_MATH_DIV_GetUnsignedModResult(), XMC_MATH_EnableEvent(),
XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n
1010 *
1011 */
1012 void XMC_MATH_DIV_UnsignedModNB(uint32_t dividend, uint32_t divisor);
1013
1014 /**
1015 * @param dividend - Dividend
1016 * @param divisor - Divisor
1017 *
1018 * @return None <BR>
1019 *
1020 * \par<b>Description:</b><br>
1021 * Performs signed modulo operation and computes remainder of the division.
1022 * Call XMC_MATH_DIV_GetSignedModResult() API to get the result.
1023 *
1024 * \par
1025 * Divider unit is configured for signed division.
1026 * \a DVD & \a DVS registers are programmed with \a dividend and \a divisor values.
1027 * The division is started with the write to DVS register.
1028 *
1029 * \par<b>Note:</b><br>
1030 * Ensure \e divisor is smaller than \e dividend.
1031 *
1032 * \par<b>Related APIs:</b><BR>
1033 * XMC_MATH_DIV_GetSignedModResult(), XMC_MATH_EnableEvent(),
XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n
1034 *
1035 */
1036 void XMC_MATH_DIV_SignedModNB(int32_t dividend, int32_t divisor);
1037
1038 /**
1039 * @}
1040 */
1041
1042 /**
1043 * @}
1044 */
1045
1046 #endif /* end of #if defined(MATH) */
1047
1048 #ifdef __cplusplus
1049 }
1050 #endif
1051
1052 #endif /* XMC_MATH_H */