AM263Px MCU+ SDK: ti_tmu_trig.h Source File

| AM263Px MCU+ SDK 26.00.00 |

ti_tmu_trig.h
Go to the documentation of this file.
1 /* Copyright (c) 2023, Texas Instruments Incorporated
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * * Neither the name of Texas Instruments Incorporated nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
30
40 #ifndef TI_TMU_TRIG_H_
41 #define TI_TMU_TRIG_H_
42
43 #include <stdint.h>
44 #include <drivers/hw_include/cslr.h>
45 #include <mathlib/trig/soc/tmu_soc.h>
46 #include <kernel/dpl/DebugP.h>
47 #include <kernel/dpl/ClockP.h>
48 #include <kernel/dpl/HwiP.h>
49
50
51 #ifndef ReciprocalOf2PI
52 #define ReciprocalOf2PI 0.159154943091895335768f
53 #endif
54
55 #ifndef TwoPI
56 #define TwoPI 6.283185307F
57 #endif
58
59 #ifndef Log2ofe
60 #define Log2ofe 1.44269F
61 #endif
62
63 #ifndef OnebyLog2ofe
64 #define OnebyLog2ofe 0.693147F
65 #endif
66
67 #define ISR_TMU_CONTEXT_SAVE HW_WR_REG32((CSL_MSS_TMU_BASE + CSL_TMU_CONTEXT_SAVE), HW_RD_REG32(CSL_MSS_TMU_BASE + CSL_TMU_CONTEXT_SAVE)| (1));
68 #define ISR_TMU_CONTEXT_RESTORE HW_WR_REG32((CSL_MSS_TMU_BASE + CSL_TMU_CONTEXT_RESTORE), HW_RD_REG32(CSL_MSS_TMU_BASE + CSL_TMU_CONTEXT_RESTORE)| (1));
69
70
71 /* ========================================================================== */
72 /* Function Declarations */
73 /* ========================================================================== */
74
86 static inline float ti_tmu_sin_pu(float anglePU)
87 {
88 __asm__ volatile("str %0, [%1]\n\t"
89 "DMB ST \n\t"
90 :
91 : "r" (anglePU), "r" (CSL_MSS_TMU_BASE + CSL_TMU_SINPUF32_R0));
92
93 return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0));
94 }
95
107 static inline float ti_tmu_cos_pu(float anglePU)
108 {
109 __asm__ volatile("str %0, [%1]\n\t"
110 "DMB ST \n\t"
111 :
112 : "r" (anglePU), "r" (CSL_MSS_TMU_BASE + CSL_TMU_COSPUF32_R0));
113
114 return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0));
115 }
116
117
129 static inline float ti_tmu_atan_pu(float x)
130 {
131 __asm__ volatile("str %0, [%1]\n\t"
132 "DMB ST \n\t"
133 :
134 : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_ATANPUF32_R2));
135
136 return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R2));
137
138 }
139
140
141
153 static inline float ti_tmu_log_pu(float x)
154 {
155 __asm__ volatile("str %0, [%1]\n\t"
156 "DMB ST \n\t"
157 :
158 : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_LOG2F32_R3));
159
160 return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R3));
161 }
162
174 static inline float ti_tmu_log_e_pu(float x)
175 {
176 __asm__ volatile("str %0, [%1]\n\t"
177 "DMB ST \n\t"
178 :
179 : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_LOG2F32_R3));
180
181 return (*((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R3))) * OnebyLog2ofe;
182 }
183
184
185
196 static inline float ti_tmu_iexp_pu(float x)
197 {
198 __asm__ volatile("str %0, [%1]\n\t"
199 "DMB ST \n\t"
200 :
201 : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_IEXP2F32_R3));
202
203 return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R3));
204 }
205
216 static inline float ti_tmu_iexp_e_pu(float x)
217 {
218 __asm__ volatile("str %0, [%1]\n\t"
219 "DMB ST \n\t"
220 :
221 : "r" (x * Log2ofe), "r" (CSL_MSS_TMU_BASE + CSL_TMU_IEXP2F32_R3));
222
223 return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R3));
224 }
225
226
227
239 static inline float ti_tmu_sin(float angleRad)
240 {
241 __asm__ volatile("str %0, [%1]\n\t"
242 "DMB ST \n\t"
243 :
244 : "r" (angleRad * ReciprocalOf2PI), "r" (CSL_MSS_TMU_BASE + CSL_TMU_SINPUF32_R0));
245
246 return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0));
247 }
248
249
261 static inline float ti_tmu_cos(float angleRad)
262 {
263 __asm__ volatile("str %0, [%1]\n\t"
264 "DMB ST \n\t"
265 :
266 : "r" (angleRad * ReciprocalOf2PI), "r" (CSL_MSS_TMU_BASE + CSL_TMU_COSPUF32_R1));
267
268 return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1));
269 }
270
282 static inline float ti_tmu_atan(float x)
283 {
284 __asm__ volatile("str %0, [%1]\n\t"
285 "DMB ST \n\t"
286 :
287 : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_ATANPUF32_R2));
288
289 return (*((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R2))) * TwoPI;
290 }
291
292
304 static inline float ti_tmu_atan2(float x, float y)
305 {
306 __asm__ volatile("str %1, [%2, #0x240] \n\t"
307 "str %0, [%2, #0x1F0] \n\t"
308 "DMB ST \n\t"
309 "ldr %0, [%2, #0x2B0] \n\t"
310 "str %0, [%2, #0xC0] \n\t"
311 "DMB ST \n\t"
312 :
313 : "r" (x), "r" (y), "r" (CSL_MSS_TMU_BASE));
314
315 return (TwoPI * ((*(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0)) + (*(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R7))));
316
317 }
318
330 static inline void ti_tmu_sincos_pu(float anglePU, float *sin_val, float *cos_val)
331 {
332 __asm__ volatile("str %0, [%1]\n\t"
333 "str %0, [%2]\n\t"
334 "DMB ST \n\t"
335 ".rept 4 ; nop ; .endr\n\t"
336 :
337 : "r" (anglePU), "r" (CSL_MSS_TMU_BASE + CSL_TMU_SINPUF32_R0), "r" (CSL_MSS_TMU_BASE + CSL_TMU_COSPUF32_R1));
338
339 *sin_val = *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0);
340 *cos_val = *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1);
341 return;
342 }
343
355 static inline void ti_tmu_sincos(float angleRad, float *sin_val, float *cos_val)
356 {
357 __asm__ volatile("str %0, [%1]\n\t"
358 "str %0, [%2]\n\t"
359 "DMB ST \n\t"
360 ".rept 4 ; nop ; .endr\n\t"
361 :
362 : "r" (angleRad * ReciprocalOf2PI), "r" (CSL_MSS_TMU_BASE + CSL_TMU_SINPUF32_R0), "r" (CSL_MSS_TMU_BASE + CSL_TMU_COSPUF32_R1));
363
364 *sin_val = *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0);
365 *cos_val = *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1);
366 return;
367 }
368
381 static inline float ti_tmu_powf(float x, float y)
382 {
383 __asm__ volatile("str %0, [%1, #0x180] \n\t"
384 "DMB ST \n\t"
385 :
386 : "r" (x), "r" (CSL_MSS_TMU_BASE));
387
388 float res = (*(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0)) * y;
389
390 __asm__ volatile("str %0, [%1, #0x148] \n\t"
391 "DMB ST \n\t"
392 :
393 : "r" (res), "r" (CSL_MSS_TMU_BASE));
394
395 return res > 0 ? *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1) : (1.0f / (*(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1)));
396
397 }
398
399
400
401 #endif /* TI_TMU_TRIG_H */
402
ti_tmu_log_pu
static float ti_tmu_log_pu(float x)
Computes the logarithmic value of the input using TMU.
Definition: ti_tmu_trig.h:153
ti_tmu_iexp_pu
static float ti_tmu_iexp_pu(float x)
Computes the inverse exponential value of the input using TMU.
Definition: ti_tmu_trig.h:196
ti_tmu_atan_pu
static float ti_tmu_atan_pu(float x)
Computes the trigonometric atan value of the input using TMU.
Definition: ti_tmu_trig.h:129
ti_tmu_cos_pu
static float ti_tmu_cos_pu(float anglePU)
Computes the trigonometric cosine value of the input angle using TMU.
Definition: ti_tmu_trig.h:107
ti_tmu_powf
static float ti_tmu_powf(float x, float y)
Computes the power of the input value.
Definition: ti_tmu_trig.h:381
ti_tmu_sincos_pu
static void ti_tmu_sincos_pu(float anglePU, float *sin_val, float *cos_val)
Computes the trigonometric sine and cosine value of the input using TMU.
Definition: ti_tmu_trig.h:330
ti_tmu_sincos
static void ti_tmu_sincos(float angleRad, float *sin_val, float *cos_val)
Computes the trigonometric sine and cosine value of the input using TMU.
Definition: ti_tmu_trig.h:355
ClockP.h
ReciprocalOf2PI
#define ReciprocalOf2PI
Definition: ti_tmu_trig.h:52
Log2ofe
#define Log2ofe
Definition: ti_tmu_trig.h:60
ti_tmu_log_e_pu
static float ti_tmu_log_e_pu(float x)
Computes the logarithmic value to the base e of the input using TMU.
Definition: ti_tmu_trig.h:174
HwiP.h
TwoPI
#define TwoPI
Definition: ti_tmu_trig.h:56
ti_tmu_atan
static float ti_tmu_atan(float x)
Computes the trigonometric atan value of the input angle using TMU.
Definition: ti_tmu_trig.h:282
OnebyLog2ofe
#define OnebyLog2ofe
Definition: ti_tmu_trig.h:64
ti_tmu_cos
static float ti_tmu_cos(float angleRad)
Computes the trigonometric cosine value of the input angle using TMU.
Definition: ti_tmu_trig.h:261
DebugP.h
ti_tmu_iexp_e_pu
static float ti_tmu_iexp_e_pu(float x)
Computes the inverse exponential value to the base e of the input using TMU.
Definition: ti_tmu_trig.h:216
ti_tmu_sin_pu
static float ti_tmu_sin_pu(float anglePU)
Computes the trigonometric sine value of the input angle using TMU.
Definition: ti_tmu_trig.h:86
ti_tmu_sin
static float ti_tmu_sin(float angleRad)
Computes the trigonometric sine value of the input angle using TMU.
Definition: ti_tmu_trig.h:239
ti_tmu_atan2
static float ti_tmu_atan2(float x, float y)
Computes the trigonometric atan2 value of the input values using TMU. Uses the quadratic built in TMU...
Definition: ti_tmu_trig.h:304