amiro-os / modules / PowerManagement_1-1 / module.c @ 8be006e0
History | View | Annotate | Download (40.8 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 |
#include <amiroos.h> |
30 |
|
31 |
/*===========================================================================*/
|
32 |
/**
|
33 |
* @name Module specific functions
|
34 |
* @{
|
35 |
*/
|
36 |
/*===========================================================================*/
|
37 |
|
38 |
/** @} */
|
39 |
|
40 |
/*===========================================================================*/
|
41 |
/**
|
42 |
* @name ChibiOS/HAL configuration
|
43 |
* @{
|
44 |
*/
|
45 |
/*===========================================================================*/
|
46 |
|
47 |
ADCConversionGroup moduleHalAdcVsysConversionGroup = { |
48 |
/* buffer type */ true, |
49 |
/* number of channels */ 1, |
50 |
/* callback function */ NULL, |
51 |
/* error callback */ NULL, |
52 |
/* CR1 */ ADC_CR1_AWDEN | ADC_CR1_AWDIE,
|
53 |
/* CR2 */ ADC_CR2_SWSTART | ADC_CR2_CONT,
|
54 |
/* SMPR1 */ 0, |
55 |
/* SMPR2 */ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480),
|
56 |
/* HTR */ ADC_HTR_HT,
|
57 |
/* LTR */ 0, |
58 |
/* SQR1 */ ADC_SQR1_NUM_CH(1), |
59 |
/* SQR2 */ 0, |
60 |
/* SQR3 */ ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9),
|
61 |
}; |
62 |
|
63 |
CANConfig moduleHalCanConfig = { |
64 |
/* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
65 |
/* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(3) | CAN_BTR_TS1(15) | CAN_BTR_BRP(1), |
66 |
}; |
67 |
|
68 |
I2CConfig moduleHalI2cSrPm18Pm33GaugeRearConfig = { |
69 |
/* I²C mode */ OPMODE_I2C,
|
70 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
71 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
72 |
}; |
73 |
|
74 |
I2CConfig moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig = { |
75 |
/* I²C mode */ OPMODE_I2C,
|
76 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
77 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
78 |
}; |
79 |
|
80 |
PWMConfig moduleHalPwmBuzzerConfig = { |
81 |
/* frequency */ 1000000, |
82 |
/* period */ 0, |
83 |
/* callback */ NULL, |
84 |
/* channel configurations */ {
|
85 |
/* channel 0 */ {
|
86 |
/* mode */ PWM_OUTPUT_DISABLED,
|
87 |
/* callback */ NULL |
88 |
}, |
89 |
/* channel 1 */ {
|
90 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
91 |
/* callback */ NULL |
92 |
}, |
93 |
/* channel 2 */ {
|
94 |
/* mode */ PWM_OUTPUT_DISABLED,
|
95 |
/* callback */ NULL |
96 |
}, |
97 |
/* channel 3 */ {
|
98 |
/* mode */ PWM_OUTPUT_DISABLED,
|
99 |
/* callback */ NULL |
100 |
}, |
101 |
}, |
102 |
/* TIM CR2 register */ 0, |
103 |
#if STM32_PWM_USE_ADVANCED
|
104 |
/* TIM BDTR register */ 0, |
105 |
#endif
|
106 |
/* TIM DIER register */ 0, |
107 |
}; |
108 |
|
109 |
SerialConfig moduleHalProgIfConfig = { |
110 |
/* bit rate */ 115200, |
111 |
/* CR1 */ 0, |
112 |
/* CR1 */ 0, |
113 |
/* CR1 */ 0, |
114 |
}; |
115 |
|
116 |
/** @} */
|
117 |
|
118 |
/*===========================================================================*/
|
119 |
/**
|
120 |
* @name GPIO definitions
|
121 |
* @{
|
122 |
*/
|
123 |
/*===========================================================================*/
|
124 |
|
125 |
/**
|
126 |
* @brief SYS_REG_EN output signal GPIO.
|
127 |
*/
|
128 |
static apalGpio_t _gpioSysRegEn = {
|
129 |
/* port */ GPIOA,
|
130 |
/* pad */ GPIOA_SYS_REG_EN,
|
131 |
}; |
132 |
ROMCONST apalControlGpio_t moduleSysRegEn = { |
133 |
/* GPIO */ &_gpioSysRegEn,
|
134 |
/* meta */ {
|
135 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
136 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
137 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
138 |
}, |
139 |
}; |
140 |
|
141 |
/**
|
142 |
* @brief IR_INT1 input signal GPIO.
|
143 |
*/
|
144 |
static apalGpio_t _gpioIrInt1 = {
|
145 |
/* port */ GPIOB,
|
146 |
/* pad */ GPIOB_IR_INT1_N,
|
147 |
}; |
148 |
ROMCONST apalControlGpio_t moduleGpioIrInt1 = { |
149 |
/* GPIO */ &_gpioIrInt1,
|
150 |
/* meta */ {
|
151 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
152 |
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
|
153 |
/* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
154 |
/* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
155 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
|
156 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
157 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
158 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
|
159 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
160 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
161 |
#else
|
162 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
163 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
164 |
#endif
|
165 |
}, |
166 |
}; |
167 |
|
168 |
/**
|
169 |
* @brief POWER_EN output signal GPIO.
|
170 |
*/
|
171 |
static apalGpio_t _gpioPowerEn = {
|
172 |
/* port */ GPIOB,
|
173 |
/* pad */ GPIOB_POWER_EN,
|
174 |
}; |
175 |
ROMCONST apalControlGpio_t moduleGpioPowerEn = { |
176 |
/* GPIO */ &_gpioPowerEn,
|
177 |
/* meta */ {
|
178 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
179 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
180 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
181 |
}, |
182 |
}; |
183 |
|
184 |
/**
|
185 |
* @brief SYS_UART_DN bidirectional signal GPIO.
|
186 |
*/
|
187 |
static apalGpio_t _gpioSysUartDn = {
|
188 |
/* port */ GPIOB,
|
189 |
/* pad */ GPIOB_SYS_UART_DN,
|
190 |
}; |
191 |
ROMCONST apalControlGpio_t moduleGpioSysUartDn = { |
192 |
/* GPIO */ &_gpioSysUartDn,
|
193 |
/* meta */ {
|
194 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
195 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
196 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
197 |
}, |
198 |
}; |
199 |
|
200 |
/**
|
201 |
* @brief CHARGE_STAT2A input signal GPIO.
|
202 |
*/
|
203 |
static apalGpio_t _gpioChargeStat2A = {
|
204 |
/* port */ GPIOB,
|
205 |
/* pad */ GPIOB_CHARGE_STAT2A,
|
206 |
}; |
207 |
ROMCONST apalControlGpio_t moduleGpioChargeStat2A = { |
208 |
/* GPIO */ &_gpioChargeStat2A,
|
209 |
/* meta */ {
|
210 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
211 |
/* active state */ BQ24103A_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
|
212 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
213 |
}, |
214 |
}; |
215 |
|
216 |
/**
|
217 |
* @brief GAUGE_BATLOW2 input signal GPIO.
|
218 |
*/
|
219 |
static apalGpio_t _gpioGaugeBatLow2 = {
|
220 |
/* port */ GPIOB,
|
221 |
/* pad */ GPIOB_GAUGE_BATLOW2,
|
222 |
}; |
223 |
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2 = { |
224 |
/* GPIO */ &_gpioGaugeBatLow2,
|
225 |
/* meta */ {
|
226 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
227 |
/* active state */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
|
228 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
229 |
}, |
230 |
}; |
231 |
|
232 |
/**
|
233 |
* @brief GAUGE_BATGD2 input signal GPIO.
|
234 |
*/
|
235 |
static apalGpio_t _gpioGaugeBatGd2 = {
|
236 |
/* port */ GPIOB,
|
237 |
/* pad */ GPIOB_GAUGE_BATGD2_N,
|
238 |
}; |
239 |
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2 = { |
240 |
/* GPIO */ &_gpioGaugeBatGd2,
|
241 |
/* meta */ {
|
242 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
243 |
/* active state */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
|
244 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
245 |
}, |
246 |
}; |
247 |
|
248 |
/**
|
249 |
* @brief LED output signal GPIO.
|
250 |
*/
|
251 |
static apalGpio_t _gpioLed = {
|
252 |
/* port */ GPIOB,
|
253 |
/* pad */ GPIOB_LED,
|
254 |
}; |
255 |
ROMCONST apalControlGpio_t moduleGpioLed = { |
256 |
/* GPIO */ &_gpioLed,
|
257 |
/* meta */ {
|
258 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
259 |
/* active state */ LED_LLD_GPIO_ACTIVE_STATE,
|
260 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
261 |
}, |
262 |
}; |
263 |
|
264 |
/**
|
265 |
* @brief SYS_UART_UP bidirectional signal GPIO.
|
266 |
*/
|
267 |
static apalGpio_t _gpioSysUartUp = {
|
268 |
/* port */ GPIOB,
|
269 |
/* pad */ GPIOB_SYS_UART_UP,
|
270 |
}; |
271 |
ROMCONST apalControlGpio_t moduleGpioSysUartUp = { |
272 |
/* GPIO */ &_gpioSysUartUp,
|
273 |
/* meta */ {
|
274 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
275 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
276 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
277 |
}, |
278 |
}; |
279 |
|
280 |
/**
|
281 |
* @brief CHARGE_STAT1A input signal GPIO.
|
282 |
*/
|
283 |
static apalGpio_t _gpioChargeStat1A = {
|
284 |
/* port */ GPIOC,
|
285 |
/* pad */ GPIOC_CHARGE_STAT1A,
|
286 |
}; |
287 |
ROMCONST apalControlGpio_t moduleGpioChargeStat1A = { |
288 |
/* GPIO */ &_gpioChargeStat1A,
|
289 |
/* meta */ {
|
290 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
291 |
/* active state */ BQ24103A_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
|
292 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
293 |
}, |
294 |
}; |
295 |
|
296 |
/**
|
297 |
* @brief GAUGE_BATLOW1 input signal GPIO.
|
298 |
*/
|
299 |
static apalGpio_t _gpioGaugeBatLow1 = {
|
300 |
/* port */ GPIOC,
|
301 |
/* pad */ GPIOC_GAUGE_BATLOW1,
|
302 |
}; |
303 |
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow1 = { |
304 |
/* GPIO */ &_gpioGaugeBatLow1,
|
305 |
/* meta */ {
|
306 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
307 |
/* active state */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
|
308 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
309 |
}, |
310 |
}; |
311 |
|
312 |
/**
|
313 |
* @brief GAUGE_BATGD1 input signal GPIO.
|
314 |
*/
|
315 |
static apalGpio_t _gpioGaugeBatGd1 = {
|
316 |
/* port */ GPIOC,
|
317 |
/* pad */ GPIOC_GAUGE_BATGD1_N,
|
318 |
}; |
319 |
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd1 = { |
320 |
/* GPIO */ &_gpioGaugeBatGd1,
|
321 |
/* meta */ {
|
322 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
323 |
/* active state */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
|
324 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
325 |
}, |
326 |
}; |
327 |
|
328 |
/**
|
329 |
* @brief CHARG_EN1 output signal GPIO.
|
330 |
*/
|
331 |
static apalGpio_t _gpioChargeEn1 = {
|
332 |
/* port */ GPIOC,
|
333 |
/* pad */ GPIOC_CHARGE_EN1_N,
|
334 |
}; |
335 |
ROMCONST apalControlGpio_t moduleGpioChargeEn1 = { |
336 |
/* GPIO */ &_gpioChargeEn1,
|
337 |
/* meta */ {
|
338 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
339 |
/* active state */ BQ24103A_LLD_ENABLED_GPIO_ACTIVE_STATE,
|
340 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
341 |
}, |
342 |
}; |
343 |
|
344 |
/**
|
345 |
* @brief IR_INT2 input signal GPIO.
|
346 |
*/
|
347 |
static apalGpio_t _gpioIrInt2 = {
|
348 |
/* port */ GPIOC,
|
349 |
/* pad */ GPIOC_IR_INT2_N,
|
350 |
}; |
351 |
ROMCONST apalControlGpio_t moduleGpioIrInt2 = { |
352 |
/* GPIO */ &_gpioIrInt2,
|
353 |
/* meta */ {
|
354 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
355 |
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
|
356 |
/* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
357 |
/* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
358 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
|
359 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
360 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
361 |
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
|
362 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
363 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
364 |
#else
|
365 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
366 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
367 |
#endif
|
368 |
}, |
369 |
}; |
370 |
|
371 |
/**
|
372 |
* @brief TOUCH_INT input signal GPIO.
|
373 |
*/
|
374 |
static apalGpio_t _gpioTouchInt = {
|
375 |
/* port */ GPIOC,
|
376 |
/* pad */ GPIOC_TOUCH_INT_N,
|
377 |
}; |
378 |
ROMCONST apalControlGpio_t moduleGpioTouchInt = { |