MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

32b/math.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 2012, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
32 #ifndef _MATH_H_
33 #define _MATH_H_
34
40
41
42 // **************************************************************************
43 // the includes
44
45 #include "sw/modules/iqmath/src/32b/IQmathLib.h"
46 #include "sw/modules/types/src/types.h"
47
48
53
54
55 // Include the algorithm overview defined in modules/<module>/docs/doxygen/doxygen.h
57
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63
64 // **************************************************************************
65 // the defines
66
69 #define MATH_Nm_TO_lbin_SF (8.8507457913)
70
73 #define MATH_FOUR_OVER_THREE (1.33333333333333333333333333333333)
74
77 #define MATH_TWO_OVER_THREE (0.66666666666666666666666666666667)
78
81 #define MATH_ONE_OVER_THREE (0.33333333333333333333333333333333)
82
85 #define MATH_ONE_OVER_PI (0.318309886183791)
86
89 #define MATH_ONE_OVER_SQRT_THREE (0.57735026918962576450914878050196)
90
93 #define MATH_ONE_OVER_FOUR_PI (0.07957747154594767)
94
97 #define MATH_ONE_OVER_TWO_PI (0.1591549430918954)
98
101 #define MATH_PI (3.1415926535897932384626433832795)
102
105 #define MATH_PI_PU (0.5)
106
109 #define MATH_TWO_PI (6.283185307179586)
110
113 #define MATH_TWO_PI_PU (1.0)
114
117 #define MATH_FOUR_PI (12.56637061435917)
118
121 #define MATH_FOUR_PI_PU (2.0)
122
125 #define MATH_PI_OVER_TWO (1.570796326794897)
126
129 #define MATH_PI_OVER_TWO_PU (0.25)
130
133 #define MATH_PI_OVER_FOUR (0.785398163397448)
134
137 #define MATH_PI_OVER_FOUR_PU (0.125)
138
139
140 #define rshft(A,n) \
141 (((n) < 2) ? rshft_1(A) \
142 :(((n) < 3) ? rshft_2(A) \
143 :(((n) < 4) ? rshft_3(A) \
144 :(((n) < 5) ? rshft_4(A) \
145 :(((n) < 6) ? rshft_5(A) \
146 :(((n) < 7) ? rshft_6(A) \
147 :(((n) < 8) ? rshft_7(A) \
148 :(((n) < 9) ? rshft_8(A) \
149 :(((n) < 10) ? rshft_9(A) \
150 :(((n) < 11) ? rshft_10(A) \
151 :(((n) < 12) ? rshft_11(A) \
152 :(((n) < 13) ? rshft_12(A) \
153 :(((n) < 14) ? rshft_13(A) \
154 :(((n) < 15) ? rshft_14(A) \
155 :(((n) < 16) ? rshft_15(A) \
156 :(((n) < 17) ? rshft_16(A) \
157 :(((n) < 18) ? rshft_17(A) \
158 :(((n) < 19) ? rshft_18(A) \
159 :(((n) < 20) ? rshft_19(A) \
160 :(((n) < 21) ? rshft_20(A) \
161 :(((n) < 22) ? rshft_21(A) \
162 :(((n) < 23) ? rshft_22(A) \
163 :(((n) < 24) ? rshft_23(A) \
164 :(((n) < 25) ? rshft_24(A) \
165 :(((n) < 26) ? rshft_25(A) \
166 :(((n) < 27) ? rshft_26(A) \
167 :(((n) < 28) ? rshft_27(A) \
168 :(((n) < 29) ? rshft_28(A) \
169 :(((n) < 30) ? rshft_29(A) \
170 :(((n) < 31) ? rshft_30(A) \
171 :(((n) < 32) ? rshft_31(A) \
172 :(rshft_32(A)))))))))))))))))))))))))))))))))
173
174 #define rshft_1(A) (((A) + 0x1)>>1)
175 #define rshft_2(A) (((A) + 0x2)>>2)
176 #define rshft_3(A) (((A) + 0x4)>>3)
177 #define rshft_4(A) (((A) + 0x8)>>4)
178 #define rshft_5(A) (((A) + 0x10)>>5)
179 #define rshft_6(A) (((A) + 0x20)>>6)
180 #define rshft_7(A) (((A) + 0x40)>>7)
181 #define rshft_8(A) (((A) + 0x80)>>8)
182 #define rshft_9(A) (((A) + 0x100)>>9)
183 #define rshft_10(A) (((A) + 0x200)>>10)
184 #define rshft_11(A) (((A) + 0x400)>>11)
185 #define rshft_12(A) (((A) + 0x800)>>12)
186 #define rshft_13(A) (((A) + 0x1000)>>13)
187 #define rshft_14(A) (((A) + 0x2000)>>14)
188 #define rshft_15(A) (((A) + 0x4000)>>15)
189 #define rshft_16(A) (((A) + 0x8000)>>16)
190 #define rshft_17(A) (((A) + 0x10000)>>17)
191 #define rshft_18(A) (((A) + 0x20000)>>18)
192 #define rshft_19(A) (((A) + 0x40000)>>19)
193 #define rshft_20(A) (((A) + 0x80000)>>20)
194 #define rshft_21(A) (((A) + 0x100000)>>21)
195 #define rshft_22(A) (((A) + 0x200000)>>22)
196 #define rshft_23(A) (((A) + 0x400000)>>23)
197 #define rshft_24(A) (((A) + 0x800000)>>24)
198 #define rshft_25(A) (((A) + 0x1000000)>>25)
199 #define rshft_26(A) (((A) + 0x2000000)>>26)
200 #define rshft_27(A) (((A) + 0x4000000)>>27)
201 #define rshft_28(A) (((A) + 0x8000000)>>28)
202 #define rshft_29(A) (((A) + 0x10000000)>>29)
203 #define rshft_30(A) (((A) + 0x20000000)>>30)
204 #define rshft_31(A) (((A) + 0x40000000)>>31)
205 #define rshft_32(A) (((A) + 0x80000000)>>32)
206
207 #define lshft(A,n) ((A)<<(n))
208
209 #define lshft_1(A) ((A)<<1)
210 #define lshft_2(A) ((A)<<2)
211 #define lshft_3(A) ((A)<<3)
212 #define lshft_4(A) ((A)<<4)
213 #define lshft_5(A) ((A)<<5)
214 #define lshft_6(A) ((A)<<6)
215 #define lshft_7(A) ((A)<<7)
216 #define lshft_8(A) ((A)<<8)
217 #define lshft_9(A) ((A)<<9)
218 #define lshft_10(A) ((A)<<10)
219 #define lshft_11(A) ((A)<<11)
220 #define lshft_12(A) ((A)<<12)
221 #define lshft_13(A) ((A)<<13)
222 #define lshft_14(A) ((A)<<14)
223 #define lshft_15(A) ((A)<<15)
224 #define lshft_16(A) ((A)<<16)
225 #define lshft_17(A) ((A)<<17)
226 #define lshft_18(A) ((A)<<18)
227 #define lshft_19(A) ((A)<<19)
228 #define lshft_20(A) ((A)<<20)
229 #define lshft_21(A) ((A)<<21)
230 #define lshft_22(A) ((A)<<22)
231 #define lshft_23(A) ((A)<<23)
232 #define lshft_24(A) ((A)<<24)
233 #define lshft_25(A) ((A)<<25)
234 #define lshft_26(A) ((A)<<26)
235 #define lshft_27(A) ((A)<<27)
236 #define lshft_28(A) ((A)<<28)
237 #define lshft_29(A) ((A)<<29)
238 #define lshft_30(A) ((A)<<30)
239 #define lshft_31(A) ((A)<<31)
240 #define lshft_32(A) ((A)<<32)
241
242
243 // **************************************************************************
244 // the typedefs
245
248 typedef struct _MATH_vec2_
249 {
250
251 _iq value[2];
252
253 } MATH_vec2;
254
255
258 typedef struct _MATH_vec3_
259 {
260
261 _iq value[3];
262
263 } MATH_vec3;
264
265
266 // **************************************************************************
267 // the function prototypes
268
269
270 #ifdef __cplusplus
271 }
272 #endif // extern "C"
273
275 #endif // end of _MATH_H_ definition
276
277
types.h
Contains the public interface to the types definitions.
_MATH_vec2_
Defines a two element vector.
Definition: 32b/math.h:248
_MATH_vec3_::value
_iq value[3]
Definition: 32b/math.h:261
_iq
long _iq
Definition: 32b/IQmathLib.h:223
_MATH_vec2_::value
_iq value[2]
Definition: 32b/math.h:251
_MATH_vec3_
Defines a three element vector.
Definition: 32b/math.h:258
MATH_vec3
struct _MATH_vec3_ MATH_vec3
Defines a three element vector.
IQmathLib.h
MATH_vec2
struct _MATH_vec2_ MATH_vec2
Defines a two element vector.