MotorWare f2806x Module API Documentation
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 //###########################################################################
46 
47 //CLASinCosTable Variables
48 extern float_t CLAsincosTable[161];
49 extern float_t CLAsinTable[128];
51 extern float_t CLAcosTable[129];
53 extern float_t *CLAsinTableEnd;
54 extern float_t *CLAcosTableEnd;
66 
67 //CLAatanTable Variables
69 extern float_t CLAatan2Table[195];
71 extern float_t *CLAINV2PI;
72 
73 //CLAacosineTable Variables
75 extern float_t CLAacosinTable[192];
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
86 extern float_t CLAExpTable[89];
87 extern float_t *CLAExpTableEnd;
88 
89 //CLAlnTable Variables
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__
float_t CLALNVe
Contains the public interface to the types definitions.
float_t CLAatan2PU(float_t fVal1, float_t fVal2)
float_t * CLAasinTableEnd
float_t CLAatan2HalfPITable[2]
float_t CLAsin(float_t fAngleRad)
float_t CLAacosinTable[192]
float_t CLAasinHalfPITable[2]
float_t * CLALnTableEnd
float_t CLALnTable[99]
float_t * CLAsincosTableEnd
float_t * CLAacosinTableEnd
float_t * CLAsincosTable_Sin0
float_t CLAsincosTable_TABLE_MASK
float_t CLAasin(float_t fVal)
float_t CLAINV4
float_t CLAatan(float_t fVal)
float_t CLAsincosTable_TwoPiDivTABLE_SIZE
float_t * CLAsincosTable_Cos0
float_t CLAcosTable[129]
float_t CLAexp2(float_t fNum, float_t fDen)
float_t CLALNV10
float_t CLABIAS
float_t CLAsincosTable[161]
long CLALN_TABLE_MASK1
float_t CLAdiv(float_t fNum, float_t fDen)
float_t CLAsincosTable_Coef3_neg
float_t CLAatan2Table[195]
float_t * CLAatan2TableEnd
float_t * CLAINV2PI
float_t CLAsincosTable_Coef3
float_t CLAINV3
float_t * CLAcosTableEnd
float_t CLAINV1
float_t CLAln(float_t fVal)
float_t CLAasinTable[195]
float_t CLAsincosTable_TABLE_SIZE
float_t CLAExpTable[89]
float_t CLAINV7
float_t CLAexp10(float_t fVal)
float_t CLAexp(float_t fVal)
float_t CLAcosPU(float_t fAngleRadPU)
float_t CLAlog10(float_t fVal)
unsigned int _cla_scratchpad_end
float_t CLALNV2
float_t CLAINV2
float_t CLAINV6
float_t CLAatan2(float_t fVal1, float_t fVal2)
float_t CLAsincosTable_Coef1_pos
float_t CLAacosinHalfPITable[2]
float_t CLAacos(float_t fVal)
float_t CLAsinPU(float_t fAngleRadPU)
float_t CLAsincosTable_Coef1
float_t CLAsincosTable_Coef2
float_t * CLAExpTableEnd
unsigned int _cla_scratchpad_start
float_t CLALOG10
float_t CLAsinTable[128]
float_t CLAisqrt(float_t fVal)
float_t CLAcos(float_t fAngleRad)
long CLALN_TABLE_MASK2
float_t CLAsincosTable_Coef0
float_t CLAsqrt(float_t fVal)
float_t CLAacos_spc(float_t fVal)
float_t CLAINV5
float_t CLAsincosTable_TABLE_SIZEDivTwoPi
#define TWOPIDDIV_TABLE_SIZE
Definition: CLAmath.h:128
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
float_t * CLAsinTableEnd