MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

32b/clarke.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 _CLARKE_H_
33 #define _CLARKE_H_
34
40
41
42 // **************************************************************************
43 // the includes
44
45 // modules
46 #include "sw/modules/iqmath/src/32b/IQmathLib.h"
47 #include "sw/modules/math/src/32b/math.h"
48 #include "sw/modules/types/src/types.h"
49
54
55
56 // Include the algorithm overview defined in modules/<module>/docs/doxygen/doxygen.h
58
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64
65 // **************************************************************************
66 // the defines
67
68
69
70 // **************************************************************************
71 // the typedefs
72
75 typedef struct _CLARKE_Obj_
76 {
77 _iq alpha_sf;
78 _iq beta_sf;
79
80 uint_least8_t numSensors;
81
82 } CLARKE_Obj;
83
84
87 typedef struct _CLARKE_Obj_ *CLARKE_Handle;
88
89
90 // **************************************************************************
91 // the globals
92
93
94 // **************************************************************************
95 // the function prototypes
96
100 static inline uint_least8_t CLARKE_getNumSensors(CLARKE_Handle handle)
101 {
102 CLARKE_Obj *obj = (CLARKE_Obj *)handle;
103
104 return(obj->numSensors);
105 } // end of CLARKE_getNumSensors() function
106
107
112 extern CLARKE_Handle CLARKE_init(void *pMemory,const size_t numBytes);
113
114
119 static inline void CLARKE_run(CLARKE_Handle handle,const MATH_vec3 *pInVec,MATH_vec2 *pOutVec)
120 {
121 CLARKE_Obj *obj = (CLARKE_Obj *)handle;
122
123 uint_least8_t numSensors = obj->numSensors;
124
125 _iq alpha_sf = obj->alpha_sf;
126 _iq beta_sf = obj->beta_sf;
127
128
129 if(numSensors == 3)
130 {
131 pOutVec->value[0] = _IQmpy(lshft_1(pInVec->value[0]) - (pInVec->value[1] + pInVec->value[2]),alpha_sf);
132 pOutVec->value[1] = _IQmpy(pInVec->value[1] - pInVec->value[2],beta_sf);
133 }
134 else if(numSensors == 2)
135 {
136 pOutVec->value[0] = _IQmpy(pInVec->value[0],alpha_sf);
137 pOutVec->value[1] = _IQmpy(pInVec->value[0] + lshft_1(pInVec->value[1]),beta_sf);
138 }
139
140 return;
141 } // end of CLARKE_run() function
142
143
148 static inline void CLARKE_run_twoInput(CLARKE_Handle handle,const MATH_vec2 *pInVec,MATH_vec2 *pOutVec)
149 {
150 CLARKE_Obj *obj = (CLARKE_Obj *)handle;
151
152 _iq beta_sf = obj->beta_sf;
153
154
155 pOutVec->value[0] = pInVec->value[0];
156
157 pOutVec->value[1] = _IQmpy(pInVec->value[0] + _IQmpy2(pInVec->value[1]),beta_sf);
158
159 return;
160 } // end of CLARKE_run_twoInput() function
161
162
166 static inline void CLARKE_setNumSensors(CLARKE_Handle handle,const uint_least8_t numSensors)
167 {
168 CLARKE_Obj *obj = (CLARKE_Obj *)handle;
169
170 obj->numSensors = numSensors;
171
172 return;
173 } // end of CLARKE_setNumSensors() function
174
175
180 static inline void CLARKE_setScaleFactors(CLARKE_Handle handle,const _iq alpha_sf,const _iq beta_sf)
181 {
182 CLARKE_Obj *obj = (CLARKE_Obj *)handle;
183
184
185 obj->alpha_sf = alpha_sf;
186 obj->beta_sf = beta_sf;
187
188 return;
189 } // end of CLARKE_setScaleFactors() function
190
191
192 #ifdef __cplusplus
193 }
194 #endif // extern "C"
195
197 #endif // end of _CLARKE_H_ definition
198
types.h
Contains the public interface to the types definitions.
_CLARKE_Obj_
Defines the CLARKE object.
Definition: 32b/clarke.h:75
_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
_CLARKE_Obj_::beta_sf
_iq beta_sf
the scale factor for the beta component
Definition: 32b/clarke.h:78
CLARKE_setScaleFactors
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
Sets the scale factors.
Definition: 32b/clarke.h:180
CLARKE_getNumSensors
static uint_least8_t CLARKE_getNumSensors(CLARKE_Handle handle)
Gets the number of sensors.
Definition: 32b/clarke.h:100
_CLARKE_Obj_::alpha_sf
_iq alpha_sf
the scale factor for the alpha component
Definition: 32b/clarke.h:77
CLARKE_Obj
struct _CLARKE_Obj_ CLARKE_Obj
Defines the CLARKE object.
_IQmpy
#define _IQmpy(A, B)
Definition: 32b/IQmathLib.h:809
_MATH_vec2_::value
_iq value[2]
Definition: 32b/math.h:251
_MATH_vec3_
Defines a three element vector.
Definition: 32b/math.h:258
CLARKE_init
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
Initializes the Clarke transform module.
Definition: 32b/clarke.c:55
math.h
Contains the public interface to the math (MATH) module routines.
CLARKE_setNumSensors
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
Sets the number of sensors.
Definition: 32b/clarke.h:166
CLARKE_run_twoInput
static void CLARKE_run_twoInput(CLARKE_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
Runs the Clarke transform module for two inputs.
Definition: 32b/clarke.h:148
CLARKE_run
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
Runs the Clarke transform module for three inputs.
Definition: 32b/clarke.h:119
_CLARKE_Obj_::numSensors
uint_least8_t numSensors
the number of sensors
Definition: 32b/clarke.h:80
CLARKE_Handle
struct _CLARKE_Obj_ * CLARKE_Handle
Defines the CLARKE handle.
Definition: 32b/clarke.h:87
_IQmpy2
#define _IQmpy2(A)
Definition: 32b/IQmathLib.h:255
lshft_1
#define lshft_1(A)
Definition: 32b/math.h:209
IQmathLib.h