1 /*
2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef RENESAS_TFU
8 #define RENESAS_TFU
9
10 /***********************************************************************************************************************
11 * Includes <System Includes> , "Project Includes"
12 **********************************************************************************************************************/
13
14 /* Mathematical Functions includes. */
15 #ifdef __cplusplus
16 #include <cmath>
17 #else
18 #include <math.h>
19 #endif
20
21 /** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
22 FSP_HEADER
23
24 /*******************************************************************************************************************//**
25 * @addtogroup BSP_MCU
26 * @{
27 **********************************************************************************************************************/
28
29 /***********************************************************************************************************************
30 * Macro definitions
31 **********************************************************************************************************************/
32
33 #define R_TFU_HYPOT_SCALING_FACTOR 0.607252935F
34 #define R_TFU_HYPOT_SCALING_FACTOR_FIXED 326016448
35 #define FIXED_POINT_FRACTIONAL_BITS 29U
36
37 #ifdef __GNUC__ /* and (arm)clang */
38 #if (__STDC_VERSION__ < 199901L) && defined(__STRICT_ANSI__) && !defined(__cplusplus)
39
40 /* No form of inline is available, it happens only when -std=c89, gnu89 and
41 * above are OK */
42 #warning \
43 "-std=c89 doesn't support type checking on TFU. Please use -std=gnu89 or higher for example -std=c99"
44 #else
45 #ifdef __GNUC_GNU_INLINE__
46
47 /* gnu89 semantics of inline and extern inline are essentially the exact
48 * opposite of those in C99 */
49 #define BSP_TFU_INLINE extern inline __attribute__((always_inline))
50 #else /* __GNUC_STDC_INLINE__ */
51 #define BSP_TFU_INLINE static inline __attribute__((always_inline))
52 #endif
53 #endif
54 #elif __ICCARM__
55 #define BSP_TFU_INLINE
56 #else
57 #error "Compiler not supported!"
58 #endif
59
60 #if BSP_CFG_USE_TFU_MATHLIB
61 #define sinf(x) __sinf(x)
62 #define cosf(x) __cosf(x)
63 #define atan2f(y, x) __atan2f(y, x)
64 #define hypotf(x, y) __hypotf(x, y)
65 #define atan2hypotf(y, x, a, h) __atan2hypotf(y, x, a, h)
66 #define sincosf(a, s, c) __sincosf(a, s, c)
67 #define sinfx(x) __sinfx(x)
68 #define cosfx(x) __cosfx(x)
69 #define atan2fx(y, x) __atan2fx(y, x)
70 #define hypotfx(x, y) __hypotfx(x, y)
71 #define atan2hypotfx(y, x, a, h) __atan2hypotfx(y, x, a, h)
72 #define sincosfx(a, s, c) __sincosfx(a, s, c)
73 #endif
74
75 #if BSP_CFG_TFU_DATA_SAVE_RESTORE_ENABLE
76 #define BSP_CFG_TFU_SAVE_ENABLE BSP_TFU_SAVE_ENABLE
77 #define BSP_CFG_TFU_RESTORE_ENABLE BSP_TFU_RESTORE_ENABLE
78 #else
79 #define BSP_CFG_TFU_SAVE_ENABLE
80 #define BSP_CFG_TFU_RESTORE_ENABLE
81 #endif
82
83 #if 2 == BSP_FEATURE_TFU_VERSION
84 #if (1 == BSP_FEATURE_TFU_UNIT)
85 #define BSP_TFU_DTSR0_ADDRESS (&R_TFU->DTSR0)
86 #define BSP_TFU_DTSR1_ADDRESS (&R_TFU->DTSR1)
87 #else
88 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
89 #define BSP_TFU_DTSR0_ADDRESS (&R_TFU0->DTSR0)
90 #define BSP_TFU_DTSR1_ADDRESS (&R_TFU0->DTSR1)
91 #else
92 #define BSP_TFU_DTSR0_ADDRESS (&R_TFU1->DTSR0)
93 #define BSP_TFU_DTSR1_ADDRESS (&R_TFU1->DTSR1)
94 #endif
95 #endif
96
97 #define BSP_TFU_SAVE_ENABLE uint32_t dtsr0 = *(volatile uint32_t *) BSP_TFU_DTSR0_ADDRESS; \
98 uint32_t dtsr1 = *(volatile uint32_t *) BSP_TFU_DTSR1_ADDRESS; \
99 __asm volatile ( \
100 "PUSH {%[DTSR0]} \n" \
101 "PUSH {%[DTSR1]} \n" \
102 ::[DTSR0] "r" (dtsr0), [DTSR1] "r" (dtsr1) : "memory");
103
104 #define BSP_TFU_RESTORE_ENABLE __asm volatile ( \
105 "POP {%[DTSR1]} \n" \
106 "POP {%[DTSR0]} \n" \
107 :[DTSR1] "=r" (dtsr1), [DTSR0] "=r" (dtsr0)::"memory"); \
108 *(volatile uint32_t *) BSP_TFU_DTSR0_ADDRESS = dtsr0; \
109 *(volatile uint32_t *) BSP_TFU_DTSR1_ADDRESS = dtsr1;
110 #endif
111
112 /***********************************************************************************************************************
113 * Typedef definitions
114 **********************************************************************************************************************/
115
116 /***********************************************************************************************************************
117 * Exported global variables
118 **********************************************************************************************************************/
119 #if (1 == BSP_LP64_SUPPORT)
120 extern float g_bsp_tfu_convert_result;
121 #endif
122
123 /***********************************************************************************************************************
124 * Exported global functions (to be accessed by other files)
125 **********************************************************************************************************************/
126
127 /***********************************************************************************************************************
128 * Inline Functions
129 **********************************************************************************************************************/
130
131 #if (1 == BSP_LP64_SUPPORT)
132
133 /*******************************************************************************************************************//**
134 * Convert unsigned int type to float type.
135 * @param[in] target_value Value before conversion.
136 *
137 * @retval Value after conversion.
138 **********************************************************************************************************************/
139 #if __ICCARM__
140 #pragma inline = forced
141 #endif
bsp_prv_conversion_uint_to_float(uint32_t target_value)142 BSP_TFU_INLINE float bsp_prv_conversion_uint_to_float (uint32_t target_value)
143 {
144 __asm volatile (
145 "ADR x9, g_bsp_tfu_convert_result \n"
146 "MOV x10, %0 \n"
147 "FMOV s0, w10 \n"
148 "STR s0, [x9] \n"
149 ::"r" (target_value) : "memory");
150
151 return g_bsp_tfu_convert_result;
152 }
153
154 #endif
155
156 #if 1 == BSP_FEATURE_TFU_VERSION
157
158 /*******************************************************************************************************************//**
159 * Calculates sine of the given angle.
160 * @param[in] angle The value of an angle in radian.
161 *
162 * @retval Sine value of an angle.
163 **********************************************************************************************************************/
164 #if __ICCARM__
165 #pragma inline = forced
166 #endif
__sinf(float angle)167 BSP_TFU_INLINE float __sinf (float angle)
168 {
169 /* Set the angle to R_TFU->SCDT1 */
170 R_TFU->SCDT1 = angle;
171
172 /* Read sin from R_TFU->SCDT1 */
173 return R_TFU->SCDT1;
174 }
175
176 /*******************************************************************************************************************//**
177 * Calculates cosine of the given angle.
178 * @param[in] angle The value of an angle in radian.
179 *
180 * @retval Cosine value of an angle.
181 **********************************************************************************************************************/
182 #if __ICCARM__
183 #pragma inline = forced
184 #endif
__cosf(float angle)185 BSP_TFU_INLINE float __cosf (float angle)
186 {
187 /* Set the angle to R_TFU->SCDT1 */
188 R_TFU->SCDT1 = angle;
189
190 /* Read cos from R_TFU->SCDT1 */
191 return R_TFU->SCDT0;
192 }
193
194 /*******************************************************************************************************************//**
195 * Calculates sine and cosine of the given angle.
196 * @param[in] angle The value of an angle in radian.
197 * @param[out] sin Sine value of an angle.
198 * @param[out] cos Cosine value of an angle.
199 **********************************************************************************************************************/
200 #if __ICCARM__
201 #pragma inline = forced
202 #endif
__sincosf(float angle,float * sin,float * cos)203 BSP_TFU_INLINE void __sincosf (float angle, float * sin, float * cos)
204 {
205 /* Set the angle to R_TFU->SCDT1 */
206 R_TFU->SCDT1 = angle;
207
208 /* Read sin from R_TFU->SCDT1 */
209 *sin = R_TFU->SCDT1;
210
211 /* Read cos from R_TFU->SCDT0 */
212 *cos = R_TFU->SCDT0;
213 }
214
215 /*******************************************************************************************************************//**
216 * Calculates the arc tangent based on given X-cordinate and Y-cordinate values.
217 * @param[in] y_cord Y-Axis cordinate value.
218 * @param[in] x_cord X-Axis cordinate value.
219 *
220 * @retval Arc tangent for given values.
221 **********************************************************************************************************************/
222 #if __ICCARM__
223 #pragma inline = forced
224 #endif
__atan2f(float y_cord,float x_cord)225 BSP_TFU_INLINE float __atan2f (float y_cord, float x_cord)
226 {
227 /* Set X-cordinate to R_TFU->ATDT0 */
228 R_TFU->ATDT0 = x_cord;
229
230 /* set Y-cordinate to R_TFU->ATDT1 */
231 R_TFU->ATDT1 = y_cord;
232
233 /* Read arctan(y/x) from R_TFU->ATDT1 */
234 return R_TFU->ATDT1;
235 }
236
237 /*******************************************************************************************************************//**
238 * Calculates the hypotenuse based on given X-cordinate and Y-cordinate values.
239 * @param[in] y_cord Y-cordinate value.
240 * @param[in] x_cord X-cordinate value.
241 *
242 * @retval Hypotenuse for given values.
243 **********************************************************************************************************************/
244 #if __ICCARM__
245 #pragma inline = forced
246 #endif
__hypotf(float x_cord,float y_cord)247 BSP_TFU_INLINE float __hypotf (float x_cord, float y_cord)
248 {
249 /* Set X-coordinate to R_TFU->ATDT0 */
250 R_TFU->ATDT0 = x_cord;
251
252 /* set Y-coordinate to R_TFU->ATDT1 */
253 R_TFU->ATDT1 = y_cord;
254
255 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->ATDT0 */
256 return R_TFU->ATDT0 * R_TFU_HYPOT_SCALING_FACTOR;
257 }
258
259 /*******************************************************************************************************************//**
260 * Calculates the arc tangent and hypotenuse based on given X-cordinate and Y-cordinate values.
261 * @param[in] y_cord Y-cordinate value.
262 * @param[in] x_cord X-cordinate value.
263 * @param[out] atan2 Arc tangent for given values.
264 * @param[out] hypot Hypotenuse for given values.
265 **********************************************************************************************************************/
266 #if __ICCARM__
267 #pragma inline = forced
268 #endif
__atan2hypotf(float y_cord,float x_cord,float * atan2,float * hypot)269 BSP_TFU_INLINE void __atan2hypotf (float y_cord, float x_cord, float * atan2, float * hypot)
270 {
271 /* Set X-coordinate to R_TFU->ATDT0 */
272 R_TFU->ATDT0 = x_cord;
273
274 /* set Y-coordinate to R_TFU->ATDT1 */
275 R_TFU->ATDT1 = y_cord;
276
277 /* Read arctan(y/x) from R_TFU->ATDT1 */
278 *atan2 = R_TFU->ATDT1;
279
280 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->ATDT0 */
281 *hypot = R_TFU->ATDT0 * R_TFU_HYPOT_SCALING_FACTOR;
282 }
283
284 #else
285
286 /*******************************************************************************************************************//**
287 * Calculates sine of the given angle.
288 * @param[in] angle The value of an angle in radian.
289 *
290 * @retval Sine value of an angle.
291 **********************************************************************************************************************/
292 #if __ICCARM__
293 #pragma inline = forced
294 #endif
__sinf(float angle)295 BSP_TFU_INLINE float __sinf (float angle)
296 {
297 #if (1 == BSP_FEATURE_TFU_UNIT)
298
299 /* Set the angle to R_TFU->FPSCDT1 */
300 R_TFU->FPSCDT1 = angle;
301
302 /* Read sin from R_TFU->FPSCDT1 */
303 return R_TFU->FPSCDT1;
304 #else
305 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
306
307 /* Set the angle to R_TFU->FPSCDT1 */
308 R_TFU0->FPSCDT1 = angle;
309
310 /* Read sin from R_TFU->FPSCDT1 */
311 return R_TFU0->FPSCDT1;
312 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
313
314 /* Set the angle to R_TFU->FPSCDT1 */
315 R_TFU1->FPSCDT1 = angle;
316
317 /* Read sin from R_TFU->FPSCDT1 */
318 return R_TFU1->FPSCDT1;
319 #endif
320 #endif
321 }
322
323 /*******************************************************************************************************************//**
324 * Calculates cosine of the given angle.
325 * @param[in] angle The value of an angle in radian.
326 *
327 * @retval Cosine value of an angle.
328 **********************************************************************************************************************/
329 #if __ICCARM__
330 #pragma inline = forced
331 #endif
__cosf(float angle)332 BSP_TFU_INLINE float __cosf (float angle)
333 {
334 #if (1 == BSP_FEATURE_TFU_UNIT)
335
336 /* Set the angle to R_TFU->FPSCDT1 */
337 R_TFU->FPSCDT1 = angle;
338
339 /* Read cos from R_TFU->FPSCDT0 */
340 return R_TFU->FPSCDT0;
341 #else
342 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
343
344 /* Set the angle to R_TFU->FPSCDT1 */
345 R_TFU0->FPSCDT1 = angle;
346
347 /* Read cos from R_TFU->FPSCDT0 */
348 return R_TFU0->FPSCDT0;
349 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
350
351 /* Set the angle to R_TFU->FPSCDT1 */
352 R_TFU1->FPSCDT1 = angle;
353
354 /* Read cos from R_TFU->FPSCDT0 */
355 return R_TFU1->FPSCDT0;
356 #endif
357 #endif
358 }
359
360 /*******************************************************************************************************************//**
361 * Calculates sine and cosine of the given angle.
362 * @param[in] angle The value of an angle in radian.
363 * @param[out] sin Sine value of an angle.
364 * @param[out] cos Cosine value of an angle.
365 **********************************************************************************************************************/
366 #if __ICCARM__
367 #pragma inline = forced
368 #endif
__sincosf(float angle,float * sin,float * cos)369 BSP_TFU_INLINE void __sincosf (float angle, float * sin, float * cos)
370 {
371 #if (1 == BSP_FEATURE_TFU_UNIT)
372
373 /* Set the angle to R_TFU->FPSCDT1 */
374 R_TFU->FPSCDT1 = angle;
375
376 /* Read sin from R_TFU->FPSCDT1 */
377 *sin = R_TFU->FPSCDT1;
378
379 /* Read sin from R_TFU->FPSCDT0 */
380 *cos = R_TFU->FPSCDT0;
381 #else
382 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
383
384 /* Set the angle to R_TFU->FPSCDT1 */
385 R_TFU0->FPSCDT1 = angle;
386
387 /* Read sin from R_TFU->FPSCDT1 */
388 *sin = R_TFU0->FPSCDT1;
389
390 /* Read sin from R_TFU->FPSCDT0 */
391 *cos = R_TFU0->FPSCDT0;
392 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
393
394 /* Set the angle to R_TFU->FPSCDT1 */
395 R_TFU1->FPSCDT1 = angle;
396
397 /* Read sin from R_TFU->FPSCDT1 */
398 *sin = R_TFU1->FPSCDT1;
399
400 /* Read sin from R_TFU->FPSCDT0 */
401 *cos = R_TFU1->FPSCDT0;
402 #endif
403 #endif
404 }
405
406 /*******************************************************************************************************************//**
407 * Calculates the arc tangent based on given X-cordinate and Y-cordinate values.
408 * @param[in] y_cord Y-Axis cordinate value.
409 * @param[in] x_cord X-Axis cordinate value.
410 *
411 * @retval Arc tangent for given values.
412 **********************************************************************************************************************/
413 #if __ICCARM__
414 #pragma inline = forced
415 #endif
__atan2f(float y_cord,float x_cord)416 BSP_TFU_INLINE float __atan2f (float y_cord, float x_cord)
417 {
418 #if (1 == BSP_FEATURE_TFU_UNIT)
419
420 /* Set X-cordinate to R_TFU->FPATDT0 */
421 R_TFU->FPATDT0 = x_cord;
422
423 /* set Y-cordinate to R_TFU->FPATDT1 */
424 R_TFU->FPATDT1 = y_cord;
425
426 /* Read arctan(y/x) from R_TFU->FPATDT1 */
427 return R_TFU->FPATDT1;
428 #else
429 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
430
431 /* Set X-cordinate to R_TFU->FPATDT0 */
432 R_TFU0->FPATDT0 = x_cord;
433
434 /* set Y-cordinate to R_TFU->FPATDT1 */
435 R_TFU0->FPATDT1 = y_cord;
436
437 /* Read arctan(y/x) from R_TFU->FPATDT1 */
438 return R_TFU0->FPATDT1;
439 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
440
441 /* Set X-cordinate to R_TFU->FPATDT0 */
442 R_TFU1->FPATDT0 = x_cord;
443
444 /* set Y-cordinate to R_TFU->FPATDT1 */
445 R_TFU1->FPATDT1 = y_cord;
446
447 /* Read arctan(y/x) from R_TFU->FPATDT1 */
448 return R_TFU1->FPATDT1;
449 #endif
450 #endif
451 }
452
453 /*******************************************************************************************************************//**
454 * Calculates the hypotenuse based on given X-cordinate and Y-cordinate values.
455 * @param[in] y_cord Y-cordinate value.
456 * @param[in] x_cord X-cordinate value.
457 *
458 * @retval Hypotenuse for given values.
459 **********************************************************************************************************************/
460 #if __ICCARM__
461 #pragma inline = forced
462 #endif
__hypotf(float x_cord,float y_cord)463 BSP_TFU_INLINE float __hypotf (float x_cord, float y_cord)
464 {
465 #if (1 == BSP_FEATURE_TFU_UNIT)
466
467 /* Set X-coordinate to R_TFU->FPATDT0 */
468 R_TFU->FPATDT0 = x_cord;
469
470 /* set Y-coordinate to R_TFU->FPATDT1 */
471 R_TFU->FPATDT1 = y_cord;
472
473 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FPATDT0 */
474 return R_TFU->FPATDT0 * R_TFU_HYPOT_SCALING_FACTOR;
475 #else
476 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
477
478 /* Set X-coordinate to R_TFU->FPATDT0 */
479 R_TFU0->FPATDT0 = x_cord;
480
481 /* set Y-coordinate to R_TFU->FPATDT1 */
482 R_TFU0->FPATDT1 = y_cord;
483
484 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FPATDT0 */
485 return R_TFU0->FPATDT0 * R_TFU_HYPOT_SCALING_FACTOR;
486 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
487
488 /* Set X-coordinate to R_TFU->FPATDT0 */
489 R_TFU1->FPATDT0 = x_cord;
490
491 /* set Y-coordinate to R_TFU->FPATDT1 */
492 R_TFU1->FPATDT1 = y_cord;
493
494 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FPATDT0 */
495 return R_TFU1->FPATDT0 * R_TFU_HYPOT_SCALING_FACTOR;
496 #endif
497 #endif
498 }
499
500 /*******************************************************************************************************************//**
501 * Calculates the arc tangent and hypotenuse based on given X-cordinate and Y-cordinate values.
502 * @param[in] y_cord Y-cordinate value.
503 * @param[in] x_cord X-cordinate value.
504 * @param[out] atan2 Arc tangent for given values.
505 * @param[out] hypot Hypotenuse for given values.
506 **********************************************************************************************************************/
507 #if __ICCARM__
508 #pragma inline = forced
509 #endif
__atan2hypotf(float y_cord,float x_cord,float * atan2,float * hypot)510 BSP_TFU_INLINE void __atan2hypotf (float y_cord, float x_cord, float * atan2, float * hypot)
511 {
512 #if (1 == BSP_FEATURE_TFU_UNIT)
513
514 /* Set X-coordinate to R_TFU->FPATDT0 */
515 R_TFU->FPATDT0 = x_cord;
516
517 /* set Y-coordinate to R_TFU->FPATDT1 */
518 R_TFU->FPATDT1 = y_cord;
519
520 /* Read arctan(y/x) from R_TFU->FPATDT1 */
521 *atan2 = R_TFU->FPATDT1;
522
523 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FPATDT0 */
524 *hypot = R_TFU->FPATDT0 * R_TFU_HYPOT_SCALING_FACTOR;
525 #else
526 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
527
528 /* Set X-coordinate to R_TFU->FPATDT0 */
529 R_TFU0->FPATDT0 = x_cord;
530
531 /* set Y-coordinate to R_TFU->FPATDT1 */
532 R_TFU0->FPATDT1 = y_cord;
533
534 /* Read arctan(y/x) from R_TFU->FPATDT1 */
535 *atan2 = R_TFU0->FPATDT1;
536
537 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FPATDT0 */
538 *hypot = R_TFU0->FPATDT0 * R_TFU_HYPOT_SCALING_FACTOR;
539 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
540
541 /* Set X-coordinate to R_TFU->FPATDT0 */
542 R_TFU1->FPATDT0 = x_cord;
543
544 /* set Y-coordinate to R_TFU->FPATDT1 */
545 R_TFU1->FPATDT1 = y_cord;
546
547 /* Read arctan(y/x) from R_TFU->FPATDT1 */
548 *atan2 = R_TFU1->FPATDT1;
549
550 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FPATDT0 */
551 *hypot = R_TFU1->FPATDT0 * R_TFU_HYPOT_SCALING_FACTOR;
552 #endif
553 #endif
554 }
555
556 /*******************************************************************************************************************//**
557 * Calculates sine of the given angle.
558 * @param[in] angle The value of an angle.
559 *
560 * @retval Sine value of an angle.
561 **********************************************************************************************************************/
562 #if __ICCARM__
563 #pragma inline = forced
564 #endif
__sinfx(uint32_t angle)565 BSP_TFU_INLINE uint32_t __sinfx (uint32_t angle)
566 {
567 #if (1 == BSP_FEATURE_TFU_UNIT)
568
569 /* Set the angle to R_TFU->FXSCDT1 */
570 R_TFU->FXSCDT1 = angle;
571
572 /* Read sin from R_TFU->FXSCDT1 */
573 return R_TFU->FXSCDT1;
574 #else
575 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
576
577 /* Set the angle to R_TFU->FXSCDT1 */
578 R_TFU0->FXSCDT1 = angle;
579
580 /* Read sin from R_TFU->FXSCDT1 */
581 return R_TFU0->FXSCDT1;
582 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
583
584 /* Set the angle to R_TFU->FXSCDT1 */
585 R_TFU1->FXSCDT1 = angle;
586
587 /* Read sin from R_TFU->FXSCDT1 */
588 return R_TFU1->FXSCDT1;
589 #endif
590 #endif
591 }
592
593 /*******************************************************************************************************************//**
594 * Calculates cosine of the given angle.
595 * @param[in] angle The value of an angle in radian.
596 *
597 * @retval Cosine value of an angle.
598 **********************************************************************************************************************/
599 #if __ICCARM__
600 #pragma inline = forced
601 #endif
__cosfx(uint32_t angle)602 BSP_TFU_INLINE uint32_t __cosfx (uint32_t angle)
603 {
604 #if (1 == BSP_FEATURE_TFU_UNIT)
605
606 /* Set the angle to R_TFU->FXSCDT1 */
607 R_TFU->FXSCDT1 = angle;
608
609 /* Read sin from R_TFU->FXSCDT0 */
610 return R_TFU->FXSCDT0;
611 #else
612 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
613
614 /* Set the angle to R_TFU->FXSCDT1 */
615 R_TFU0->FXSCDT1 = angle;
616
617 /* Read sin from R_TFU->FXSCDT0 */
618 return R_TFU0->FXSCDT0;
619 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
620
621 /* Set the angle to R_TFU->FXSCDT1 */
622 R_TFU1->FXSCDT1 = angle;
623
624 /* Read sin from R_TFU->FXSCDT0 */
625 return R_TFU1->FXSCDT0;
626 #endif
627 #endif
628 }
629
630 /*******************************************************************************************************************//**
631 * Calculates sine and cosine of the given angle.
632 * @param[in] angle The value of an angle.
633 * @param[out] sin Sine value of an angle.
634 * @param[out] cos Cosine value of an angle.
635 **********************************************************************************************************************/
636 #if __ICCARM__
637 #pragma inline = forced
638 #endif
__sincosfx(uint32_t angle,uint32_t * sin,uint32_t * cos)639 BSP_TFU_INLINE void __sincosfx (uint32_t angle, uint32_t * sin, uint32_t * cos)
640 {
641 #if (1 == BSP_FEATURE_TFU_UNIT)
642
643 /* Set the angle to R_TFU->FXSCDT1 */
644 R_TFU->FXSCDT1 = angle;
645
646 /* Read sin from R_TFU->FXSCDT1 */
647 *sin = R_TFU->FXSCDT1;
648
649 /* Read sin from R_TFU->FXSCDT0 */
650 *cos = R_TFU->FXSCDT0;
651 #else
652 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
653
654 /* Set the angle to R_TFU->FXSCDT1 */
655 R_TFU0->FXSCDT1 = angle;
656
657 /* Read sin from R_TFU->FXSCDT1 */
658 *sin = R_TFU0->FXSCDT1;
659
660 /* Read sin from R_TFU->FXSCDT0 */
661 *cos = R_TFU0->FXSCDT0;
662 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
663
664 /* Set the angle to R_TFU->FXSCDT1 */
665 R_TFU1->FXSCDT1 = angle;
666
667 /* Read sin from R_TFU->FXSCDT1 */
668 *sin = R_TFU1->FXSCDT1;
669
670 /* Read sin from R_TFU->FXSCDT0 */
671 *cos = R_TFU1->FXSCDT0;
672 #endif
673 #endif
674 }
675
676 /*******************************************************************************************************************//**
677 * Calculates the arc tangent based on given X-cordinate and Y-cordinate values.
678 * @param[in] y_cord Y-Axis cordinate value.
679 * @param[in] x_cord X-Axis cordinate value.
680 *
681 * @retval Arc tangent for given values.
682 **********************************************************************************************************************/
683 #if __ICCARM__
684 #pragma inline = forced
685 #endif
__atan2fx(uint32_t y_cord,uint32_t x_cord)686 BSP_TFU_INLINE uint32_t __atan2fx (uint32_t y_cord, uint32_t x_cord)
687 {
688 #if (1 == BSP_FEATURE_TFU_UNIT)
689
690 /* Set X-cordinate to R_TFU->FXATDT0 */
691 R_TFU->FXATDT0 = x_cord;
692
693 /* set Y-cordinate to R_TFU->FXATDT1 */
694 R_TFU->FXATDT1 = y_cord;
695
696 /* Read arctan(y/x) from R_TFU->FXATDT1 */
697 return R_TFU->FXATDT1;
698 #else
699 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
700
701 /* Set X-cordinate to R_TFU->FXATDT0 */
702 R_TFU0->FXATDT0 = x_cord;
703
704 /* set Y-cordinate to R_TFU->FXATDT1 */
705 R_TFU0->FXATDT1 = y_cord;
706
707 /* Read arctan(y/x) from R_TFU->FXATDT1 */
708 return R_TFU0->FXATDT1;
709 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
710
711 /* Set X-cordinate to R_TFU->FXATDT0 */
712 R_TFU1->FXATDT0 = x_cord;
713
714 /* set Y-cordinate to R_TFU->FXATDT1 */
715 R_TFU1->FXATDT1 = y_cord;
716
717 /* Read arctan(y/x) from R_TFU->FXATDT1 */
718 return R_TFU1->FXATDT1;
719 #endif
720 #endif
721 }
722
723 /*******************************************************************************************************************//**
724 * Calculates the hypotenuse based on given X-cordinate and Y-cordinate values.
725 * @param[in] y_cord Y-cordinate value.
726 * @param[in] x_cord X-cordinate value.
727 *
728 * @retval Hypotenuse for given values.
729 **********************************************************************************************************************/
730 #if __ICCARM__
731 #pragma inline = forced
732 #endif
__hypotfx(uint32_t x_cord,uint32_t y_cord)733 BSP_TFU_INLINE int32_t __hypotfx (uint32_t x_cord, uint32_t y_cord)
734 {
735 #if (1 == BSP_FEATURE_TFU_UNIT)
736
737 /* Set X-coordinate to R_TFU->FXATDT0 */
738 R_TFU->FXATDT0 = x_cord;
739
740 /* set Y-coordinate to R_TFU->FXATDT1 */
741 R_TFU->FXATDT1 = y_cord;
742
743 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FXATDT0 */
744 int64_t calc_hypotValue = (int64_t) R_TFU->FXATDT0 * R_TFU_HYPOT_SCALING_FACTOR_FIXED;
745 #else
746 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
747
748 /* Set X-coordinate to R_TFU->FXATDT0 */
749 R_TFU0->FXATDT0 = x_cord;
750
751 /* set Y-coordinate to R_TFU->FXATDT1 */
752 R_TFU0->FXATDT1 = y_cord;
753
754 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FXATDT0 */
755 int64_t calc_hypotValue = (int64_t) R_TFU0->FXATDT0 * R_TFU_HYPOT_SCALING_FACTOR_FIXED;
756 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
757
758 /* Set X-coordinate to R_TFU->FXATDT0 */
759 R_TFU1->FXATDT0 = x_cord;
760
761 /* set Y-coordinate to R_TFU->FXATDT1 */
762 R_TFU1->FXATDT1 = y_cord;
763
764 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FXATDT0 */
765 int64_t calc_hypotValue = (int64_t) R_TFU1->FXATDT0 * R_TFU_HYPOT_SCALING_FACTOR_FIXED;
766 #endif
767 #endif
768
769 return (int32_t) (calc_hypotValue >> FIXED_POINT_FRACTIONAL_BITS);
770 }
771
772 /*******************************************************************************************************************//**
773 * Calculates the arc tangent and hypotenuse based on given X-cordinate and Y-cordinate values.
774 * @param[in] y_cord Y-cordinate value.
775 * @param[in] x_cord X-cordinate value.
776 * @param[out] atan2 Arc tangent for given values.
777 * @param[out] hypot Hypotenuse for given values.
778 **********************************************************************************************************************/
779 #if __ICCARM__
780 #pragma inline = forced
781 #endif
__atan2hypotfx(uint32_t y_cord,uint32_t x_cord,uint32_t * atan2,int32_t * hypot)782 BSP_TFU_INLINE void __atan2hypotfx (uint32_t y_cord, uint32_t x_cord, uint32_t * atan2, int32_t * hypot)
783 {
784 #if (1 == BSP_FEATURE_TFU_UNIT)
785
786 /* Set X-coordinate to R_TFU->FXATDT0 */
787 R_TFU->FXATDT0 = x_cord;
788
789 /* set Y-coordinate to R_TFU->FXATDT1 */
790 R_TFU->FXATDT1 = y_cord;
791
792 /* Read arctan(y/x) from R_TFU->FXATDT1 */
793 *atan2 = R_TFU->FXATDT1;
794
795 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FXATDT0 */
796 int64_t calc_hypotValue = (int64_t) R_TFU->FXATDT0 * R_TFU_HYPOT_SCALING_FACTOR_FIXED;
797 #else
798 #if (0 == BSP_FEATURE_TFU_UNIT_NUMBER)
799
800 /* Set X-coordinate to R_TFU->FXATDT0 */
801 R_TFU0->FXATDT0 = x_cord;
802
803 /* set Y-coordinate to R_TFU->FXATDT1 */
804 R_TFU0->FXATDT1 = y_cord;
805
806 /* Read arctan(y/x) from R_TFU->FXATDT1 */
807 *atan2 = R_TFU0->FXATDT1;
808
809 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FXATDT0 */
810 int64_t calc_hypotValue = (int64_t) R_TFU0->FXATDT0 * R_TFU_HYPOT_SCALING_FACTOR_FIXED;
811 #elif (1 == BSP_FEATURE_TFU_UNIT_NUMBER)
812
813 /* Set X-coordinate to R_TFU->FXATDT0 */
814 R_TFU1->FXATDT0 = x_cord;
815
816 /* set Y-coordinate to R_TFU->FXATDT1 */
817 R_TFU1->FXATDT1 = y_cord;
818
819 /* Read arctan(y/x) from R_TFU->FXATDT1 */
820 *atan2 = R_TFU1->FXATDT1;
821
822 /* Read sqrt (x_cord2 + y_cord2) from R_TFU->FXATDT0 */
823 int64_t calc_hypotValue = (int64_t) R_TFU1->FXATDT0 * R_TFU_HYPOT_SCALING_FACTOR_FIXED;
824 #endif
825 #endif
826 *hypot = (int32_t) (calc_hypotValue >> FIXED_POINT_FRACTIONAL_BITS);
827 }
828
829 #endif
830
831 /** @} (end addtogroup BSP_MCU) */
832
833 /** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
834 FSP_FOOTER
835
836 #endif /* RENESAS_TFU */
837