amiro-os / modules / DiWheelDrive_1-1 / module.c @ 75d6970a
History | View | Annotate | Download (24.517 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 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 |
#include "module.h" |
20 |
|
21 |
/*===========================================================================*/
|
22 |
/**
|
23 |
* @name Module specific functions
|
24 |
* @{
|
25 |
*/
|
26 |
/*===========================================================================*/
|
27 |
#include <amiroos.h> |
28 |
|
29 |
/**
|
30 |
* @brief Interrupt service routine callback for I/O interrupt signals.
|
31 |
*
|
32 |
* @param extp EXT driver to handle the ISR.
|
33 |
* @param channel Channel on which the interrupt was encountered.
|
34 |
*/
|
35 |
static void _moduleIsrCallback(EXTDriver* extp, expchannel_t channel) { |
36 |
(void)extp;
|
37 |
|
38 |
chSysLockFromISR(); |
39 |
chEvtBroadcastFlagsI(&aos.events.io, (1 << channel));
|
40 |
chSysUnlockFromISR(); |
41 |
|
42 |
return;
|
43 |
} |
44 |
|
45 |
/** @} */
|
46 |
|
47 |
/*===========================================================================*/
|
48 |
/**
|
49 |
* @name ChibiOS/HAL configuration
|
50 |
* @{
|
51 |
*/
|
52 |
/*===========================================================================*/
|
53 |
|
54 |
CANConfig moduleHalCanConfig = { |
55 |
/* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
56 |
/* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1), |
57 |
}; |
58 |
|
59 |
EXTConfig moduleHalExtConfig = { |
60 |
/* channel configrations */ {
|
61 |
/* channel 0 */ {
|
62 |
/* mode */ EXT_CH_MODE_DISABLED,
|
63 |
/* callback */ NULL, |
64 |
}, |
65 |
/* channel 1 */ { // SYS_INT_N/SYS_SYNC_N: automatic interrupt on event |
66 |
/* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
|
67 |
/* callback */ _moduleIsrCallback,
|
68 |
}, |
69 |
/* channel 2 */ { // SYS_WARMRST_N: automatic interrupt when activated |
70 |
/* mode */ EXT_MODE_GPIOD | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
|
71 |
/* callback */ _moduleIsrCallback,
|
72 |
}, |
73 |
/* channel 3 */ { // PATH_DCSTAT: must be enabled explicitely when charging is in progress to detect unexpected voltage drop |
74 |
/* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE,
|
75 |
/* callback */ _moduleIsrCallback,
|
76 |
}, |
77 |
/* channel 4 */ {
|
78 |
/* mode */ EXT_CH_MODE_DISABLED,
|
79 |
/* callback */ NULL, |
80 |
}, |
81 |
/* channel 5 */ { // COMPASS_DRDY: must be enabled explicitely |
82 |
/* mode */ EXT_MODE_GPIOB | APAL2CH_EDGE(HMC5883L_LLD_INT_EDGE),
|
83 |
/* callback */ _moduleIsrCallback,
|
84 |
}, |
85 |
/* channel 6 */ {
|
86 |
/* mode */ EXT_CH_MODE_DISABLED,
|
87 |
/* callback */ NULL, |
88 |
}, |
89 |
/* channel 7 */ {
|
90 |
/* mode */ EXT_CH_MODE_DISABLED,
|
91 |
/* callback */ NULL, |
92 |
}, |
93 |
/* channel 8 */ { // SYS_PD_N: automatic interrupt when activated |
94 |
/* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
|
95 |
/* callback */ _moduleIsrCallback,
|
96 |
}, |
97 |
/* channel 9 */ { // SYS_REG_EN: automatic interrupt when activated |
98 |
/* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
|
99 |
/* callback */ _moduleIsrCallback,
|
100 |
}, |
101 |
/* channel 10 */ {
|
102 |
/* mode */ EXT_CH_MODE_DISABLED,
|
103 |
/* callback */ NULL, |
104 |
}, |
105 |
/* channel 11 */ {
|
106 |
/* mode */ EXT_CH_MODE_DISABLED,
|
107 |
/* callback */ NULL, |
108 |
}, |
109 |
/* channel 12 */ { // IR_INT: must be enabled explicitely |
110 |
/* mode */ EXT_MODE_GPIOB | APAL2CH_EDGE(VCNL4020_LLD_INT_EDGE),
|
111 |
/* callback */ _moduleIsrCallback,
|
112 |
}, |
113 |
/* channel 13 */ { // GYRO_DRDY: must be enabled explicitely |
114 |
/* mode */ EXT_MODE_GPIOB | APAL2CH_EDGE(L3G4200D_LLD_INT_EDGE),
|
115 |
/* callback */ _moduleIsrCallback,
|
116 |
}, |
117 |
/* channel 14 */ { // SYS_UART_UP: automatic interrupt on event |
118 |
/* mode */ EXT_MODE_GPIOB | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
|
119 |
/* callback */ _moduleIsrCallback,
|
120 |
}, |
121 |
/* channel 15 */ { // ACCEL_INT_N: must be enabled explicitely |
122 |
/* mode */ EXT_MODE_GPIOB | APAL2CH_EDGE(LIS331DLH_LLD_INT_EDGE),
|
123 |
/* callback */ _moduleIsrCallback,
|
124 |
}, |
125 |
/* channel 16 */ {
|
126 |
/* mode */ EXT_CH_MODE_DISABLED,
|
127 |
/* callback */ NULL, |
128 |
}, |
129 |
/* channel 17 */ {
|
130 |
/* mode */ EXT_CH_MODE_DISABLED,
|
131 |
/* callback */ NULL, |
132 |
}, |
133 |
/* channel 18 */ {
|
134 |
/* mode */ EXT_CH_MODE_DISABLED,
|
135 |
/* callback */ NULL, |
136 |
}, |
137 |
}, |
138 |
}; |
139 |
|
140 |
I2CConfig moduleHalI2cCompassConfig = { |
141 |
/* I²C mode */ OPMODE_I2C,
|
142 |
/* frequency */ 400000, |
143 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
144 |
}; |
145 |
|
146 |
I2CConfig moduleHalI2cProxEepromPwrmtrConfig = { |
147 |
/* I²C mode */ OPMODE_I2C,
|
148 |
/* frequency */ 400000, |
149 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
150 |
}; |
151 |
|
152 |
PWMConfig moduleHalPwmDriveConfig = { |
153 |
/* frequency */ 7200000, |
154 |
/* period */ 360, |
155 |
/* callback */ NULL, |
156 |
/* channel configurations */ {
|
157 |
/* channel 0 */ {
|
158 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
159 |
/* callback */ NULL |
160 |
}, |
161 |
/* channel 1 */ {
|
162 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
163 |
/* callback */ NULL |
164 |
}, |
165 |
/* channel 2 */ {
|
166 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
167 |
/* callback */ NULL |
168 |
}, |
169 |
/* channel 3 */ {
|
170 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
171 |
/* callback */ NULL |
172 |
}, |
173 |
}, |
174 |
/* TIM CR2 register */ 0, |
175 |
#if STM32_PWM_USE_ADVANCED
|
176 |
/* TIM BDTR register */ 0, |
177 |
#endif
|
178 |
/* TIM DIER register */ 0 |
179 |
}; |
180 |
|
181 |
QEIConfig moduleHalQeiConfig = { |
182 |
/* mode */ QEI_COUNT_BOTH,
|
183 |
/* channel config */ {
|
184 |
/* channel 0 */ {
|
185 |
/* input mode */ QEI_INPUT_NONINVERTED,
|
186 |
}, |
187 |
/* channel 1 */ {
|
188 |
/* input mode */ QEI_INPUT_NONINVERTED,
|
189 |
}, |
190 |
}, |
191 |
/* encoder range */ 0x10000u, |
192 |
}; |
193 |
|
194 |
SerialConfig moduleHalProgIfConfig = { |
195 |
/* bit rate */ 115200, |
196 |
/* CR1 */ 0, |
197 |
/* CR1 */ 0, |
198 |
/* CR1 */ 0, |
199 |
}; |
200 |
|
201 |
SPIConfig moduleHalSpiAccelerometerConfig = { |
202 |
/* callback function pointer */ NULL, |
203 |
/* chip select line port */ GPIOC,
|
204 |
/* chip select line pad number */ GPIOC_ACCEL_SS_N,
|
205 |
/* CR1 */ SPI_CR1_BR_0,
|
206 |
/* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
207 |
}; |
208 |
|
209 |
SPIConfig moduleHalSpiGyroscopeConfig = { |
210 |
/* callback function pointer */ NULL, |
211 |
/* chip select line port */ GPIOC,
|
212 |
/* chip select line pad number */ GPIOC_GYRO_SS_N,
|
213 |
/* CR1 */ SPI_CR1_BR_0,
|
214 |
/* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
215 |
}; |
216 |
|
217 |
/** @} */
|
218 |
|
219 |
/*===========================================================================*/
|
220 |
/**
|
221 |
* @name GPIO definitions
|
222 |
* @{
|
223 |
*/
|
224 |
/*===========================================================================*/
|
225 |
|
226 |
apalGpio_t moduleGpioLed = { |
227 |
/* port */ GPIOA,
|
228 |
/* pad */ GPIOA_LED,
|
229 |
}; |
230 |
|
231 |
apalGpio_t moduleGpioPowerEn = { |
232 |
/* port */GPIOB,
|
233 |
/* pad */ GPIOB_POWER_EN,
|
234 |
}; |
235 |
|
236 |
apalGpio_t moduleGpioCompassDrdy = { |
237 |
/* port */ GPIOB,
|
238 |
/* pad */ GPIOB_COMPASS_DRDY,
|
239 |
}; |
240 |
|
241 |
apalGpio_t moduleGpioIrInt = { |
242 |
/* port */ GPIOB,
|
243 |
/* pad */ GPIOB_IR_INT,
|
244 |
}; |
245 |
|
246 |
apalGpio_t moduleGpioGyroDrdy = { |
247 |
/* port */ GPIOB,
|
248 |
/* pad */ GPIOB_GYRO_DRDY,
|
249 |
}; |
250 |
|
251 |
apalGpio_t moduleGpioSysUartUp = { |
252 |
/* port */ GPIOB,
|
253 |
/* pad */ GPIOB_SYS_UART_UP,
|
254 |
}; |
255 |
|
256 |
apalGpio_t moduleGpioAccelInt = { |
257 |
/* port */ GPIOB,
|
258 |
/* pad */ GPIOB_ACCEL_INT_N,
|
259 |
}; |
260 |
|
261 |
apalGpio_t moduleGpioSysSync = { |
262 |
/* port */ GPIOC,
|
263 |
/* pad */ GPIOC_SYS_INT_N,
|
264 |
}; |
265 |
|
266 |
apalGpio_t moduleGpioPathDcStat = { |
267 |
/* port */ GPIOC,
|
268 |
/* pad */ GPIOC_PATH_DCSTAT,
|
269 |
}; |
270 |
|
271 |
apalGpio_t moduleGpioPathDcEn = { |
272 |
/* port */ GPIOC,
|
273 |
/* pad */ GPIOC_PATH_DCEN,
|
274 |
}; |
275 |
|
276 |
apalGpio_t moduleGpioSysPd = { |
277 |
/* port */ GPIOC,
|
278 |
/* pad */ GPIOC_SYS_PD_N,
|
279 |
}; |
280 |
|
281 |
apalGpio_t moduleGpioSysRegEn = { |
282 |
/* port */ GPIOC,
|
283 |
/* pad */ GPIOC_SYS_REG_EN,
|
284 |
}; |
285 |
|
286 |
apalGpio_t moduleGpioSysWarmrst = { |
287 |
/* port */ GPIOD,
|
288 |
/* pad */ GPIOD_SYS_WARMRST_N,
|
289 |
}; |
290 |
|
291 |
/** @} */
|
292 |
|
293 |
/*===========================================================================*/
|
294 |
/**
|
295 |
* @name AMiRo-OS core configurations
|
296 |
* @{
|
297 |
*/
|
298 |
/*===========================================================================*/
|
299 |
|
300 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
301 |
const char* moduleShellPrompt = "DiWheelDrive"; |
302 |
#endif
|
303 |
|
304 |
/** @} */
|
305 |
|
306 |
/*===========================================================================*/
|
307 |
/**
|
308 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
309 |
* @{
|
310 |
*/
|
311 |
/*===========================================================================*/
|
312 |
|
313 |
|
314 |
apalControlGpio_t moduleSsspGpioPd = { |
315 |
/* GPIO */ &moduleGpioSysPd,
|
316 |
/* meta */ {
|
317 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
318 |
/* edge */ APAL_GPIO_EDGE_FALLING,
|
319 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
320 |
}, |
321 |
}; |
322 |
|
323 |
apalControlGpio_t moduleSsspGpioSync = { |
324 |
/* GPIO */ &moduleGpioSysSync,
|
325 |
/* meta */ {
|
326 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
327 |
/* edge */ APAL_GPIO_EDGE_FALLING,
|
328 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
329 |
}, |
330 |
}; |
331 |
|
332 |
/** @} */
|
333 |
|
334 |
/*===========================================================================*/
|
335 |
/**
|
336 |
* @name Low-level drivers
|
337 |
* @{
|
338 |
*/
|
339 |
/*===========================================================================*/
|
340 |
|
341 |
A3906Driver moduleLldMotors = { |
342 |
/* power enable GPIO */ {
|
343 |
/* GPIO */& moduleGpioPowerEn,
|
344 |
/* meta */ {
|
345 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
346 |
/* edge */ APAL_GPIO_EDGE_NONE,
|
347 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
348 |
}, |
349 |
}, |
350 |
}; |
351 |
|
352 |
AT24C01BNDriver moduleLldEeprom = { |
353 |
/* I2C driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
354 |
/* I²C address */ AT24C01BN_LLD_I2C_ADDR_FIXED,
|
355 |
}; |
356 |
|
357 |
HMC5883LDriver moduleLldCompass = { |
358 |
/* I²C Driver */ &MODULE_HAL_I2C_COMPASS,
|
359 |
}; |
360 |
|
361 |
INA219Driver moduleLldPowerMonitorVdd = { |
362 |
/* I2C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
363 |
/* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
364 |
/* current LSB (uA) */ 0x00u, |
365 |
/* configuration */ NULL, |
366 |
}; |
367 |
|
368 |
L3G4200DDriver moduleLldGyroscope = { |
369 |
/* SPI Driver */ &MODULE_HAL_SPI_MOTION,
|
370 |
}; |
371 |
|
372 |
LEDDriver moduleLldStatusLed = { |
373 |
/* LED enable Gpio */ {
|
374 |
/* GPIO */ &moduleGpioLed,
|
375 |
/* GPIO meta */ {
|
376 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
377 |
/* edge */ APAL_GPIO_EDGE_NONE,
|
378 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
379 |
}, |
380 |
}, |
381 |
}; |
382 |
|
383 |
LIS331DLHDriver moduleLldAccelerometer = { |
384 |
/* SPI Driver */ &MODULE_HAL_SPI_MOTION,
|
385 |
}; |
386 |
|
387 |
LTC4412Driver moduleLldPowerPathController = { |
388 |
/* Control GPIO */ {
|
389 |
/* GPIO */ &moduleGpioPathDcEn,
|
390 |
/* GPIO meta */ {
|
391 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
392 |
/* edge */ APAL_GPIO_EDGE_NONE,
|
393 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
394 |
}, |
395 |
}, |
396 |
/* Status GPIO */ {
|
397 |
/* GPIO */ &moduleGpioPathDcStat,
|
398 |
/* GPIO meta */ {
|
399 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
400 |
/* edge */ APAL_GPIO_EDGE_NONE,
|
401 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
402 |
}, |
403 |
}, |
404 |
}; |
405 |
|
406 |
PCA9544ADriver moduleLldI2cMultiplexer = { |
407 |
/* I²C driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
408 |
/* I²C address */ PCA9544A_LLD_I2C_ADDR_FIXED | PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
409 |
}; |
410 |
|
411 |
TPS62113Driver moduleLldStepDownConverterVdrive = { |
412 |
/* Power enable Gpio */ {
|
413 |
/* GPIO */ &moduleGpioPowerEn,
|
414 |
/* GPIO meta */ {
|
415 |
/* 'power on' state */ APAL_GPIO_ACTIVE_HIGH,
|
416 |
/* edge */ APAL_GPIO_EDGE_NONE,
|
417 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
418 |
}, |
419 |
}, |
420 |
}; |
421 |
|
422 |
VCNL4020Driver moduleLldProximity = { |
423 |
/* I²C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
424 |
}; |
425 |
|
426 |
/** @} */
|
427 |
|
428 |
/*===========================================================================*/
|
429 |
/**
|
430 |
* @name Unit tests (UT)
|
431 |
* @{
|
432 |
*/
|
433 |
/*===========================================================================*/
|
434 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
435 |
#include <string.h> |
436 |
#include <chprintf.h> |
437 |
|
438 |
/* A3906 (motor driver) */
|
439 |
static int _utShellCmdCb_AlldA3906(BaseSequentialStream* stream, int argc, char* argv[]) |
440 |
{ |
441 |
(void)argc;
|
442 |
(void)argv;
|
443 |
aosUtRun(stream, &moduleUtAlldA3906, NULL);
|
444 |
return AOS_OK;
|
445 |
} |
446 |
static ut_a3906data_t _utA3906Data = {
|
447 |
/* driver */ &moduleLldMotors,
|
448 |
/* PWM information */ {
|
449 |
/* driver */ &MODULE_HAL_PWM_DRIVE,
|
450 |
/* channels */ {
|
451 |
/* left wheel forward */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD,
|
452 |
/* left wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD,
|
453 |
/* right wheel forward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD,
|
454 |
/* right wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD,
|
455 |
}, |
456 |
}, |
457 |
/* QEI information */ {
|
458 |
/* left wheel */ &MODULE_HAL_QEI_LEFT_WHEEL,
|
459 |
/* right wheel */ &MODULE_HAL_QEI_RIGHT_WHEEL,
|
460 |
/* increment per revolution */ MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION,
|
461 |
}, |
462 |
/* Wheel diameter */ 0.05571f, |
463 |
/* timeout */ 10* MICROSECONDS_PER_SECOND, |
464 |
}; |
465 |
aos_unittest_t moduleUtAlldA3906 = { |
466 |
/* name */ "A3906", |
467 |
/* info */ "motor driver", |
468 |
/* test function */ utAlldA3906Func,
|
469 |
/* shell command */ {
|
470 |
/* name */ "unittest:MotorDriver", |
471 |
/* callback */ _utShellCmdCb_AlldA3906,
|
472 |
/* next */ NULL, |
473 |
}, |
474 |
/* data */ &_utA3906Data,
|
475 |
}; |
476 |
|
477 |
/* AT24C01BN (EEPROM) */
|
478 |
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[]) |
479 |
{ |
480 |
(void)argc;
|
481 |
(void)argv;
|
482 |
aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
|
483 |
return AOS_OK;
|
484 |
} |
485 |
static ut_at24c01bndata_t _utAt24c01bnData = {
|
486 |
/* driver */ &moduleLldEeprom,
|
487 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
488 |
}; |
489 |
aos_unittest_t moduleUtAlldAt24c01bn = { |
490 |
/* name */ "AT24C01BN-SH-B", |
491 |
/* info */ "1kbit EEPROM", |
492 |
/* test function */ utAlldAt24c01bnFunc,
|
493 |
/* shell command */ {
|
494 |
/* name */ "unittest:EEPROM", |
495 |
/* callback */ _utShellCmdCb_AlldAt24c01bn,
|
496 |
/* next */ NULL, |
497 |
}, |
498 |
/* data */ &_utAt24c01bnData,
|
499 |
}; |
500 |
|
501 |
/* HMC5883L (compass) */
|
502 |
static int _utShellCmdCb_AlldHmc5883l(BaseSequentialStream* stream, int argc, char* argv[]) |
503 |
{ |
504 |
(void)argc;
|
505 |
(void)argv;
|
506 |
extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_COMPASSDRDY); |
507 |
aosUtRun(stream, &moduleUtAlldHmc5883l, NULL);
|
508 |
return AOS_OK;
|
509 |
} |
510 |
static ut_hmc5883ldata_t _utHmc5883lData = {
|
511 |
/* HMC driver */ &moduleLldCompass,
|
512 |
/* event source */ &aos.events.io,
|
513 |
/* event flags */ (1 << MODULE_GPIO_EXTCHANNEL_COMPASSDRDY), |
514 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
515 |
}; |
516 |
aos_unittest_t moduleUtAlldHmc5883l = { |
517 |
/* name */ "HMC5883L", |
518 |
/* info */ "compass", |
519 |
/* test function */ utAlldHmc5883lFunc,
|
520 |
/* shell command */ {
|
521 |
/* name */ "unittest:Compass", |
522 |
/* callback */ _utShellCmdCb_AlldHmc5883l,
|
523 |
/* next */ NULL, |
524 |
}, |
525 |
/* data */ &_utHmc5883lData,
|
526 |
}; |
527 |
|
528 |
/* INA219 (power monitor) */
|
529 |
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[]) |
530 |
{ |
531 |
(void)argc;
|
532 |
(void)argv;
|
533 |
aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
|
534 |
return AOS_OK;
|
535 |
} |
536 |
static ut_ina219data_t _utIna219Data = {
|
537 |
/* driver */ &moduleLldPowerMonitorVdd,
|
538 |
/* expected voltage */ 3.3f, |
539 |
/* tolerance */ 0.05f, |
540 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
541 |
}; |
542 |
aos_unittest_t moduleUtAlldIna219 = { |
543 |
/* name */ "INA219", |
544 |
/* info */ "power monitor", |
545 |
/* test function */ utAlldIna219Func,
|
546 |
/* shell command */ {
|
547 |
/* name */ "unittest:PowerMonitor", |
548 |
/* callback */ _utShellCmdCb_AlldIna219,
|
549 |
/* next */ NULL, |
550 |
}, |
551 |
/* data */ &_utIna219Data,
|
552 |
}; |
553 |
|
554 |
/* L3G4200D (gyroscope) */
|
555 |
static int _utShellCmdCb_AlldL3g4200d(BaseSequentialStream* stream, int argc, char* argv[]) |
556 |
{ |
557 |
(void)argc;
|
558 |
(void)argv;
|
559 |
extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_GYRODRDY); |
560 |
spiStart(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid, ((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->spiconf); |
561 |
aosUtRun(stream, &moduleUtAlldL3g4200d, NULL);
|
562 |
spiStop(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid); |
563 |
return AOS_OK;
|
564 |
} |
565 |
static ut_l3g4200ddata_t _utL3g4200dData = {
|
566 |
/* driver */ &moduleLldGyroscope,
|
567 |
/* SPI configuration */ &moduleHalSpiGyroscopeConfig,
|
568 |
/* event source */ &aos.events.io,
|
569 |
/* event flags */ (1 << MODULE_GPIO_EXTCHANNEL_GYRODRDY), |
570 |
}; |
571 |
aos_unittest_t moduleUtAlldL3g4200d = { |
572 |
/* name */ "L3G4200D", |
573 |
/* info */ "Gyroscope", |
574 |
/* test function */ utAlldL3g4200dFunc,
|
575 |
/* shell command */ {
|
576 |
/* name */ "unittest:Gyroscope", |
577 |
/* callback */ _utShellCmdCb_AlldL3g4200d,
|
578 |
/* next */ NULL, |
579 |
}, |
580 |
/* data */ &_utL3g4200dData,
|
581 |
}; |
582 |
|
583 |
/* Status LED */
|
584 |
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[]) |
585 |
{ |
586 |
(void)argc;
|
587 |
(void)argv;
|
588 |
aosUtRun(stream, &moduleUtAlldLed, NULL);
|
589 |
return AOS_OK;
|
590 |
} |
591 |
aos_unittest_t moduleUtAlldLed = { |
592 |
/* name */ "LED", |
593 |
/* info */ NULL, |
594 |
/* test function */ utAlldLedFunc,
|
595 |
/* shell command */ {
|
596 |
/* name */ "unittest:StatusLED", |
597 |
/* callback */ _utShellCmdCb_AlldLed,
|
598 |
/* next */ NULL, |
599 |
}, |
600 |
/* data */ &moduleLldStatusLed,
|
601 |
}; |
602 |
|
603 |
/* LIS331DLH (accelerometer) */
|
604 |
static int _utShellCmdCb_AlldLis331dlh(BaseSequentialStream* stream, int argc, char* argv[]) |
605 |
{ |
606 |
(void)argc;
|
607 |
(void)argv;
|
608 |
extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_ACCELINT); |
609 |
spiStart(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid, ((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->spiconf); |
610 |
aosUtRun(stream, &moduleUtAlldLis331dlh, NULL);
|
611 |
spiStop(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid); |
612 |
return AOS_OK;
|
613 |
} |
614 |
static ut_lis331dlhdata_t _utLis331dlhData = {
|
615 |
/* driver */ &moduleLldAccelerometer,
|
616 |
/* SPI configuration */ &moduleHalSpiAccelerometerConfig,
|
617 |
/* event source */ &aos.events.io,
|
618 |
/* event flags */ (1 << MODULE_GPIO_EXTCHANNEL_ACCELINT), |
619 |
}; |
620 |
aos_unittest_t moduleUtAlldLis331dlh = { |
621 |
/* name */ "LIS331DLH", |
622 |
/* info */ "Accelerometer", |
623 |
/* test function */ utAlldLis331dlhFunc,
|
624 |
/* shell command */ {
|
625 |
/* name */ "unittest:Accelerometer", |
626 |
/* callback */ _utShellCmdCb_AlldLis331dlh,
|
627 |
/* next */ NULL, |
628 |
}, |
629 |
/* data */ &_utLis331dlhData,
|
630 |
}; |
631 |
|
632 |
/* LTC4412 (power path controller) */
|
633 |
static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[]) |
634 |
{ |
635 |
(void)argc;
|
636 |
(void)argv;
|
637 |
aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
|
638 |
return AOS_OK;
|
639 |
} |
640 |
aos_unittest_t moduleUtAlldLtc4412 = { |
641 |
/* name */ "LTC4412", |
642 |
/* info */ "Power path controller", |
643 |
/* test function */ utAlldLtc4412Func,
|
644 |
/* shell command */ {
|
645 |
/* name */ "unittest:PowerPathController", |
646 |
/* callback */ _utShellCmdCb_AlldLtc4412,
|
647 |
/* next */ NULL, |
648 |
}, |
649 |
/* data */ &moduleLldPowerPathController,
|
650 |
}; |
651 |
|
652 |
/* PCA9544A (I2C multiplexer) */
|
653 |
static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[]) |
654 |
{ |
655 |
(void)argc;
|
656 |
(void)argv;
|
657 |
aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
|
658 |
return AOS_OK;
|
659 |
} |
660 |
static ut_pca9544adata_t _utPca9544aData = {
|
661 |
/* driver */ &moduleLldI2cMultiplexer,
|
662 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
663 |
}; |
664 |
aos_unittest_t moduleUtAlldPca9544a = { |
665 |
/* name */ "PCA9544A", |
666 |
/* info */ "I2C multiplexer", |
667 |
/* test function */ utAlldPca9544aFunc,
|
668 |
/* shell command */ {
|
669 |
/* name */ "unittest:I2CMultiplexer", |
670 |
/* callback */ _utShellCmdCb_AlldPca9544a,
|
671 |
/* next */ NULL, |
672 |
}, |
673 |
/* data */ &_utPca9544aData,
|
674 |
}; |
675 |
|
676 |
/* TPS62113 (step-down converter) */
|
677 |
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[]) |
678 |
{ |
679 |
(void)argc;
|
680 |
(void)argv;
|
681 |
aosUtRun(stream, &moduleUtAlldTps62113, NULL);
|
682 |
return AOS_OK;
|
683 |
} |
684 |
aos_unittest_t moduleUtAlldTps62113 = { |
685 |
/* name */ "TPS62113", |
686 |
/* info */ "Step down converter", |
687 |
/* test function */ utAlldTps62113Func,
|
688 |
/* shell command */ {
|
689 |
/* name */ "unittest:StepDownConverter", |
690 |
/* callback */ _utShellCmdCb_AlldTps62113,
|
691 |
/* next */ NULL, |
692 |
}, |
693 |
/* data */ &moduleLldStepDownConverterVdrive,
|
694 |
}; |
695 |
|
696 |
/* VCNL4020 (proximity sensor) */
|
697 |
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl) |
698 |
{ |
699 |
uint8_t intstatus; |
700 |
vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
|
701 |
vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
702 |
if (intstatus) {
|
703 |
vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
704 |
} |
705 |
return;
|
706 |
} |
707 |
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[]) |
708 |
{ |
709 |
enum {
|
710 |
UNKNOWN, |
711 |
FL, FR, WL, WR, |
712 |
} sensor = UNKNOWN; |
713 |
// evaluate arguments
|
714 |
if (argc == 2) { |
715 |
if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) { |
716 |
sensor = FL; |
717 |
} else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) { |
718 |
sensor = FR; |
719 |
} else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) { |
720 |
sensor = WL; |
721 |
} else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) { |
722 |
sensor = WR; |
723 |
} |
724 |
} |
725 |
if (sensor != UNKNOWN) {
|
726 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
727 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
728 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
729 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
730 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
731 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
732 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
733 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
734 |
extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_IRINT); |
735 |
switch (sensor) {
|
736 |
case FL:
|
737 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
738 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "front left snesor");
|
739 |
break;
|
740 |
case FR:
|
741 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
742 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
|
743 |
break;
|
744 |
case WL:
|
745 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
746 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
|
747 |
break;
|
748 |
case WR:
|
749 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
750 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
|
751 |
break;
|
752 |
default:
|
753 |
break;
|
754 |
} |
755 |
return AOS_OK;
|
756 |
} |
757 |
// print help
|
758 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
759 |
chprintf(stream, "Options:\n");
|
760 |
chprintf(stream, " --frontleft, -fl\n");
|
761 |
chprintf(stream, " Test front left proximity sensor.\n");
|
762 |
chprintf(stream, " --frontrigt, -fr\n");
|
763 |
chprintf(stream, " Test front right proximity sensor.\n");
|
764 |
chprintf(stream, " --wheelleft, -wl\n");
|
765 |
chprintf(stream, " Test left wheel proximity sensor.\n");
|
766 |
chprintf(stream, " --wheelright, -wr\n");
|
767 |
chprintf(stream, " Test right wheel proximity sensor.\n");
|
768 |
return AOS_INVALID_ARGUMENTS;
|
769 |
} |
770 |
static ut_vcnl4020data_t _utVcnl4020Data = {
|
771 |
/* driver */ &moduleLldProximity,
|
772 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
773 |
/* event source */ &aos.events.io,
|
774 |
/* event flags */ (1 << MODULE_GPIO_EXTCHANNEL_IRINT), |
775 |
}; |
776 |
aos_unittest_t moduleUtAlldVcnl4020 = { |
777 |
/* name */ "VCNL4020", |
778 |
/* info */ "proximity sensor", |
779 |
/* test function */ utAlldVcnl4020Func,
|
780 |
/* shell command */ {
|
781 |
/* name */ "unittest:Proximity", |
782 |
/* callback */ _utShellCmdCb_AlldVcnl4020,
|
783 |
/* next */ NULL, |
784 |
}, |
785 |
/* data */ &_utVcnl4020Data,
|
786 |
}; |
787 |
|
788 |
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
789 |
|
790 |
/** @} */
|