MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

CLAmath.h
Go to the documentation of this file.
1 /******************************************************************************
2 *******************************************************************************
3 *
4 * FILE: CLAmath.h
5 *
6 * DESCRIPTION: CLA math routines library
7 *
8 *******************************************************************************
9 * $TI Release: CLA Math Library for CLA C Compiler V4.00.01.00 $
10 * $Release Date: Apr 23, 2014 $
11 *******************************************************************************
12 * This software is licensed for use with Texas Instruments C28x
13 * family DSCs. This license was provided to you prior to installing
14 * the software. You may review this license by consulting a copy of
15 * the agreement in the doc directory of this library.
16 * ------------------------------------------------------------------------
17 * Copyright (C) 2014 Texas Instruments, Incorporated.
18 * All Rights Reserved.
19 ******************************************************************************/
20 #ifndef __CLAMATH_H__
21 #define __CLAMATH_H__
22
23 //###########################################################################
24 //
25 // If building with a C++ compiler, make all of the definitions in this header
26 // have a C binding.
27 //
28 //###########################################################################
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 //###########################################################################
34 //
35 // Macro Definitions
36 //
37 //###########################################################################
38
39
40 //###########################################################################
41 //
42 // Structures, variables and typedefs.
43 //
44 //###########################################################################
45 #include "sw/modules/types/src/types.h"
46
47 //CLASinCosTable Variables
48 extern float_t CLAsincosTable[161];
49 extern float_t CLAsinTable[128];
50 extern float_t *CLAsincosTable_Sin0;
51 extern float_t CLAcosTable[129];
52 extern float_t *CLAsincosTable_Cos0;
53 extern float_t *CLAsinTableEnd;
54 extern float_t *CLAcosTableEnd;
55 extern float_t *CLAsincosTableEnd;
56 extern float_t CLAsincosTable_TABLE_SIZE;
57 extern float_t CLAsincosTable_TABLE_SIZEDivTwoPi;
58 extern float_t CLAsincosTable_TwoPiDivTABLE_SIZE;
59 extern float_t CLAsincosTable_TABLE_MASK;
60 extern float_t CLAsincosTable_Coef0;
61 extern float_t CLAsincosTable_Coef1;
62 extern float_t CLAsincosTable_Coef1_pos;
63 extern float_t CLAsincosTable_Coef2;
64 extern float_t CLAsincosTable_Coef3;
65 extern float_t CLAsincosTable_Coef3_neg;
66
67 //CLAatanTable Variables
68 extern float_t CLAatan2HalfPITable[2];
69 extern float_t CLAatan2Table[195];
70 extern float_t *CLAatan2TableEnd;
71 extern float_t *CLAINV2PI;
72
73 //CLAacosineTable Variables
74 extern float_t CLAacosinHalfPITable[2];
75 extern float_t CLAacosinTable[192];
76 extern float_t *CLAacosinTableEnd;
77
78 //CLAasineTable Variables
79 extern float_t CLAasinHalfPITable[2];
80 extern float_t CLAasinTable[195];
81 extern float_t *CLAasinTableEnd;
82
83 //CLAexpTable Variables
84 extern float_t CLAINV1,CLAINV2,CLAINV3,CLAINV4;
85 extern float_t CLAINV5,CLAINV6,CLAINV7,CLALOG10;
86 extern float_t CLAExpTable[89];
87 extern float_t *CLAExpTableEnd;
88
89 //CLAlnTable Variables
90 extern float_t CLALNV2,CLALNVe,CLALNV10,CLABIAS;
91 extern long CLALN_TABLE_MASK1,CLALN_TABLE_MASK2;
92 extern float_t CLALnTable[99];
93 extern float_t *CLALnTableEnd;
94
95 //Linker Defined variables
96 extern unsigned int _cla_scratchpad_start;
97 extern unsigned int _cla_scratchpad_end;
98
99 //###########################################################################
100 //
101 // Function Prototypes
102 //
103 //###########################################################################
104 extern float_t CLAacos(float_t fVal);
105 extern float_t CLAacos_spc(float_t fVal);
106 extern float_t CLAasin(float_t fVal);
107 extern float_t CLAatan(float_t fVal);
108 extern float_t CLAatan2(float_t fVal1, float_t fVal2);
109 extern float_t CLAatan2PU(float_t fVal1, float_t fVal2);
110 extern float_t CLAcos(float_t fAngleRad);
111 extern float_t CLAcosPU(float_t fAngleRadPU);
112 extern float_t CLAdiv(float_t fNum, float_t fDen);
113 extern float_t CLAexp(float_t fVal);
114 extern float_t CLAexp10(float_t fVal);
115 extern float_t CLAexp2(float_t fNum, float_t fDen);
116 extern float_t CLAisqrt(float_t fVal);
117 extern float_t CLAln(float_t fVal);
118 extern float_t CLAlog10(float_t fVal);
119 extern float_t CLAsin(float_t fAngleRad);
120 extern float_t CLAsinPU(float_t fAngleRadPU);
121 extern float_t CLAsqrt(float_t fVal);
122 //###########################################################################
123 //
124 // Inline Functions
125 //
126 //###########################################################################
127 #define TABLE_SIZE_DIVTWOPI 20.37183271576; //TABLE_SIZE/(2*Pi)
128 #define TWOPIDDIV_TABLE_SIZE 0.04908738521234; //(2*Pi)/TABLE_SIZE
129 #define TABLE_SIZE 64
130 #define TABLE_SIZE_M_1 TABLE_SIZE-1
131 #ifndef PI
132 #define PI 3.141592653589
133 #endif
134
135
136 #ifdef __TMS320C28XX_CLA__
137 #pragma FUNC_ALWAYS_INLINE(CLAsqrt_inline)
138 extern float_t __meisqrtf32(float_t in);
139 static inline float_t CLAsqrt_inline(float_t in)
140 {
141 float_t y0,y1,y2;
142
143 y0 = __meisqrtf32(in); //Initial estimate of isqrt(in)
144
145
146 if(in == (float_t)0.0)
147 {
148 y0 = (float_t)0.0;
149 }
150
151 y1 = y0*((float_t)1.5 - y0*y0*in*(float_t)0.5); //Newton rapshon iteration 1
152 y2 = y1*((float_t)1.5 - y1*y1*in*(float_t)0.5); //Newton rapshon iteration 2
153 y2 = y2 * in; //est(1/sqrt(in))*in = est(sqrt(in))
154
155 return(y2);
156 }
157
158
159 #pragma FUNC_ALWAYS_INLINE(CLAsin_inline)
160 extern float_t __mfracf32(float_t in);
161 static inline float_t CLAsin_inline(float_t fAngle)
162 {
163 //Local Variables
164 float_t tblIdx; //The floating pt table index
165 float_t X; //Fractional part of tblidx
166 float_t SinK,CosK; //Table values sin and cos that are closest to the
167 //user input angle value
168 signed int index;
169
170 tblIdx = fAngle * CLAsincosTable_TABLE_SIZEDivTwoPi;
171 index=(((signed int)tblIdx)&(signed int)0x007F);
172 SinK = CLAsincosTable[(signed int)index];
173 CosK = CLAsincosTable[index+32];
174
175 X = __mfracf32(tblIdx);
176 X = X * (float_t)TWOPIDDIV_TABLE_SIZE;
177
178 //Using the Taylor series
179 return (SinK + X * (CosK \
180 + X * (CLAsincosTable_Coef0 * SinK \
181 + X * (CLAsincosTable_Coef1 * CosK \
182 + X * (CLAsincosTable_Coef2 * SinK \
183 + X * (CLAsincosTable_Coef3 * CosK))))));
184 }
185
186
187 #pragma FUNC_ALWAYS_INLINE(CLAcos_inline)
188 static inline float_t CLAcos_inline(float_t fAngle)
189 {
190 //Local Variables
191 float_t tblIdx; //The floating pt table index, needs to be volatile due to compiler BUG
192 float_t X; //Fractional part of tblidx
193 float_t SinK,CosK; //Table values sin and cos that are closest to the
194 //user input angle value
195 signed int index;
196
197 tblIdx = fAngle * CLAsincosTable_TABLE_SIZEDivTwoPi;
198 index=(((signed int)tblIdx)&(signed int)0x007F);
199
200 SinK = CLAsincosTable[index]; //*pTblSin;
201 CosK = CLAsincosTable[index+32]; //*pTblCos;
202
203 X = __mfracf32(tblIdx);
204 X = X * (float_t)TWOPIDDIV_TABLE_SIZE;
205
206 //Using the Taylor series
207 return (CosK + X * (-SinK \
208 + X * (CLAsincosTable_Coef0 * CosK \
209 + X * (CLAsincosTable_Coef1_pos * SinK \
210 + X * (CLAsincosTable_Coef2 * CosK \
211 + X * (CLAsincosTable_Coef3_neg * SinK))))));
212 }
213 #endif
214
215
216 //###########################################################################
217 //
218 //End of the C bindings section for C++ compilers.
219 //
220 //###########################################################################
221 #ifdef __cplusplus
222 }
223 #endif //__cplusplus
224
225 #endif // __CLAMATH_H__
CLALNVe
float_t CLALNVe
types.h
Contains the public interface to the types definitions.
CLAatan2PU
float_t CLAatan2PU(float_t fVal1, float_t fVal2)
CLAasinTableEnd
float_t * CLAasinTableEnd
CLAatan2HalfPITable
float_t CLAatan2HalfPITable[2]
CLAsin
float_t CLAsin(float_t fAngleRad)
CLAacosinTable
float_t CLAacosinTable[192]
CLAasinHalfPITable
float_t CLAasinHalfPITable[2]
CLALnTableEnd
float_t * CLALnTableEnd
CLALnTable
float_t CLALnTable[99]
CLAsincosTableEnd
float_t * CLAsincosTableEnd
CLAacosinTableEnd
float_t * CLAacosinTableEnd
CLAsincosTable_Sin0
float_t * CLAsincosTable_Sin0
CLAsincosTable_TABLE_MASK
float_t CLAsincosTable_TABLE_MASK
CLAasin
float_t CLAasin(float_t fVal)
CLAINV4
float_t CLAINV4
CLAatan
float_t CLAatan(float_t fVal)
CLAsincosTable_TwoPiDivTABLE_SIZE
float_t CLAsincosTable_TwoPiDivTABLE_SIZE
CLAsincosTable_Cos0
float_t * CLAsincosTable_Cos0
CLAcosTable
float_t CLAcosTable[129]
CLAexp2
float_t CLAexp2(float_t fNum, float_t fDen)
CLALNV10
float_t CLALNV10
CLABIAS
float_t CLABIAS
CLAsincosTable
float_t CLAsincosTable[161]
CLALN_TABLE_MASK1
long CLALN_TABLE_MASK1
CLAdiv
float_t CLAdiv(float_t fNum, float_t fDen)
CLAsincosTable_Coef3_neg
float_t CLAsincosTable_Coef3_neg
CLAatan2Table
float_t CLAatan2Table[195]
CLAatan2TableEnd
float_t * CLAatan2TableEnd
CLAINV2PI
float_t * CLAINV2PI
CLAsincosTable_Coef3
float_t CLAsincosTable_Coef3
CLAINV3
float_t CLAINV3
CLAcosTableEnd
float_t * CLAcosTableEnd
CLAINV1
float_t CLAINV1
CLAln
float_t CLAln(float_t fVal)
CLAasinTable
float_t CLAasinTable[195]
CLAsincosTable_TABLE_SIZE
float_t CLAsincosTable_TABLE_SIZE
CLAExpTable
float_t CLAExpTable[89]
CLAINV7
float_t CLAINV7
CLAexp10
float_t CLAexp10(float_t fVal)
CLAexp
float_t CLAexp(float_t fVal)
CLAcosPU
float_t CLAcosPU(float_t fAngleRadPU)
CLAlog10
float_t CLAlog10(float_t fVal)
_cla_scratchpad_end
unsigned int _cla_scratchpad_end
CLALNV2
float_t CLALNV2
CLAINV2
float_t CLAINV2
CLAINV6
float_t CLAINV6
CLAatan2
float_t CLAatan2(float_t fVal1, float_t fVal2)
CLAsincosTable_Coef1_pos
float_t CLAsincosTable_Coef1_pos
CLAacosinHalfPITable
float_t CLAacosinHalfPITable[2]
CLAacos
float_t CLAacos(float_t fVal)
CLAsinPU
float_t CLAsinPU(float_t fAngleRadPU)
CLAsincosTable_Coef1
float_t CLAsincosTable_Coef1
CLAsincosTable_Coef2
float_t CLAsincosTable_Coef2
CLAExpTableEnd
float_t * CLAExpTableEnd
_cla_scratchpad_start
unsigned int _cla_scratchpad_start
CLALOG10
float_t CLALOG10
CLAsinTable
float_t CLAsinTable[128]
CLAisqrt
float_t CLAisqrt(float_t fVal)
CLAcos
float_t CLAcos(float_t fAngleRad)
CLALN_TABLE_MASK2
long CLALN_TABLE_MASK2
CLAsincosTable_Coef0
float_t CLAsincosTable_Coef0
CLAsqrt
float_t CLAsqrt(float_t fVal)
CLAacos_spc
float_t CLAacos_spc(float_t fVal)
CLAINV5
float_t CLAINV5
CLAsincosTable_TABLE_SIZEDivTwoPi
float_t CLAsincosTable_TABLE_SIZEDivTwoPi
TWOPIDDIV_TABLE_SIZE
#define TWOPIDDIV_TABLE_SIZE
Definition: CLAmath.h:128
float_t
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
CLAsinTableEnd
float_t * CLAsinTableEnd