From 35cc73f4031a61c33c9c2848fed625a64881c0de Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 11 Mar 2016 16:25:00 +0100 Subject: [PATCH] tests/leds: blink ALL defined on-board LEDs --- tests/leds/Makefile | 2 - tests/leds/README.md | 15 ++-- tests/leds/main.c | 195 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 178 insertions(+), 34 deletions(-) diff --git a/tests/leds/Makefile b/tests/leds/Makefile index 1bccb9df11..9e35d60083 100644 --- a/tests/leds/Makefile +++ b/tests/leds/Makefile @@ -1,6 +1,4 @@ export APPLICATION = leds include ../Makefile.tests_common -USEMODULE += xtimer - include $(RIOTBASE)/Makefile.include diff --git a/tests/leds/README.md b/tests/leds/README.md index a03c6386f5..ce2423cd7a 100644 --- a/tests/leds/README.md +++ b/tests/leds/README.md @@ -1,12 +1,13 @@ Expected result =============== -The 'red' and the 'green' LEDs of the board should light up alternating with a -500ms interval. If your board has only one LED (probably defined as LED_RED), -you will see only this LED blink at 1Hz. If your board has no on-board LED, you -will see nothing. +This test will blink all available on-board LEDs, one after each other in an +endless loop. Each LED will light up once long, and twice short, where the long +interval is roughly 4 times as long as the short interval. The length of the +interval is not specified and differs for each platform. Background ========== -All boards in RIOT define at least two macros for accessing two selected -on-board LEDs directly. These are called LED_RED and LED_GREEN, independent if -the actual color of those LED is red or green. +Running this test shows if all the direct access macros for all on-board LEDs +are working correctly (xx_ON, xx_OFF, xx_TOGGLE). This test is intentionally not +using any timers, so it can also be used early on in the porting process, where +timers might not yet be available. diff --git a/tests/leds/main.c b/tests/leds/main.c index 42669c956c..61a79e762b 100644 --- a/tests/leds/main.c +++ b/tests/leds/main.c @@ -21,38 +21,183 @@ #include #include "board.h" -#include "xtimer.h" +#include "periph_conf.h" -#define WAIT_INTERVAL (500 * MS_IN_USEC) +#ifdef CLOCK_CORECLOCK +#define DELAY_SHORT (CLOCK_CORECLOCK / 50) +#else +#define DELAY_SHORT (500000UL) +#endif +#define DELAY_LONG (DELAY_SHORT * 4) + +void dumb_delay(uint32_t delay) +{ + for (uint32_t i = 0; i < delay; i++) { + asm("nop"); + } +} int main(void) { - puts("On-board LED test\n"); - puts("You should now see the 'red' and the 'green' LED lighting up in a\n" - "500ms interval, alternating of each other."); + int numof = 0; + + /* get the number of available LED's and turn them all off*/ +#ifdef LED0_ON + ++numof; + LED0_OFF; +#endif +#ifdef LED1_ON + ++numof; + LED1_OFF; +#endif +#ifdef LED2_ON + ++numof; + LED2_OFF; +#endif +#ifdef LED3_ON + ++numof; + LED3_OFF; +#endif +#ifdef LED4_ON + ++numof; + LED4_OFF; +#endif +#ifdef LED5_ON + ++numof; + LED5_OFF; +#endif +#ifdef LED6_ON + ++numof; + LED6_OFF; +#endif +#ifdef LED7_ON + ++numof; + LED7_OFF; +#endif + + puts("On-board LED test\n"); + if (numof == 0) { + puts("NO LEDs AVAILABLE"); + } + else { + printf("Available LEDs: %i\n\n", numof); + puts("Will now light up each LED once short and twice long in a loop"); + } - /* turn off all LEDs */ - LED_RED_OFF; - LED_GREEN_OFF; while (1) { - LED_RED_ON; - puts("LED_RED_ON"); - xtimer_usleep(WAIT_INTERVAL); - LED_RED_OFF; - LED_GREEN_ON; - puts("LED_GREEN_ON"); - xtimer_usleep(WAIT_INTERVAL); - LED_GREEN_OFF; - - LED_RED_TOGGLE; - puts("LED_RED_TOGGLE"); - xtimer_usleep(WAIT_INTERVAL); - LED_RED_TOGGLE; - LED_GREEN_TOGGLE; - puts("LED_GREEN_TOGGLE"); - xtimer_usleep(WAIT_INTERVAL); - LED_GREEN_TOGGLE; +#ifdef LED0_ON + LED0_ON; + dumb_delay(DELAY_LONG); + LED0_OFF; + dumb_delay(DELAY_LONG); + LED0_TOGGLE; + dumb_delay(DELAY_SHORT); + LED0_TOGGLE; + dumb_delay(DELAY_SHORT); + LED0_TOGGLE; + dumb_delay(DELAY_SHORT); + LED0_TOGGLE; + dumb_delay(DELAY_LONG); +#endif +#ifdef LED1_ON + LED1_ON; + dumb_delay(DELAY_LONG); + LED1_OFF; + dumb_delay(DELAY_LONG); + LED1_TOGGLE; + dumb_delay(DELAY_SHORT); + LED1_TOGGLE; + dumb_delay(DELAY_SHORT); + LED1_TOGGLE; + dumb_delay(DELAY_SHORT); + LED1_TOGGLE; + dumb_delay(DELAY_LONG); +#endif +#ifdef LED2_ON + LED2_ON; + dumb_delay(DELAY_LONG); + LED2_OFF; + dumb_delay(DELAY_LONG); + LED2_TOGGLE; + dumb_delay(DELAY_SHORT); + LED2_TOGGLE; + dumb_delay(DELAY_SHORT); + LED2_TOGGLE; + dumb_delay(DELAY_SHORT); + LED2_TOGGLE; + dumb_delay(DELAY_LONG); +#endif +#ifdef LED3_ON + LED3_ON; + dumb_delay(DELAY_LONG); + LED3_OFF; + dumb_delay(DELAY_LONG); + LED3_TOGGLE; + dumb_delay(DELAY_SHORT); + LED3_TOGGLE; + dumb_delay(DELAY_SHORT); + LED3_TOGGLE; + dumb_delay(DELAY_SHORT); + LED3_TOGGLE; + dumb_delay(DELAY_LONG); +#endif +#ifdef LED4_ON + LED4_ON; + dumb_delay(DELAY_LONG); + LED4_OFF; + dumb_delay(DELAY_LONG); + LED4_TOGGLE; + dumb_delay(DELAY_SHORT); + LED4_TOGGLE; + dumb_delay(DELAY_SHORT); + LED4_TOGGLE; + dumb_delay(DELAY_SHORT); + LED4_TOGGLE; + dumb_delay(DELAY_LONG); +#endif +#ifdef LED5_ON + LED5_ON; + dumb_delay(DELAY_LONG); + LED5_OFF; + dumb_delay(DELAY_LONG); + LED5_TOGGLE; + dumb_delay(DELAY_SHORT); + LED5_TOGGLE; + dumb_delay(DELAY_SHORT); + LED5_TOGGLE; + dumb_delay(DELAY_SHORT); + LED5_TOGGLE; + dumb_delay(DELAY_LONG); +#endif +#ifdef LED6_ON + LED6_ON; + dumb_delay(DELAY_LONG); + LED6_OFF; + dumb_delay(DELAY_LONG); + LED6_TOGGLE; + dumb_delay(DELAY_SHORT); + LED6_TOGGLE; + dumb_delay(DELAY_SHORT); + LED6_TOGGLE; + dumb_delay(DELAY_SHORT); + LED6_TOGGLE; + dumb_delay(DELAY_LONG); +#endif +#ifdef LED7_ON + LED7_ON; + dumb_delay(DELAY_LONG); + LED7_OFF; + dumb_delay(DELAY_LONG); + LED7_TOGGLE; + dumb_delay(DELAY_SHORT); + LED7_TOGGLE; + dumb_delay(DELAY_SHORT); + LED7_TOGGLE; + dumb_delay(DELAY_SHORT); + LED7_TOGGLE; + dumb_delay(DELAY_LONG); +#endif } return 0;