amiro-os / modules / DiWheelDrive_1-2 / module.c @ 5668089d
History | View | Annotate | Download (20.203 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 DiWheelDrive module.
|
22 |
*
|
23 |
* @addtogroup diwheeldrive_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 |
CANConfig moduleHalCanConfig = { |
46 |
/* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
47 |
/* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1), |
48 |
}; |
49 |
|
50 |
I2CConfig moduleHalI2cImuConfig = { |
51 |
/* I²C mode */ OPMODE_I2C,
|
52 |
/* frequency */ 400000, |
53 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
54 |
}; |
55 |
|
56 |
I2CConfig moduleHalI2cProxEepromPwrmtrConfig = { |
57 |
/* I²C mode */ OPMODE_I2C,
|
58 |
/* frequency */ 400000, |
59 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
60 |
}; |
61 |
|
62 |
PWMConfig moduleHalPwmDriveConfig = { |
63 |
/* frequency */ 7200000, |
64 |
/* period */ 360, |
65 |
/* callback */ NULL, |
66 |
/* channel configurations */ {
|
67 |
/* channel 0 */ {
|
68 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
69 |
/* callback */ NULL |
70 |
}, |
71 |
/* channel 1 */ {
|
72 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
73 |
/* callback */ NULL |
74 |
}, |
75 |
/* channel 2 */ {
|
76 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
77 |
/* callback */ NULL |
78 |
}, |
79 |
/* channel 3 */ {
|
80 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
81 |
/* callback */ NULL |
82 |
}, |
83 |
}, |
84 |
/* TIM CR2 register */ 0, |
85 |
#if (STM32_PWM_USE_ADVANCED == TRUE)
|
86 |
/* TIM BDTR register */ 0, |
87 |
#endif /* (STM32_PWM_USE_ADVANCED == TRUE) */ |
88 |
/* TIM DIER register */ 0 |
89 |
}; |
90 |
|
91 |
QEIConfig moduleHalQeiConfig = { |
92 |
/* mode */ QEI_COUNT_BOTH,
|
93 |
/* channel config */ {
|
94 |
/* channel 0 */ {
|
95 |
/* input mode */ QEI_INPUT_NONINVERTED,
|
96 |
}, |
97 |
/* channel 1 */ {
|
98 |
/* input mode */ QEI_INPUT_NONINVERTED,
|
99 |
}, |
100 |
}, |
101 |
/* encoder range */ 0x10000u, |
102 |
}; |
103 |
|
104 |
SerialConfig moduleHalProgIfConfig = { |
105 |
/* bit rate */ 115200, |
106 |
/* CR1 */ 0, |
107 |
/* CR1 */ 0, |
108 |
/* CR1 */ 0, |
109 |
}; |
110 |
|
111 |
/** @} */
|
112 |
|
113 |
/*===========================================================================*/
|
114 |
/**
|
115 |
* @name GPIO definitions
|
116 |
* @{
|
117 |
*/
|
118 |
/*===========================================================================*/
|
119 |
|
120 |
/**
|
121 |
* @brief LED output signal GPIO.
|
122 |
*/
|
123 |
static apalGpio_t _gpioLed = {
|
124 |
/* line */ LINE_LED,
|
125 |
}; |
126 |
ROMCONST apalControlGpio_t moduleGpioLed = { |
127 |
/* GPIO */ &_gpioLed,
|
128 |
/* meta */ {
|
129 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
130 |
/* active state */ LED_LLD_GPIO_ACTIVE_STATE,
|
131 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
132 |
}, |
133 |
}; |
134 |
|
135 |
/**
|
136 |
* @brief POWER_EN output signal GPIO.
|
137 |
*/
|
138 |
static apalGpio_t _gpioPowerEn = {
|
139 |
/* line */ LINE_POWER_EN,
|
140 |
}; |
141 |
ROMCONST apalControlGpio_t moduleGpioPowerEn = { |
142 |
/* GPIO */ &_gpioPowerEn,
|
143 |
/* meta */ {
|
144 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
145 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
146 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
147 |
}, |
148 |
}; |
149 |
|
150 |
/**
|
151 |
* @brief IR_INT input signal GPIO.
|
152 |
*/
|
153 |
static apalGpio_t _gpioIrInt = {
|
154 |
/* line */ LINE_IR_INT,
|
155 |
}; |
156 |
ROMCONST apalControlGpio_t moduleGpioIrInt = { |
157 |
/* GPIO */ &_gpioIrInt,
|
158 |
/* meta */ {
|
159 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
160 |
/* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
161 |
/* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
162 |
}, |
163 |
}; |
164 |
|
165 |
/**
|
166 |
* @brief SYS_UART_UP bidirectional signal GPIO.
|
167 |
*/
|
168 |
static apalGpio_t _gpioSysUartUp = {
|
169 |
/* line */ LINE_SYS_UART_UP,
|
170 |
}; |
171 |
ROMCONST apalControlGpio_t moduleGpioSysUartUp = { |
172 |
/* GPIO */ &_gpioSysUartUp,
|
173 |
/* meta */ {
|
174 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
175 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
176 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
177 |
}, |
178 |
}; |
179 |
|
180 |
/**
|
181 |
* @brief IMU_INT input signal GPIO.
|
182 |
*/
|
183 |
static apalGpio_t _gpioImuInt = {
|
184 |
/* line */ LINE_IMU_INT,
|
185 |
}; |
186 |
ROMCONST apalControlGpio_t moduleGpioImuInt = { |
187 |
/* GPIO */ &_gpioImuInt,
|
188 |
/* meta */ {
|
189 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
190 |
/* active state */ APAL_GPIO_ACTIVE_HIGH, // TODO |
191 |
/* interrupt edge */ APAL_GPIO_EDGE_RISING, // TODO |
192 |
}, |
193 |
}; |
194 |
|
195 |
/**
|
196 |
* @brief SYS_SNYC bidirectional signal GPIO.
|
197 |
*/
|
198 |
static apalGpio_t _gpioSysSync = {
|
199 |
/* line */ LINE_SYS_INT_N,
|
200 |
}; |
201 |
ROMCONST apalControlGpio_t moduleGpioSysSync = { |
202 |
/* GPIO */ &_gpioSysSync,
|
203 |
/* meta */ {
|
204 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
205 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
206 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
207 |
}, |
208 |
}; |
209 |
|
210 |
/**
|
211 |
* @brief IMU_RESET output signal GPIO.
|
212 |
*/
|
213 |
static apalGpio_t _gpioImuReset = {
|
214 |
/* line */ LINE_IMU_RESET_N,
|
215 |
}; |
216 |
ROMCONST apalControlGpio_t moduleGpioImuReset = { |
217 |
/* GPIO */ &_gpioImuReset,
|
218 |
/* meta */ {
|
219 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
220 |
/* active state */ APAL_GPIO_ACTIVE_LOW, // TODO |
221 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO |
222 |
}, |
223 |
}; |
224 |
|
225 |
/**
|
226 |
* @brief PATH_DCSTAT input signal GPIO.
|
227 |
*/
|
228 |
static apalGpio_t _gpioPathDcStat = {
|
229 |
/* line */ LINE_PATH_DCSTAT,
|
230 |
}; |
231 |
ROMCONST apalControlGpio_t moduleGpioPathDcStat = { |
232 |
/* GPIO */ &_gpioPathDcStat,
|
233 |
/* meta */ {
|
234 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
235 |
/* active state */ LTC4412_LLD_STAT_ACTIVE_STATE,
|
236 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
237 |
}, |
238 |
}; |
239 |
|
240 |
/**
|
241 |
* @brief PATH_DCEN output signal GPIO.
|
242 |
*/
|
243 |
static apalGpio_t _gpioPathDcEn = {
|
244 |
/* line */ LINE_PATH_DCEN,
|
245 |
}; |
246 |
ROMCONST apalControlGpio_t moduleGpioPathDcEn = { |
247 |
/* GPIO */ &_gpioPathDcEn,
|
248 |
/* meta */ {
|
249 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
250 |
/* active state */ LTC4412_LLD_CTRL_ACTIVE_STATE,
|
251 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
252 |
}, |
253 |
}; |
254 |
|
255 |
/**
|
256 |
* @brief SYS_PD bidirectional signal GPIO.
|
257 |
*/
|
258 |
static apalGpio_t _gpioSysPd = {
|
259 |
/* line */ LINE_SYS_PD_N,
|
260 |
}; |
261 |
ROMCONST apalControlGpio_t moduleGpioSysPd = { |
262 |
/* GPIO */ &_gpioSysPd,
|
263 |
/* meta */ {
|
264 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
265 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
266 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
267 |
}, |
268 |
}; |
269 |
|
270 |
/**
|
271 |
* @brief SYS_REG_EN input signal GPIO.
|
272 |
*/
|
273 |
static apalGpio_t _gpioSysRegEn = {
|
274 |
/* line */ LINE_SYS_REG_EN,
|
275 |
}; |
276 |
ROMCONST apalControlGpio_t moduleGpioSysRegEn = { |
277 |
/* GPIO */ &_gpioSysRegEn,
|
278 |
/* meta */ {
|
279 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
280 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
281 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
282 |
}, |
283 |
}; |
284 |
|
285 |
/**
|
286 |
* @brief IMU_BOOT_LOAD output signal GPIO.
|
287 |
*/
|
288 |
static apalGpio_t _gpioImuBootLoad = {
|
289 |
/* line */ LINE_IMU_BOOT_LOAD_N,
|
290 |
}; |
291 |
ROMCONST apalControlGpio_t moduleGpioImuBootLoad = { |
292 |
/* GPIO */ &_gpioImuBootLoad,
|
293 |
/* meta */ {
|
294 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
295 |
/* active state */ APAL_GPIO_ACTIVE_LOW, // TODO |
296 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO |
297 |
}, |
298 |
}; |
299 |
|
300 |
/**
|
301 |
* @brief IMU_BL_IND input signal GPIO.
|
302 |
*/
|
303 |
static apalGpio_t _gpioImuBlInd = {
|
304 |
/* line */ LINE_IMU_BL_IND,
|
305 |
}; |
306 |
ROMCONST apalControlGpio_t moduleGpioImuBlInd = { |
307 |
/* GPIO */ &_gpioImuBlInd,
|
308 |
/* meta */ {
|
309 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
310 |
/* active state */ APAL_GPIO_ACTIVE_HIGH, // TODO |
311 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO |
312 |
}, |
313 |
}; |
314 |
|
315 |
/**
|
316 |
* @brief SYS_WARMRST bidirectional signal GPIO.
|
317 |
*/
|
318 |
static apalGpio_t _gpioSysWarmrst = {
|
319 |
/* line */ LINE_SYS_WARMRST_N,
|
320 |
}; |
321 |
ROMCONST apalControlGpio_t moduleGpioSysWarmrst = { |
322 |
/* GPIO */ &_gpioSysWarmrst,
|
323 |
/* meta */ {
|
324 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
325 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
326 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
327 |
}, |
328 |
}; |
329 |
|
330 |
/** @} */
|
331 |
|
332 |
/*===========================================================================*/
|
333 |
/**
|
334 |
* @name AMiRo-OS core configurations
|
335 |
* @{
|
336 |
*/
|
337 |
/*===========================================================================*/
|
338 |
|
339 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
340 |
ROMCONST char* moduleShellPrompt = "DiWheelDrive"; |
341 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
342 |
|
343 |
/** @} */
|
344 |
|
345 |
/*===========================================================================*/
|
346 |
/**
|
347 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
348 |
* @{
|
349 |
*/
|
350 |
/*===========================================================================*/
|
351 |
|
352 |
/** @} */
|
353 |
|
354 |
/*===========================================================================*/
|
355 |
/**
|
356 |
* @name Low-level drivers
|
357 |
* @{
|
358 |
*/
|
359 |
/*===========================================================================*/
|
360 |
|
361 |
A3906Driver moduleLldMotors = { |
362 |
/* power enable GPIO */ &moduleGpioPowerEn,
|
363 |
}; |
364 |
|
365 |
AT24C01BDriver moduleLldEeprom = { |
366 |
/* I2C driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
367 |
/* I²C address */ AT24C01B_LLD_I2C_ADDR_FIXED,
|
368 |
}; |
369 |
|
370 |
INA219Driver moduleLldPowerMonitorVdd = { |
371 |
/* I2C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
372 |
/* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
373 |
/* current LSB (uA) */ 0x00u, |
374 |
/* configuration */ NULL, |
375 |
}; |
376 |
|
377 |
LEDDriver moduleLldStatusLed = { |
378 |
/* LED enable Gpio */ &moduleGpioLed,
|
379 |
}; |
380 |
|
381 |
LTC4412Driver moduleLldPowerPathController = { |
382 |
/* Control GPIO */ &moduleGpioPathDcEn,
|
383 |
/* Status GPIO */ &moduleGpioPathDcStat,
|
384 |
}; |
385 |
|
386 |
PCA9544ADriver moduleLldI2cMultiplexer = { |
387 |
/* I²C driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
388 |
/* I²C address */ PCA9544A_LLD_I2C_ADDR_FIXED | PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
389 |
}; |
390 |
|
391 |
TPS6211xDriver moduleLldStepDownConverterVdrive = { |
392 |
/* Power enable Gpio */ &moduleGpioPowerEn,
|
393 |
}; |
394 |
|
395 |
VCNL4020Driver moduleLldProximity = { |
396 |
/* I²C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
397 |
}; |
398 |
|
399 |
/** @} */
|
400 |
|
401 |
/*===========================================================================*/
|
402 |
/**
|
403 |
* @name Unit tests (UT)
|
404 |
* @{
|
405 |
*/
|
406 |
/*===========================================================================*/
|
407 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
408 |
#include <string.h> |
409 |
|
410 |
/*
|
411 |
* A3906 (motor driver)
|
412 |
*/
|
413 |
static int _utShellCmdCb_AlldA3906(BaseSequentialStream* stream, int argc, char* argv[]) |
414 |
{ |
415 |
(void)argc;
|
416 |
(void)argv;
|
417 |
aosUtRun(stream, &moduleUtAlldA3906, NULL);
|
418 |
return AOS_OK;
|
419 |
} |
420 |
static ut_a3906data_t _utA3906Data = {
|
421 |
/* driver */ &moduleLldMotors,
|
422 |
/* PWM information */ {
|
423 |
/* driver */ &MODULE_HAL_PWM_DRIVE,
|
424 |
/* channels */ {
|
425 |
/* left wheel forward */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD,
|
426 |
/* left wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD,
|
427 |
/* right wheel forward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD,
|
428 |
/* right wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD,
|
429 |
}, |
430 |
}, |
431 |
/* QEI information */ {
|
432 |
/* left wheel */ &MODULE_HAL_QEI_LEFT_WHEEL,
|
433 |
/* right wheel */ &MODULE_HAL_QEI_RIGHT_WHEEL,
|
434 |
/* increment per revolution */ MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION,
|
435 |
}, |
436 |
/* Wheel diameter */ {
|
437 |
/* left wheel */ 0.05571f, |
438 |
/* right wheel */ 0.05571f, |
439 |
}, |
440 |
/* timeout */ 10 * MICROSECONDS_PER_SECOND, |
441 |
}; |
442 |
aos_unittest_t moduleUtAlldA3906 = { |
443 |
/* name */ "A3906", |
444 |
/* info */ "motor driver", |
445 |
/* test function */ utAlldA3906Func,
|
446 |
/* shell command */ {
|
447 |
/* name */ "unittest:MotorDriver", |
448 |
/* callback */ _utShellCmdCb_AlldA3906,
|
449 |
/* next */ NULL, |
450 |
}, |
451 |
/* data */ &_utA3906Data,
|
452 |
}; |
453 |
|
454 |
/*
|
455 |
* AT24C01B (EEPROM)
|
456 |
*/
|
457 |
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[]) |
458 |
{ |
459 |
(void)argc;
|
460 |
(void)argv;
|
461 |
aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
|
462 |
return AOS_OK;
|
463 |
} |
464 |
static ut_at24c01bdata_t _utAlldAt24c01bData = {
|
465 |
/* driver */ &moduleLldEeprom,
|
466 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
467 |
}; |
468 |
aos_unittest_t moduleUtAlldAt24c01b = { |
469 |
/* name */ "AT24C01B", |
470 |
/* info */ "1kbit EEPROM", |
471 |
/* test function */ utAlldAt24c01bFunc,
|
472 |
/* shell command */ {
|
473 |
/* name */ "unittest:EEPROM", |
474 |
/* callback */ _utShellCmdCb_AlldAt24c01b,
|
475 |
/* next */ NULL, |
476 |
}, |
477 |
/* data */ &_utAlldAt24c01bData,
|
478 |
}; |
479 |
|
480 |
/*
|
481 |
* INA219 (power monitor)
|
482 |
*/
|
483 |
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[]) |
484 |
{ |
485 |
(void)argc;
|
486 |
(void)argv;
|
487 |
aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
|
488 |
return AOS_OK;
|
489 |
} |
490 |
static ut_ina219data_t _utIna219Data = {
|
491 |
/* driver */ &moduleLldPowerMonitorVdd,
|
492 |
/* expected voltage */ 3.3f, |
493 |
/* tolerance */ 0.05f, |
494 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
495 |
}; |
496 |
aos_unittest_t moduleUtAlldIna219 = { |
497 |
/* name */ "INA219", |
498 |
/* info */ "power monitor", |
499 |
/* test function */ utAlldIna219Func,
|
500 |
/* shell command */ {
|
501 |
/* name */ "unittest:PowerMonitor", |
502 |
/* callback */ _utShellCmdCb_AlldIna219,
|
503 |
/* next */ NULL, |
504 |
}, |
505 |
/* data */ &_utIna219Data,
|
506 |
}; |
507 |
|
508 |
/*
|
509 |
* Status LED
|
510 |
*/
|
511 |
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[]) |
512 |
{ |
513 |
(void)argc;
|
514 |
(void)argv;
|
515 |
aosUtRun(stream, &moduleUtAlldLed, NULL);
|
516 |
return AOS_OK;
|
517 |
} |
518 |
aos_unittest_t moduleUtAlldLed = { |
519 |
/* name */ "LED", |
520 |
/* info */ NULL, |
521 |
/* test function */ utAlldLedFunc,
|
522 |
/* shell command */ {
|
523 |
/* name */ "unittest:StatusLED", |
524 |
/* callback */ _utShellCmdCb_AlldLed,
|
525 |
/* next */ NULL, |
526 |
}, |
527 |
/* data */ &moduleLldStatusLed,
|
528 |
}; |
529 |
|
530 |
/*
|
531 |
* LTC4412 (power path controller)
|
532 |
*/
|
533 |
static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[]) |
534 |
{ |
535 |
(void)argc;
|
536 |
(void)argv;
|
537 |
aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
|
538 |
return AOS_OK;
|
539 |
} |
540 |
aos_unittest_t moduleUtAlldLtc4412 = { |
541 |
/* name */ "LTC4412", |
542 |
/* info */ "Power path controller", |
543 |
/* test function */ utAlldLtc4412Func,
|
544 |
/* shell command */ {
|
545 |
/* name */ "unittest:PowerPathController", |
546 |
/* callback */ _utShellCmdCb_AlldLtc4412,
|
547 |
/* next */ NULL, |
548 |
}, |
549 |
/* data */ &moduleLldPowerPathController,
|
550 |
}; |
551 |
|
552 |
/*
|
553 |
* PCA9544A (I2C multiplexer)
|
554 |
*/
|
555 |
static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[]) |
556 |
{ |
557 |
(void)argc;
|
558 |
(void)argv;
|
559 |
aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
|
560 |
return AOS_OK;
|
561 |
} |
562 |
static ut_pca9544adata_t _utPca9544aData = {
|
563 |
/* driver */ &moduleLldI2cMultiplexer,
|
564 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
565 |
}; |
566 |
aos_unittest_t moduleUtAlldPca9544a = { |
567 |
/* name */ "PCA9544A", |
568 |
/* info */ "I2C multiplexer", |
569 |
/* test function */ utAlldPca9544aFunc,
|
570 |
/* shell command */ {
|
571 |
/* name */ "unittest:I2CMultiplexer", |
572 |
/* callback */ _utShellCmdCb_AlldPca9544a,
|
573 |
/* next */ NULL, |
574 |
}, |
575 |
/* data */ &_utPca9544aData,
|
576 |
}; |
577 |
|
578 |
/*
|
579 |
* TPS62113 (step-down converter)
|
580 |
*/
|
581 |
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[]) |
582 |
{ |
583 |
(void)argc;
|
584 |
(void)argv;
|
585 |
aosUtRun(stream, &moduleUtAlldTps62113, NULL);
|
586 |
return AOS_OK;
|
587 |
} |
588 |
aos_unittest_t moduleUtAlldTps62113 = { |
589 |
/* name */ "TPS62113", |
590 |
/* info */ "Step down converter", |
591 |
/* test function */ utAlldTps6211xFunc,
|
592 |
/* shell command */ {
|
593 |
/* name */ "unittest:StepDownConverter", |
594 |
/* callback */ _utShellCmdCb_AlldTps62113,
|
595 |
/* next */ NULL, |
596 |
}, |
597 |
/* data */ &moduleLldStepDownConverterVdrive,
|
598 |
}; |
599 |
|
600 |
/*
|
601 |
* VCNL4020 (proximity sensor)
|
602 |
*/
|
603 |
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl) |
604 |
{ |
605 |
uint8_t intstatus; |
606 |
vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
|
607 |
vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
608 |
if (intstatus) {
|
609 |
vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
610 |
} |
611 |
return;
|
612 |
} |
613 |
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[]) |
614 |
{ |
615 |
enum {
|
616 |
UNKNOWN, |
617 |
FL, FR, WL, WR, |
618 |
} sensor = UNKNOWN; |
619 |
// evaluate arguments
|
620 |
if (argc == 2) { |
621 |
if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) { |
622 |
sensor = FL; |
623 |
} else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) { |
624 |
sensor = FR; |
625 |
} else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) { |
626 |
sensor = WL; |
627 |
} else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) { |
628 |
sensor = WR; |
629 |
} |
630 |
} |
631 |
if (sensor != UNKNOWN) {
|
632 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
633 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
634 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
635 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
636 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
637 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
638 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
639 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
640 |
switch (sensor) {
|
641 |
case FL:
|
642 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
643 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "front left sensor");
|
644 |
break;
|
645 |
case FR:
|
646 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
647 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
|
648 |
break;
|
649 |
case WL:
|
650 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
651 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
|
652 |
break;
|
653 |
case WR:
|
654 |
pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
655 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
|
656 |
break;
|
657 |
default:
|
658 |
break;
|
659 |
} |
660 |
return AOS_OK;
|
661 |
} |
662 |
// print help
|
663 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
664 |
chprintf(stream, "Options:\n");
|
665 |
chprintf(stream, " --frontleft, -fl\n");
|
666 |
chprintf(stream, " Test front left proximity sensor.\n");
|
667 |
chprintf(stream, " --frontrigt, -fr\n");
|
668 |
chprintf(stream, " Test front right proximity sensor.\n");
|
669 |
chprintf(stream, " --wheelleft, -wl\n");
|
670 |
chprintf(stream, " Test left wheel proximity sensor.\n");
|
671 |
chprintf(stream, " --wheelright, -wr\n");
|
672 |
chprintf(stream, " Test right wheel proximity sensor.\n");
|
673 |
return AOS_INVALIDARGUMENTS;
|
674 |
} |
675 |
static ut_vcnl4020data_t _utVcnl4020Data = {
|
676 |
/* driver */ &moduleLldProximity,
|
677 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
678 |
/* event source */ &aos.events.io,
|
679 |
/* event flags */ MODULE_OS_IOEVENTFLAGS_IRINT,
|
680 |
}; |
681 |
aos_unittest_t moduleUtAlldVcnl4020 = { |
682 |
/* name */ "VCNL4020", |
683 |
/* info */ "proximity sensor", |
684 |
/* test function */ utAlldVcnl4020Func,
|
685 |
/* shell command */ {
|
686 |
/* name */ "unittest:Proximity", |
687 |
/* callback */ _utShellCmdCb_AlldVcnl4020,
|
688 |
/* next */ NULL, |
689 |
}, |
690 |
/* data */ &_utVcnl4020Data,
|
691 |
}; |
692 |
|
693 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
694 |
|
695 |
/** @} */
|
696 |
/** @} */
|