MotorWare f2806x Module API Documentation
drv8312kit_revD/f28x/f2806x/src/hal_obj.h
Go to the documentation of this file.
1 #ifndef _HAL_OBJ_H_
2 #define _HAL_OBJ_H_
3 /* --COPYRIGHT--,BSD
4  * Copyright (c) 2012, Texas Instruments Incorporated
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  *
18  * * Neither the name of Texas Instruments Incorporated nor the names of
19  * its contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  * --/COPYRIGHT--*/
34 
39 
40 
41 // drivers
42 #include "sw/drivers/adc/src/32b/f28x/f2806x/adc.h"
43 #include "sw/drivers/clk/src/32b/f28x/f2806x/clk.h"
44 #include "sw/drivers/cpu/src/32b/f28x/f2806x/cpu.h"
45 #include "sw/drivers/flash/src/32b/f28x/f2806x/flash.h"
46 #include "sw/drivers/gpio/src/32b/f28x/f2806x/gpio.h"
47 #include "sw/drivers/osc/src/32b/f28x/f2806x/osc.h"
48 #include "sw/drivers/pie/src/32b/f28x/f2806x/pie.h"
49 #include "sw/drivers/pll/src/32b/f28x/f2806x/pll.h"
50 #include "sw/drivers/pwm/src/32b/f28x/f2806x/pwm.h"
51 #include "sw/drivers/pwmdac/src/32b/f28x/f2806x/pwmdac.h"
52 #include "sw/drivers/pwr/src/32b/f28x/f2806x/pwr.h"
53 #include "sw/drivers/spi/src/32b/f28x/f2806x/spi.h"
54 #include "sw/drivers/timer/src/32b/f28x/f2806x/timer.h"
55 #include "sw/drivers/wdog/src/32b/f28x/f2806x/wdog.h"
56 
57 #ifdef QEP
58 #include "sw/drivers/qep/src/32b/f28x/f2806x/qep.h"
59 #endif
60 
61 // modules
65 
66 
67 // platforms
68 #include "user.h"
69 
70 
75 
76 
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 typedef struct _HAL_AdcData_t_
87 {
88  MATH_vec3 I;
89 
90  MATH_vec3 V;
91 
92  _iq dcBus;
93 
95 
96 
101 typedef struct _HAL_DacData_t_
102 {
103  _iq value[4];
104 
105 } HAL_DacData_t;
106 
107 
114 typedef struct _HAL_PwmData_t_
115 {
116  MATH_vec3 Tabc;
117 
118 } HAL_PwmData_t;
119 
120 
126 typedef struct _HAL_Obj_
127 {
128  ADC_Handle adcHandle;
129 
130  CLK_Handle clkHandle;
131 
132  CPU_Handle cpuHandle;
133 
134  FLASH_Handle flashHandle;
135 
136  GPIO_Handle gpioHandle;
137 
139  OFFSET_Obj offset_I[3];
140 
142  OFFSET_Obj offset_V[3];
143 
144  OSC_Handle oscHandle;
145 
146  PIE_Handle pieHandle; //<! the PIE handle
147 
148  PLL_Handle pllHandle;
149 
150  PWM_Handle pwmHandle[3]; //<! the PWM handles
151 
152  PWMDAC_Handle pwmDacHandle[3]; //<! the PWMDAC handles
153 
154  PWR_Handle pwrHandle; //<! the power handle
155 
156  TIMER_Handle timerHandle[3]; //<! the timer handles
157 
158  WDOG_Handle wdogHandle;
159 
161 
162  _iq current_sf;
163 
164  _iq voltage_sf;
165 
166  uint_least8_t numCurrentSensors;
167  uint_least8_t numVoltageSensors;
168 
169  SPI_Handle spiAHandle;
170 #ifdef QEP
171  QEP_Handle qepHandle[1];
172 #endif
173 
174 } HAL_Obj;
175 
176 
182 typedef struct _HAL_Obj_ *HAL_Handle;
183 
184 
187 extern HAL_Obj hal;
188 
189 
195 inline void HAL_runOffsetEst(HAL_Handle handle,const HAL_AdcData_t *pAdcData)
196 {
197  uint_least8_t cnt;
198  HAL_Obj *obj = (HAL_Obj *)handle;
199 
200 
201  // estimate the current offsets
202  for(cnt=0;cnt<obj->numCurrentSensors;cnt++)
203  {
204  OFFSET_run(obj->offsetHandle_I[cnt],pAdcData->I.value[cnt]);
205  }
206 
207 
208  // estimate the voltage offsets
209  for(cnt=0;cnt<obj->numVoltageSensors;cnt++)
210  {
211  OFFSET_run(obj->offsetHandle_V[cnt],pAdcData->V.value[cnt]);
212  }
213 
214  return;
215 } // end of HAL_runOffsetEst() function
216 
217 
218 #ifdef __cplusplus
219 }
220 #endif // extern "C"
221 
223 #endif // end of _HAL_OBJ_H_ definition
224 
OFFSET_Handle offsetHandle_I[3]
the handles for the current offset estimators
OFFSET_Obj offset_V[3]
the voltage offset objects
Contains the public interface to the types definitions.
Contains the public interface to the offset (OFFSET) module routines.
_iq value[3]
Definition: 32b/math.h:261
CLK_Handle clkHandle
the clock handle
_iq current_sf
the current scale factor, amps_pu/cnt
long _iq
HAL_AdcData_t adcBias
the ADC bias
FLASH_Handle flashHandle
the flash handle
Contains public interface to the micro-second delay function.
MATH_vec3 Tabc
the PWM time-durations for each motor phase
struct _HAL_Obj_ * HAL_Handle
Defines the HAL handle.
Defines a three element vector.
Definition: 32b/math.h:258
void HAL_runOffsetEst(HAL_Handle handle, const HAL_AdcData_t *pAdcData)
Runs offset estimation.
struct _HAL_DacData_t_ HAL_DacData_t
Defines the DAC data.
uint_least8_t numCurrentSensors
the number of current sensors
struct _OFFSET_Obj_ * OFFSET_Handle
Defines the OFFSET handle.
Definition: 32b/offset.h:95
SPI_Handle spiAHandle
the SPI handle
_iq voltage_sf
the voltage scale factor, volts_pu/cnt
WDOG_Handle wdogHandle
the watchdog handle
struct _HAL_PwmData_t_ HAL_PwmData_t
Defines the PWM data.
struct _HAL_AdcData_t_ HAL_AdcData_t
Defines the ADC data.
OSC_Handle oscHandle
the oscillator handle
ADC_Handle adcHandle
the ADC handle
CPU_Handle cpuHandle
the CPU handle
struct _HAL_Obj_ HAL_Obj
Defines the hardware abstraction layer (HAL) data.
HAL_Obj hal
Defines the HAL object.
OFFSET_Obj offset_I[3]
the current offset objects
PLL_Handle pllHandle
the PLL handle
uint_least8_t numVoltageSensors
the number of voltage sensors
static void OFFSET_run(OFFSET_Handle handle, const _iq inputValue)
Runs an offset filter of the form y[n] = beta*(x[n]+bias) + (1 - beta)*y[n-1] y -> The DC offset x ->...
Definition: 32b/offset.h:137
OFFSET_Handle offsetHandle_V[3]
the handles for the voltage offset estimators
Defines the hardware abstraction layer (HAL) data.
GPIO_Handle gpioHandle
the GPIO handle
Defines the offset (OFFSET) object.
Definition: 32b/offset.h:82