Revision ee884101
modules/LightRing_1-2/alldconf.h | ||
---|---|---|
49 | 49 |
#define AMIROLLD_CFG_AT24C01B 1 |
50 | 50 |
|
51 | 51 |
/** |
52 |
* @brief Enable flag for the INA219 power monitor. |
|
53 |
*/ |
|
54 |
#define AMIROLLD_CFG_INA219 1 |
|
55 |
|
|
56 |
/** |
|
52 | 57 |
* @brief Enable flag for the status LED. |
53 | 58 |
*/ |
54 | 59 |
#define AMIROLLD_CFG_LED 1 |
55 | 60 |
|
56 | 61 |
/** |
57 |
* @brief Enable flag for the TLC5947 LED driver.
|
|
62 |
* @brief Enable flag for the MIC94042 high-side load switches.
|
|
58 | 63 |
*/ |
59 |
#define AMIROLLD_CFG_TLC5947 1 |
|
60 |
#define TLC5947_LLD_CHAINED 3 |
|
64 |
#define AMIROLLD_CFG_MIC9404x 1 |
|
61 | 65 |
|
62 | 66 |
/** |
63 | 67 |
* @brief Enable flag for the SN75C3221E RS232 Transceiver. |
... | ... | |
65 | 69 |
#define AMIROLLD_CFG_SNx5C3221E 1 |
66 | 70 |
|
67 | 71 |
/** |
68 |
* @brief Enable flag for the MIC94042 high-side load switches. |
|
69 |
*/ |
|
70 |
#define AMIROLLD_CFG_MIC9404x 1 |
|
71 |
|
|
72 |
/** |
|
73 |
* @brief Enable flag for the INA219 power monitor. |
|
72 |
* @brief Enable flag for the TLC5947 LED driver. |
|
74 | 73 |
*/ |
75 |
#define AMIROLLD_CFG_INA219 1 |
|
74 |
#define AMIROLLD_CFG_TLC5947 1 |
|
75 |
#define TLC5947_LLD_CHAINED 3 |
|
76 | 76 |
|
77 | 77 |
#endif /* ALLDCONF_H */ |
78 | 78 |
|
modules/LightRing_1-2/module.c | ||
---|---|---|
47 | 47 |
/* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1), |
48 | 48 |
}; |
49 | 49 |
|
50 |
I2CConfig moduleHalI2cEepromBreakoutConfig = { |
|
50 |
I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig = {
|
|
51 | 51 |
/* I²C mode */ OPMODE_I2C, |
52 | 52 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
53 | 53 |
/* duty cycle */ FAST_DUTY_CYCLE_2, |
... | ... | |
120 | 120 |
/* GPIO */ &_gpioSwV33En, |
121 | 121 |
/* meta */ { |
122 | 122 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT, |
123 |
/* active state */ APAL_GPIO_ACTIVE_HIGH, //TODO
|
|
123 |
/* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
|
124 | 124 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE, |
125 | 125 |
}, |
126 | 126 |
}; |
... | ... | |
136 | 136 |
/* GPIO */ &_gpioSwV42En, |
137 | 137 |
/* meta */ { |
138 | 138 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT, |
139 |
/* active state */ APAL_GPIO_ACTIVE_HIGH, //TODO
|
|
139 |
/* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
|
140 | 140 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE, |
141 | 141 |
}, |
142 | 142 |
}; |
... | ... | |
152 | 152 |
/* GPIO */ &_gpioSwV50En, |
153 | 153 |
/* meta */ { |
154 | 154 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT, |
155 |
/* active state */ APAL_GPIO_ACTIVE_HIGH, //TODO
|
|
155 |
/* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
|
156 | 156 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE, |
157 | 157 |
}, |
158 | 158 |
}; |
... | ... | |
344 | 344 |
/* GPIO */ &_gpioSwV18En, |
345 | 345 |
/* meta */ { |
346 | 346 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT, |
347 |
/* active state */ APAL_GPIO_ACTIVE_HIGH, //TODO
|
|
347 |
/* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
|
348 | 348 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE, |
349 | 349 |
}, |
350 | 350 |
}; |
... | ... | |
360 | 360 |
/* GPIO */ &_gpioSwVsysEn, |
361 | 361 |
/* meta */ { |
362 | 362 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT, |
363 |
/* active state */ APAL_GPIO_ACTIVE_HIGH, //TODO
|
|
363 |
/* active state */ APAL_GPIO_ACTIVE_HIGH, |
|
364 | 364 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE, |
365 | 365 |
}, |
366 | 366 |
}; |
... | ... | |
445 | 445 |
/*===========================================================================*/ |
446 | 446 |
|
447 | 447 |
AT24C01BDriver moduleLldEeprom = { |
448 |
/* I2C driver */ &MODULE_HAL_I2C_EEPROM_BREAKOUT, |
|
448 |
/* I2C driver */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
|
|
449 | 449 |
/* I2C address */ 0x00u, |
450 | 450 |
}; |
451 | 451 |
|
452 |
INA219Driver moduleLldPowerMonitorVled = { |
|
453 |
/* I2C Driver */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT, |
|
454 |
/* I²C address */ INA219_LLD_I2C_ADDR_FIXED, |
|
455 |
/* current LSB (uA) */ 0x00u, |
|
456 |
/* configuration */ NULL, |
|
457 |
}; |
|
458 |
|
|
459 |
LEDDriver moduleLldStatusLed = { |
|
460 |
/* LED enable Gpio */ &moduleGpioLed, |
|
461 |
}; |
|
462 |
|
|
463 |
MIC9404xDriver moduleLldPowerSwitchV18 = { |
|
464 |
/* power enable GPIO */ &moduleGpioSwV18En, |
|
465 |
}; |
|
466 |
|
|
467 |
MIC9404xDriver moduleLldPowerSwitchV33 = { |
|
468 |
/* power enable GPIO */ &moduleGpioSwV33En, |
|
469 |
}; |
|
470 |
|
|
471 |
MIC9404xDriver moduleLldPowerSwitchV42 = { |
|
472 |
/* power enable GPIO */ &moduleGpioSwV42En, |
|
473 |
}; |
|
474 |
|
|
475 |
MIC9404xDriver moduleLldPowerSwitchV50 = { |
|
476 |
/* power enable GPIO */ &moduleGpioSwV50En, |
|
477 |
}; |
|
478 |
|
|
479 |
MIC9404xDriver moduleLldPowerSwitchVsys = { |
|
480 |
/* power enable GPIO */ &moduleGpioSwVsysEn, |
|
481 |
}; |
|
482 |
|
|
452 | 483 |
TLC5947Driver moduleLldLedPwm = { |
453 | 484 |
/* SPI driver */ &MODULE_HAL_SPI_LIGHT, |
454 | 485 |
/* BLANK signal GPIO */ &moduleGpioLightBlank, |
... | ... | |
464 | 495 |
*/ |
465 | 496 |
/*===========================================================================*/ |
466 | 497 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
498 |
#include <string.h> |
|
467 | 499 |
|
468 | 500 |
/* |
469 | 501 |
* EEPROM (AT24C01B) |
... | ... | |
492 | 524 |
}; |
493 | 525 |
|
494 | 526 |
/* |
527 |
* INA219 (power monitor) |
|
528 |
*/ |
|
529 |
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[]) |
|
530 |
{ |
|
531 |
(void)argc; |
|
532 |
(void)argv; |
|
533 |
aosUtRun(stream, &moduleUtAlldIna219, "VLED (4.2V)"); |
|
534 |
return AOS_OK; |
|
535 |
} |
|
536 |
static ut_ina219data_t _utIna219Data = { |
|
537 |
/* driver */ &moduleLldPowerMonitorVled, |
|
538 |
/* expected voltage */ 4.2f, |
|
539 |
/* tolerance */ 0.2f, |
|
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 |
/* |
|
555 |
* Status LED |
|
556 |
*/ |
|
557 |
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[]) |
|
558 |
{ |
|
559 |
(void)argc; |
|
560 |
(void)argv; |
|
561 |
aosUtRun(stream, &moduleUtAlldLed, NULL); |
|
562 |
return AOS_OK; |
|
563 |
} |
|
564 |
aos_unittest_t moduleUtAlldLed = { |
|
565 |
/* name */ "LED", |
|
566 |
/* info */ NULL, |
|
567 |
/* test function */ utAlldLedFunc, |
|
568 |
/* shell command */ { |
|
569 |
/* name */ "unittest:StatusLED", |
|
570 |
/* callback */ _utShellCmdCb_AlldLed, |
|
571 |
/* next */ NULL, |
|
572 |
}, |
|
573 |
/* data */ &moduleLldStatusLed, |
|
574 |
}; |
|
575 |
|
|
576 |
/* |
|
577 |
* Power switch driver (MIC9404x) |
|
578 |
*/ |
|
579 |
static int _utShellCmdCb_Mic9404x(BaseSequentialStream* stream, int argc, char* argv[]) |
|
580 |
{ |
|
581 |
// evaluate arguments |
|
582 |
if (argc == 2) { |
|
583 |
if (strcmp(argv[1], "1.8V") == 0) { |
|
584 |
moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV18; |
|
585 |
aosUtRun(stream, &moduleUtAlldMic9404x, "1.8V"); |
|
586 |
moduleUtAlldMic9404x.data = NULL; |
|
587 |
return AOS_OK; |
|
588 |
} |
|
589 |
else if (strcmp(argv[1], "3.3V") == 0) { |
|
590 |
moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV33; |
|
591 |
aosUtRun(stream, &moduleUtAlldMic9404x, "3.3V"); |
|
592 |
moduleUtAlldMic9404x.data = NULL; |
|
593 |
return AOS_OK; |
|
594 |
} |
|
595 |
else if (strcmp(argv[1], "4.2V") == 0) { |
|
596 |
moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV42; |
|
597 |
aosUtRun(stream, &moduleUtAlldMic9404x, "4.2V"); |
|
598 |
moduleUtAlldMic9404x.data = NULL; |
|
599 |
return AOS_OK; |
|
600 |
} |
|
601 |
else if (strcmp(argv[1], "5.0V") == 0) { |
|
602 |
moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV50; |
|
603 |
aosUtRun(stream, &moduleUtAlldMic9404x, "5.0V"); |
|
604 |
moduleUtAlldMic9404x.data = NULL; |
|
605 |
return AOS_OK; |
|
606 |
} |
|
607 |
else if (strcmp(argv[1], "VSYS") == 0) { |
|
608 |
moduleUtAlldMic9404x.data = &moduleLldPowerSwitchVsys; |
|
609 |
aosUtRun(stream, &moduleUtAlldMic9404x, "VSYS"); |
|
610 |
moduleUtAlldMic9404x.data = NULL; |
|
611 |
return AOS_OK; |
|
612 |
} |
|
613 |
} |
|
614 |
// print help |
|
615 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
|
616 |
chprintf(stream, "Options:\n"); |
|
617 |
chprintf(stream, " 1.8V\n"); |
|
618 |
chprintf(stream, " Test power switch for 1.8V supply.\n"); |
|
619 |
chprintf(stream, " 3.3V\n"); |
|
620 |
chprintf(stream, " Test power switch for 3.3V supply.\n"); |
|
621 |
chprintf(stream, " 4.2V\n"); |
|
622 |
chprintf(stream, " Test power switch for 4.2V supply.\n"); |
|
623 |
chprintf(stream, " 5.0V\n"); |
|
624 |
chprintf(stream, " Test power switch for 5.0V supply.\n"); |
|
625 |
chprintf(stream, " VSYS\n"); |
|
626 |
chprintf(stream, " Test power switch for VSYS supply.\n"); |
|
627 |
return AOS_INVALID_ARGUMENTS; |
|
628 |
} |
|
629 |
aos_unittest_t moduleUtAlldMic9404x = { |
|
630 |
/* info */ "MIC9404x", |
|
631 |
/* name */ "power swicth driver", |
|
632 |
/* test function */ utAlldMic9404xFunc, |
|
633 |
/* shell command */ { |
|
634 |
/* name */ "unittest:PowerSwitch", |
|
635 |
/* callback */ _utShellCmdCb_Mic9404x, |
|
636 |
/* next */ NULL, |
|
637 |
}, |
|
638 |
/* data */ NULL, |
|
639 |
}; |
|
640 |
|
|
641 |
/* |
|
495 | 642 |
* LED PWM driver (TLC5947) |
496 | 643 |
*/ |
497 | 644 |
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[]) |
modules/LightRing_1-2/module.h | ||
---|---|---|
56 | 56 |
extern CANConfig moduleHalCanConfig; |
57 | 57 |
|
58 | 58 |
/** |
59 |
* @brief I2C driver to access the EEPROM and the breakout header. |
|
59 |
* @brief I2C driver to access the EEPROM, power monitor and the breakout header.
|
|
60 | 60 |
*/ |
61 |
#define MODULE_HAL_I2C_EEPROM_BREAKOUT I2CD2
|
|
61 |
#define MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT I2CD2
|
|
62 | 62 |
|
63 | 63 |
/** |
64 |
* @brief Configuration for the EEPROM & breakout I2C driver.
|
|
64 |
* @brief Configuration for the EEPROM, power monitor and breakout I2C driver.
|
|
65 | 65 |
*/ |
66 |
extern I2CConfig moduleHalI2cEepromBreakoutConfig; |
|
66 |
extern I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig;
|
|
67 | 67 |
|
68 | 68 |
/** |
69 | 69 |
* @brief Serial driver of the programmer interface. |
... | ... | |
299 | 299 |
#define MODULE_INIT_TESTS() { \ |
300 | 300 |
/* add unit-test shell commands */ \ |
301 | 301 |
aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01b.shellcmd); \ |
302 |
aosShellAddCommand(&aos.shell, &moduleUtAlldIna219.shellcmd); \ |
|
303 |
aosShellAddCommand(&aos.shell, &moduleUtAlldLed.shellcmd); \ |
|
304 |
aosShellAddCommand(&aos.shell, &moduleUtAlldMic9404x.shellcmd); \ |
|
302 | 305 |
aosShellAddCommand(&aos.shell, &moduleUtAlldTlc5947.shellcmd); \ |
303 | 306 |
} |
304 | 307 |
|
... | ... | |
309 | 312 |
/* serial driver */ \ |
310 | 313 |
sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig); \ |
311 | 314 |
/* I2C */ \ |
312 |
moduleHalI2cEepromBreakoutConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromBreakoutConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromBreakoutConfig.clock_speed; \ |
|
313 |
moduleHalI2cEepromBreakoutConfig.duty_cycle = (moduleHalI2cEepromBreakoutConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2; \ |
|
314 |
i2cStart(&MODULE_HAL_I2C_EEPROM_BREAKOUT, &moduleHalI2cEepromBreakoutConfig); \ |
|
315 |
moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed; \ |
|
316 |
moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed; \ |
|
317 |
moduleHalI2cEepromPwrmtrBreakoutConfig.duty_cycle = (moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2; \ |
|
318 |
i2cStart(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT, &moduleHalI2cEepromPwrmtrBreakoutConfig); \ |
|
315 | 319 |
/* SPI */ \ |
316 | 320 |
spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig); \ |
317 | 321 |
} |
... | ... | |
323 | 327 |
/* SPI */ \ |
324 | 328 |
spiStop(&MODULE_HAL_SPI_LIGHT); \ |
325 | 329 |
/* I2C */ \ |
326 |
i2cStop(&MODULE_HAL_I2C_EEPROM_BREAKOUT); \
|
|
330 |
i2cStop(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT); \
|
|
327 | 331 |
/* don't stop the serial driver so messages can still be printed */ \ |
328 | 332 |
} |
329 | 333 |
|
... | ... | |
385 | 389 |
*/ |
386 | 390 |
/*===========================================================================*/ |
387 | 391 |
#include <alld_AT24C01B.h> |
392 |
#include <alld_INA219.h> |
|
388 | 393 |
#include <alld_LED.h> |
394 |
#include <alld_MIC9404x.h> |
|
395 |
//#include <alld_SNx5C3221E.h> |
|
389 | 396 |
#include <alld_TLC5947.h> |
390 | 397 |
|
391 | 398 |
/** |
... | ... | |
394 | 401 |
extern AT24C01BDriver moduleLldEeprom; |
395 | 402 |
|
396 | 403 |
/** |
404 |
* @brief Power monitor (VLED 4.2) driver. |
|
405 |
*/ |
|
406 |
extern INA219Driver moduleLldPowerMonitorVled; |
|
407 |
|
|
408 |
/** |
|
397 | 409 |
* @brief Status LED driver. |
398 | 410 |
*/ |
399 | 411 |
extern LEDDriver moduleLldStatusLed; |
400 | 412 |
|
401 | 413 |
/** |
414 |
* @brief Power switch driver (1.8V). |
|
415 |
*/ |
|
416 |
extern MIC9404xDriver moduleLldPowerSwitchV18; |
|
417 |
|
|
418 |
/** |
|
419 |
* @brief Power switch driver (3.3V). |
|
420 |
*/ |
|
421 |
extern MIC9404xDriver moduleLldPowerSwitchV33; |
|
422 |
|
|
423 |
/** |
|
424 |
* @brief Power switch driver (4.2V). |
|
425 |
*/ |
|
426 |
extern MIC9404xDriver moduleLldPowerSwitchV42; |
|
427 |
|
|
428 |
/** |
|
429 |
* @brief Power switch driver (5.0V). |
|
430 |
*/ |
|
431 |
extern MIC9404xDriver moduleLldPowerSwitchV50; |
|
432 |
|
|
433 |
/** |
|
434 |
* @brief Pseudo power switch driver (VSYS). |
|
435 |
* @details There is no actual MIC9040x device, but the swicthable circuit behaves analogous. |
|
436 |
*/ |
|
437 |
extern MIC9404xDriver moduleLldPowerSwitchVsys; |
|
438 |
|
|
439 |
/** |
|
402 | 440 |
* @brief LED PWM driver. |
403 | 441 |
*/ |
404 | 442 |
extern TLC5947Driver moduleLldLedPwm; |
... | ... | |
413 | 451 |
/*===========================================================================*/ |
414 | 452 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
415 | 453 |
#include <ut_alld_AT24C01B_v1.h> |
454 |
#include <ut_alld_INA219_v1.h> |
|
455 |
#include <ut_alld_LED_v1.h> |
|
456 |
#include <ut_alld_MIC9404x_v1.h> |
|
457 |
//#include <ut_alld_SNx5C3221E_v1.h> |
|
416 | 458 |
#include <ut_alld_TLC5947_v1.h> |
417 | 459 |
|
418 | 460 |
/** |
... | ... | |
421 | 463 |
extern aos_unittest_t moduleUtAlldAt24c01b; |
422 | 464 |
|
423 | 465 |
/** |
466 |
* @brief INA219 (power monitor) unit test object. |
|
467 |
*/ |
|
468 |
extern aos_unittest_t moduleUtAlldIna219; |
|
469 |
|
|
470 |
/** |
|
471 |
* @brief Status LED unit test object. |
|
472 |
*/ |
|
473 |
extern aos_unittest_t moduleUtAlldLed; |
|
474 |
|
|
475 |
/** |
|
476 |
* @brief Power switch unit test object. |
|
477 |
*/ |
|
478 |
extern aos_unittest_t moduleUtAlldMic9404x; |
|
479 |
|
|
480 |
/** |
|
424 | 481 |
* @brief LED PWM driver unit test object. |
425 | 482 |
*/ |
426 | 483 |
extern aos_unittest_t moduleUtAlldTlc5947; |
periphery-lld/AMiRo-LLD | ||
---|---|---|
1 |
Subproject commit 5d0950c9bfb4c1aa7fc79b08f57febc7c873f1c4 |
|
1 |
Subproject commit 78cc79d4e470ffbd441c47a8835c138718996c85 |
unittests/periphery-lld/inc/ut_alld_MIC9404x_v1.h | ||
---|---|---|
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 |
#ifndef AMIROOS_UT_ALLD_MIC9404x_V1_H |
|
20 |
#define AMIROOS_UT_ALLD_MIC9404x_V1_H |
|
21 |
|
|
22 |
#include <amiroos.h> |
|
23 |
|
|
24 |
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_MIC9404x) && (AMIROLLD_CFG_MIC9404x == 1)) || defined(__DOXYGEN__) |
|
25 |
|
|
26 |
#include <alld_MIC9404x.h> |
|
27 |
|
|
28 |
/******************************************************************************/ |
|
29 |
/* CONSTANTS */ |
|
30 |
/******************************************************************************/ |
|
31 |
|
|
32 |
/******************************************************************************/ |
|
33 |
/* SETTINGS */ |
|
34 |
/******************************************************************************/ |
|
35 |
|
|
36 |
/******************************************************************************/ |
|
37 |
/* CHECKS */ |
|
38 |
/******************************************************************************/ |
|
39 |
|
|
40 |
/******************************************************************************/ |
|
41 |
/* DATA STRUCTURES AND TYPES */ |
|
42 |
/******************************************************************************/ |
|
43 |
|
|
44 |
/******************************************************************************/ |
|
45 |
/* MACROS */ |
|
46 |
/******************************************************************************/ |
|
47 |
|
|
48 |
/******************************************************************************/ |
|
49 |
/* EXTERN DECLARATIONS */ |
|
50 |
/******************************************************************************/ |
|
51 |
|
|
52 |
#if defined(__cplusplus) |
|
53 |
extern "C" { |
|
54 |
#endif /* defined(__cplusplus) */ |
|
55 |
aos_utresult_t utAlldMic9404xFunc(BaseSequentialStream* stream, aos_unittest_t* ut); |
|
56 |
#if defined(__cplusplus) |
|
57 |
} |
|
58 |
#endif /* defined(__cplusplus) */ |
|
59 |
|
|
60 |
/******************************************************************************/ |
|
61 |
/* INLINE FUNCTIONS */ |
|
62 |
/******************************************************************************/ |
|
63 |
|
|
64 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_MIC9404x) && (AMIROLLD_CFG_MIC9404x == 1) */ |
|
65 |
|
|
66 |
#endif /* AMIROOS_UT_ALLD_MIC9404x_V1_H */ |
unittests/periphery-lld/src/ut_alld_MIC9404x_v1.c | ||
---|---|---|
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 |
#include <amiroos.h> |
|
20 |
#include <ut_alld_MIC9404x_v1.h> |
|
21 |
|
|
22 |
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_MIC9404x) && (AMIROLLD_CFG_MIC9404x == 1)) || defined(__DOXYGEN__) |
|
23 |
|
|
24 |
/******************************************************************************/ |
|
25 |
/* LOCAL DEFINITIONS */ |
|
26 |
/******************************************************************************/ |
|
27 |
|
|
28 |
/******************************************************************************/ |
|
29 |
/* EXPORTED VARIABLES */ |
|
30 |
/******************************************************************************/ |
|
31 |
|
|
32 |
/******************************************************************************/ |
|
33 |
/* LOCAL TYPES */ |
|
34 |
/******************************************************************************/ |
|
35 |
|
|
36 |
/******************************************************************************/ |
|
37 |
/* LOCAL VARIABLES */ |
|
38 |
/******************************************************************************/ |
|
39 |
|
|
40 |
/******************************************************************************/ |
|
41 |
/* LOCAL FUNCTIONS */ |
|
42 |
/******************************************************************************/ |
|
43 |
|
|
44 |
/******************************************************************************/ |
|
45 |
/* EXPORTED FUNCTIONS */ |
|
46 |
/******************************************************************************/ |
|
47 |
|
|
48 |
/** |
|
49 |
* @brief MIC9404x unit test function. |
|
50 |
* |
|
51 |
* @param[in] stream Stream for input/output. |
|
52 |
* @param[in] ut Unit test object. |
|
53 |
* |
|
54 |
* @return Unit test result value. |
|
55 |
*/ |
|
56 |
aos_utresult_t utAlldMic9404xFunc(BaseSequentialStream* stream, aos_unittest_t* ut) |
|
57 |
{ |
|
58 |
aosDbgCheck(ut->data != NULL); |
|
59 |
|
|
60 |
// local variables |
|
61 |
mic9404x_lld_state_t state_orig; |
|
62 |
mic9404x_lld_state_t state; |
|
63 |
aos_utresult_t result = {0, 0}; |
|
64 |
uint32_t status = APAL_STATUS_OK; |
|
65 |
|
|
66 |
chprintf(stream, "reading current status...\n"); |
|
67 |
status = mic9404x_lld_get((MIC9404xDriver*)ut->data, &state_orig); |
|
68 |
if (status == APAL_STATUS_OK) { |
|
69 |
aosUtPassedMsg(stream, &result, "power %s\n", (state_orig == MIC9404x_LLD_STATE_ON) ? "enabled" : "disabled"); |
|
70 |
} else { |
|
71 |
aosUtFailed(stream, &result); |
|
72 |
} |
|
73 |
|
|
74 |
state = state_orig; |
|
75 |
for (uint8_t i = 0; i < 2; ++i) { |
|
76 |
if (state == MIC9404x_LLD_STATE_ON) { |
|
77 |
chprintf(stream, "disabling for five seconds...\n"); |
|
78 |
status = mic9404x_lld_set((MIC9404xDriver*)ut->data, MIC9404x_LLD_STATE_OFF); |
|
79 |
status |= mic9404x_lld_get((MIC9404xDriver*)ut->data, &state); |
|
80 |
if (state == MIC9404x_LLD_STATE_OFF) { |
|
81 |
aosThdSSleep(5); |
|
82 |
status |= mic9404x_lld_get((MIC9404xDriver*)ut->data, &state); |
|
83 |
} |
|
84 |
if ((status == APAL_STATUS_OK) && (state == MIC9404x_LLD_STATE_OFF)) { |
|
85 |
aosUtPassed(stream, &result); |
|
86 |
} else { |
|
87 |
aosUtFailed(stream, &result); |
|
88 |
break; |
|
89 |
} |
|
90 |
} else { |
|
91 |
chprintf(stream, "enabling for five seconds...\n"); |
|
92 |
status = mic9404x_lld_set((MIC9404xDriver*)ut->data, MIC9404x_LLD_STATE_ON); |
|
93 |
status |= mic9404x_lld_get((MIC9404xDriver*)ut->data, &state); |
|
94 |
if (state == MIC9404x_LLD_STATE_ON) { |
|
95 |
aosThdSSleep(5); |
|
96 |
status |= mic9404x_lld_get((MIC9404xDriver*)ut->data, &state); |
|
97 |
} |
|
98 |
if ((status == APAL_STATUS_OK) && (state == MIC9404x_LLD_STATE_ON)) { |
|
99 |
aosUtPassed(stream, &result); |
|
100 |
} else { |
|
101 |
aosUtFailed(stream, &result); |
|
102 |
break; |
|
103 |
} |
|
104 |
} |
|
105 |
} |
|
106 |
// restore original state |
|
107 |
if (state != state_orig) { |
|
108 |
status = mic9404x_lld_set((MIC9404xDriver*)ut->data, state); |
|
109 |
if (status != APAL_STATUS_OK) { |
|
110 |
chprintf(stream, "\t\tWARNING: failed to restore original status!\n"); |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(MIC9404xDriver)); |
|
115 |
|
|
116 |
return result; |
|
117 |
} |
|
118 |
|
|
119 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_MIC9404x) && (AMIROLLD_CFG_MIC9404x == 1) */ |
Also available in: Unified diff