amiro-os / modules / PowerManagement_1-1 / module.c @ 6a5c36eb
History | View | Annotate | Download (32.87 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file
|
21 |
* @brief Structures and constant for the PowerManagement module.
|
22 |
*
|
23 |
* @addtogroup powermanagement_module
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#include "module.h" |
28 |
|
29 |
/*===========================================================================*/
|
30 |
/**
|
31 |
* @name Module specific functions
|
32 |
* @{
|
33 |
*/
|
34 |
/*===========================================================================*/
|
35 |
|
36 |
/** @} */
|
37 |
|
38 |
/*===========================================================================*/
|
39 |
/**
|
40 |
* @name ChibiOS/HAL configuration
|
41 |
* @{
|
42 |
*/
|
43 |
/*===========================================================================*/
|
44 |
|
45 |
ADCConversionGroup moduleHalAdcVsysConversionGroup = { |
46 |
/* buffer type */ true, |
47 |
/* number of channels */ 1, |
48 |
/* callback function */ NULL, |
49 |
/* error callback */ NULL, |
50 |
/* CR1 */ ADC_CR1_AWDEN | ADC_CR1_AWDIE,
|
51 |
/* CR2 */ ADC_CR2_SWSTART | ADC_CR2_CONT,
|
52 |
/* SMPR1 */ 0, |
53 |
/* SMPR2 */ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480),
|
54 |
/* HTR */ ADC_HTR_HT,
|
55 |
/* LTR */ 0, |
56 |
/* SQR1 */ ADC_SQR1_NUM_CH(1), |
57 |
/* SQR2 */ 0, |
58 |
/* SQR3 */ ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9),
|
59 |
}; |
60 |
|
61 |
CANConfig moduleHalCanConfig = { |
62 |
/* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
63 |
/* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(3) | CAN_BTR_TS1(15) | CAN_BTR_BRP(1), |
64 |
}; |
65 |
|
66 |
I2CConfig moduleHalI2cSrPm18Pm33GaugeRearConfig = { |
67 |
/* I²C mode */ OPMODE_I2C,
|
68 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
69 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
70 |
}; |
71 |
|
72 |
I2CConfig moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig = { |
73 |
/* I²C mode */ OPMODE_I2C,
|
74 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
75 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
76 |
}; |
77 |
|
78 |
PWMConfig moduleHalPwmBuzzerConfig = { |
79 |
/* frequency */ 1000000, |
80 |
/* period */ 0, |
81 |
/* callback */ NULL, |
82 |
/* channel configurations */ {
|
83 |
/* channel 0 */ {
|
84 |
/* mode */ PWM_OUTPUT_DISABLED,
|
85 |
/* callback */ NULL |
86 |
}, |
87 |
/* channel 1 */ {
|
88 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
89 |
/* callback */ NULL |
90 |
}, |
91 |
/* channel 2 */ {
|
92 |
/* mode */ PWM_OUTPUT_DISABLED,
|
93 |
/* callback */ NULL |
94 |
}, |
95 |
/* channel 3 */ {
|
96 |
/* mode */ PWM_OUTPUT_DISABLED,
|
97 |
/* callback */ NULL |
98 |
}, |
99 |
}, |
100 |
/* TIM CR2 register */ 0, |
101 |
#if (STM32_PWM_USE_ADVANCED == TRUE)
|
102 |
/* TIM BDTR register */ 0, |
103 |
#endif /* (STM32_PWM_USE_ADVANCED == TRUE) */ |
104 |
/* TIM DIER register */ 0, |
105 |
}; |
106 |
|
107 |
SerialConfig moduleHalProgIfConfig = { |
108 |
/* bit rate */ 115200, |
109 |
/* CR1 */ 0, |
110 |
/* CR1 */ 0, |
111 |
/* CR1 */ 0, |
112 |
}; |
113 |
|
114 |
/** @} */
|
115 |
|
116 |
/*===========================================================================*/
|
117 |
/**
|
118 |
* @name GPIO definitions
|
119 |
* @{
|
120 |
*/
|
121 |
/*===========================================================================*/
|
122 |
|
123 |
/**
|
124 |
* @brief SYS_REG_EN output signal GPIO.
|
125 |
*/
|
126 |
static apalGpio_t _gpioSysRegEn = {
|
127 |
/* line */ LINE_SYS_REG_EN,
|
128 |
}; |
129 |
ROMCONST apalControlGpio_t moduleGpioSysRegEn = { |
130 |
/* GPIO */ &_gpioSysRegEn,
|
131 |
/* meta */ {
|
132 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
133 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
134 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
135 |
}, |
136 |
}; |
137 |
|
138 |
/**
|
139 |
* @brief IR_INT1 input signal GPIO.
|
140 |
*/
|
141 |
static apalGpio_t _gpioIrInt1 = {
|
142 |
/* line */ LINE_IR_INT1_N,
|
143 |
}; |
144 |
ROMCONST apalControlGpio_t moduleGpioIrInt1 = { |
145 |
/* GPIO */ &_gpioIrInt1,
|
146 |
/* meta */ {
|
147 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
148 |
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
|
149 |
/* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
150 |
/* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
151 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
|
152 |
/* active state */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
153 |
/* interrupt edge */ PCAL6524_LLD_INT_EDGE,
|
154 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
|
155 |
/* active state */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
156 |
/* interrupt edge */ PCAL6524_LLD_INT_EDGE,
|
157 |
#else /* (BOARD_SENSORRING == ?) */ |
158 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
159 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
160 |
#endif /* (BOARD_SENSORRING == ?) */ |
161 |
}, |
162 |
}; |
163 |
|
164 |
/**
|
165 |
* @brief POWER_EN output signal GPIO.
|
166 |
*/
|
167 |
static apalGpio_t _gpioPowerEn = {
|
168 |
/* line */ LINE_POWER_EN,
|
169 |
}; |
170 |
ROMCONST apalControlGpio_t moduleGpioPowerEn = { |
171 |
/* GPIO */ &_gpioPowerEn,
|
172 |
/* meta */ {
|
173 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
174 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
175 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
176 |
}, |
177 |
}; |
178 |
|
179 |
/**
|
180 |
* @brief SYS_UART_DN bidirectional signal GPIO.
|
181 |
*/
|
182 |
static apalGpio_t _gpioSysUartDn = {
|
183 |
/* line */ LINE_SYS_UART_DN,
|
184 |
}; |
185 |
ROMCONST apalControlGpio_t moduleGpioSysUartDn = { |
186 |
/* GPIO */ &_gpioSysUartDn,
|
187 |
/* meta */ {
|
188 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
189 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
190 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
191 |
}, |
192 |
}; |
193 |
|
194 |
/**
|
195 |
* @brief CHARGE_STAT2A input signal GPIO.
|
196 |
*/
|
197 |
static apalGpio_t _gpioChargeStat2A = {
|
198 |
/* line */ LINE_CHARGE_STAT2A,
|
199 |
}; |
200 |
ROMCONST apalControlGpio_t moduleGpioChargeStat2A = { |
201 |
/* GPIO */ &_gpioChargeStat2A,
|
202 |
/* meta */ {
|
203 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
204 |
/* active state */ BQ241xx_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
|
205 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
206 |
}, |
207 |
}; |
208 |
|
209 |
/**
|
210 |
* @brief GAUGE_BATLOW2 input signal GPIO.
|
211 |
*/
|
212 |
static apalGpio_t _gpioGaugeBatLow2 = {
|
213 |
/* line */ LINE_GAUGE_BATLOW2,
|
214 |
}; |
215 |
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2 = { |
216 |
/* GPIO */ &_gpioGaugeBatLow2,
|
217 |
/* meta */ {
|
218 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
219 |
/* active state */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
|
220 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
221 |
}, |
222 |
}; |
223 |
|
224 |
/**
|
225 |
* @brief GAUGE_BATGD2 input signal GPIO.
|
226 |
*/
|
227 |
static apalGpio_t _gpioGaugeBatGd2 = {
|
228 |
/* line */ LINE_GAUGE_BATGD2_N,
|
229 |
}; |
230 |
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2 = { |
231 |
/* GPIO */ &_gpioGaugeBatGd2,
|
232 |
/* meta */ {
|
233 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
234 |
/* active state */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
|
235 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
236 |
}, |
237 |
}; |
238 |
|
239 |
/**
|
240 |
* @brief LED output signal GPIO.
|
241 |
*/
|
242 |
static apalGpio_t _gpioLed = {
|
243 |
/* line */ LINE_LED,
|
244 |
}; |
245 |
ROMCONST apalControlGpio_t moduleGpioLed = { |
246 |
/* GPIO */ &_gpioLed,
|
247 |
/* meta */ {
|
248 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
249 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
250 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
251 |
}, |
252 |
}; |
253 |
|
254 |
/**
|
255 |
* @brief SYS_UART_UP bidirectional signal GPIO.
|
256 |
*/
|
257 |
static apalGpio_t _gpioSysUartUp = {
|
258 |
/* line */ LINE_SYS_UART_UP,
|
259 |
}; |
260 |
ROMCONST apalControlGpio_t moduleGpioSysUartUp = { |
261 |
/* GPIO */ &_gpioSysUartUp,
|
262 |
/* meta */ {
|
263 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
264 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
265 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
266 |
}, |
267 |
}; |
268 |
|
269 |
/**
|
270 |
* @brief CHARGE_STAT1A input signal GPIO.
|
271 |
*/
|
272 |
static apalGpio_t _gpioChargeStat1A = {
|
273 |
/* line */ LINE_CHARGE_STAT1A,
|
274 |
}; |
275 |
ROMCONST apalControlGpio_t moduleGpioChargeStat1A = { |
276 |
/* GPIO */ &_gpioChargeStat1A,
|
277 |
/* meta */ {
|
278 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
279 |
/* active state */ BQ241xx_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
|
280 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
281 |
}, |
282 |
}; |
283 |
|
284 |
/**
|
285 |
* @brief GAUGE_BATLOW1 input signal GPIO.
|
286 |
*/
|
287 |
static apalGpio_t _gpioGaugeBatLow1 = {
|
288 |
/* line */ LINE_GAUGE_BATLOW1,
|
289 |
}; |
290 |
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow1 = { |
291 |
/* GPIO */ &_gpioGaugeBatLow1,
|
292 |
/* meta */ {
|
293 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
294 |
/* active state */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
|
295 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
296 |
}, |
297 |
}; |
298 |
|
299 |
/**
|
300 |
* @brief GAUGE_BATGD1 input signal GPIO.
|
301 |
*/
|
302 |
static apalGpio_t _gpioGaugeBatGd1 = {
|
303 |
/* line */ LINE_GAUGE_BATGD1_N,
|
304 |
}; |
305 |
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd1 = { |
306 |
/* GPIO */ &_gpioGaugeBatGd1,
|
307 |
/* meta */ {
|
308 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
309 |
/* active state */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
|
310 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
311 |
}, |
312 |
}; |
313 |
|
314 |
/**
|
315 |
* @brief CHARG_EN1 output signal GPIO.
|
316 |
*/
|
317 |
static apalGpio_t _gpioChargeEn1 = {
|
318 |
/* line */ LINE_CHARGE_EN1_N,
|
319 |
}; |
320 |
ROMCONST apalControlGpio_t moduleGpioChargeEn1 = { |
321 |
/* GPIO */ &_gpioChargeEn1,
|
322 |
/* meta */ {
|
323 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
324 |
/* active state */ BQ241xx_LLD_ENABLED_GPIO_ACTIVE_STATE,
|
325 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
326 |
}, |
327 |
}; |
328 |
|
329 |
/**
|
330 |
* @brief IR_INT2 input signal GPIO.
|
331 |
*/
|
332 |
static apalGpio_t _gpioIrInt2 = {
|
333 |
/* line */ LINE_IR_INT2_N,
|
334 |
}; |
335 |
ROMCONST apalControlGpio_t moduleGpioIrInt2 = { |
336 |
/* GPIO */ &_gpioIrInt2,
|
337 |
/* meta */ {
|
338 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
339 |
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
|
340 |
/* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
341 |
/* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
342 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
|
343 |
/* active state */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
344 |
/* interrupt edge */ PCAL6524_LLD_INT_EDGE,
|
345 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
|
346 |
/* active state */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
347 |
/* interrupt edge */ PCAL6524_LLD_INT_EDGE,
|
348 |
#else /* (BOARD_SENSORRING == ?) */ |
349 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
350 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
351 |
#endif /* (BOARD_SENSORRING == ?) */ |
352 |
}, |
353 |
}; |
354 |
|
355 |
/**
|
356 |
* @brief TOUCH_INT input signal GPIO.
|
357 |
*/
|
358 |
static apalGpio_t _gpioTouchInt = {
|
359 |
/* line */ LINE_TOUCH_INT_N,
|
360 |
}; |
361 |
ROMCONST apalControlGpio_t moduleGpioTouchInt = { |
362 |
/* GPIO */ &_gpioTouchInt,
|
363 |
/* meta */ {
|
364 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
365 |
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
|
366 |
/* active state */ (MPR121_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
367 |
/* interrupt edge */ MPR121_LLD_INT_EDGE,
|
368 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
|
369 |
/* active state */ (AT42QT1050_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
370 |
/* interrupt edge */ AT42QT1050_LLD_INT_EDGE,
|
371 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
|
372 |
/* active state */ (AT42QT1050_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
373 |
/* interrupt edge */ AT42QT1050_LLD_INT_EDGE,
|
374 |
|