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