AM263x MCU+ SDK  09.02.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 <drivers/hw_include/am263px/cslr_tmu.h>
46 #include <drivers/hw_include/am263px/cslr_soc_r5_baseaddress.h>
47 #include <kernel/dpl/DebugP.h>
48 #include <kernel/dpl/ClockP.h>
49 #include <kernel/dpl/HwiP.h>
50 
51 
52 #ifndef ReciprocalOf2PI
53 #define ReciprocalOf2PI 0.159154943091895335768f
54 #endif
55 
56 #ifndef TwoPI
57 #define TwoPI 6.283185307F
58 #endif
59 
60 #ifndef Log2ofe
61 #define Log2ofe 1.44269F
62 #endif
63 
64 #ifndef OnebyLog2ofe
65 #define OnebyLog2ofe 0.693147F
66 #endif
67 
68 #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));
69 #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));
70 
71 
72 /* ========================================================================== */
73 /* Function Declarations */
74 /* ========================================================================== */
75 
87 static inline float ti_tmu_sin_pu(float anglePU)
88 {
89  __asm__ volatile("str %0, [%1]\n\t"
90  "DMB ST \n\t"
91  :
92  : "r" (anglePU), "r" (CSL_MSS_TMU_BASE + CSL_TMU_SINPUF32_R0));
93 
94  return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0));
95 }
96 
108 static inline float ti_tmu_cos_pu(float anglePU)
109 {
110  __asm__ volatile("str %0, [%1]\n\t"
111  "DMB ST \n\t"
112  :
113  : "r" (anglePU), "r" (CSL_MSS_TMU_BASE + CSL_TMU_COSPUF32_R0));
114 
115  return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0));
116 }
117 
118 
130  static inline float ti_tmu_atan_pu(float x)
131 {
132  __asm__ volatile("str %0, [%1]\n\t"
133  "DMB ST \n\t"
134  :
135  : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_ATANPUF32_R2));
136 
137  return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R2));
138 
139 }
140 
141 
142 
154  static inline float ti_tmu_log_pu(float x)
155 {
156  __asm__ volatile("str %0, [%1]\n\t"
157  "DMB ST \n\t"
158  :
159  : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_LOG2F32_R3));
160 
161  return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R3));
162 }
163 
175  static inline float ti_tmu_log_e_pu(float x)
176 {
177  __asm__ volatile("str %0, [%1]\n\t"
178  "DMB ST \n\t"
179  :
180  : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_LOG2F32_R3));
181 
182  return (*((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R3))) * OnebyLog2ofe;
183 }
184 
185 
186 
197  static inline float ti_tmu_iexp_pu(float x)
198 {
199  __asm__ volatile("str %0, [%1]\n\t"
200  "DMB ST \n\t"
201  :
202  : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_IEXP2F32_R3));
203 
204  return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R3));
205 }
206 
217  static inline float ti_tmu_iexp_e_pu(float x)
218 {
219  __asm__ volatile("str %0, [%1]\n\t"
220  "DMB ST \n\t"
221  :
222  : "r" (x * Log2ofe), "r" (CSL_MSS_TMU_BASE + CSL_TMU_IEXP2F32_R3));
223 
224  return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R3));
225 }
226 
227 
228 
240 static inline float ti_tmu_sin(float angleRad)
241 {
242  __asm__ volatile("str %0, [%1]\n\t"
243  "DMB ST \n\t"
244  :
245  : "r" (angleRad * ReciprocalOf2PI), "r" (CSL_MSS_TMU_BASE + CSL_TMU_SINPUF32_R0));
246 
247  return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0));
248 }
249 
250 
262 static inline float ti_tmu_cos(float angleRad)
263 {
264  __asm__ volatile("str %0, [%1]\n\t"
265  "DMB ST \n\t"
266  :
267  : "r" (angleRad * ReciprocalOf2PI), "r" (CSL_MSS_TMU_BASE + CSL_TMU_COSPUF32_R1));
268 
269  return *((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1));
270 }
271 
283 static inline float ti_tmu_atan(float x)
284 {
285  __asm__ volatile("str %0, [%1]\n\t"
286  "DMB ST \n\t"
287  :
288  : "r" (x), "r" (CSL_MSS_TMU_BASE + CSL_TMU_ATANPUF32_R2));
289 
290  return (*((float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R2))) * TwoPI;
291 }
292 
293 
305 static inline float ti_tmu_atan2(float x, float y)
306 {
307  __asm__ volatile("str %1, [%2, #0x240] \n\t"
308  "str %0, [%2, #0x1F0] \n\t"
309  "DMB ST \n\t"
310  "ldr %0, [%2, #0x2B0] \n\t"
311  "str %0, [%2, #0xC0] \n\t"
312  "DMB ST \n\t"
313  :
314  : "r" (x), "r" (y), "r" (CSL_MSS_TMU_BASE));
315 
316  return (TwoPI * ((*(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0)) + (*(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R7))));
317 
318 }
319 
331 static inline void ti_tmu_sincos_pu(float anglePU, float *sin_val, float *cos_val)
332 {
333  __asm__ volatile("str %0, [%1]\n\t"
334  "str %0, [%2]\n\t"
335  "DMB ST \n\t"
336  ".rept 4 ; nop ; .endr\n\t"
337  :
338  : "r" (anglePU), "r" (CSL_MSS_TMU_BASE + CSL_TMU_SINPUF32_R0), "r" (CSL_MSS_TMU_BASE + CSL_TMU_COSPUF32_R1));
339 
340  *sin_val = *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0);
341  *cos_val = *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1);
342  return;
343 }
344 
356 static inline void ti_tmu_sincos(float angleRad, float *sin_val, float *cos_val)
357 {
358  __asm__ volatile("str %0, [%1]\n\t"
359  "str %0, [%2]\n\t"
360  "DMB ST \n\t"
361  ".rept 4 ; nop ; .endr\n\t"
362  :
363  : "r" (angleRad * ReciprocalOf2PI), "r" (CSL_MSS_TMU_BASE + CSL_TMU_SINPUF32_R0), "r" (CSL_MSS_TMU_BASE + CSL_TMU_COSPUF32_R1));
364 
365  *sin_val = *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0);
366  *cos_val = *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1);
367  return;
368 }
369 
382 static inline float ti_tmu_powf(float x, float y)
383 {
384  __asm__ volatile("str %0, [%1, #0x180] \n\t"
385  "DMB ST \n\t"
386  :
387  : "r" (x), "r" (CSL_MSS_TMU_BASE));
388 
389  float res = (*(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R0)) * y;
390 
391  __asm__ volatile("str %0, [%1, #0x148] \n\t"
392  "DMB ST \n\t"
393  :
394  : "r" (res), "r" (CSL_MSS_TMU_BASE));
395 
396  return res > 0 ? *(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1) : (1.0f / (*(float *)(CSL_MSS_TMU_BASE + CSL_TMU_RESULT_R1)));
397 
398 }
399 
400 
401 
402 #endif /* TI_TMU_TRIG_H */
403 
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:154
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:197
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:130
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:108
ti_tmu_powf
static float ti_tmu_powf(float x, float y)
Computes the power of the input value.
Definition: ti_tmu_trig.h:382
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:331
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:356
ClockP.h
ReciprocalOf2PI
#define ReciprocalOf2PI
Definition: ti_tmu_trig.h:53
Log2ofe
#define Log2ofe
Definition: ti_tmu_trig.h:61
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:175
HwiP.h
TwoPI
#define TwoPI
Definition: ti_tmu_trig.h:57
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:283
OnebyLog2ofe
#define OnebyLog2ofe
Definition: ti_tmu_trig.h:65
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:262
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:217
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:87
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:240
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:305