tests/leds: blink ALL defined on-board LEDs

This commit is contained in:
Hauke Petersen 2016-03-11 16:25:00 +01:00
parent c11517138e
commit 35cc73f403
3 changed files with 178 additions and 34 deletions

View File

@ -1,6 +1,4 @@
export APPLICATION = leds export APPLICATION = leds
include ../Makefile.tests_common include ../Makefile.tests_common
USEMODULE += xtimer
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

View File

@ -1,12 +1,13 @@
Expected result Expected result
=============== ===============
The 'red' and the 'green' LEDs of the board should light up alternating with a This test will blink all available on-board LEDs, one after each other in an
500ms interval. If your board has only one LED (probably defined as LED_RED), endless loop. Each LED will light up once long, and twice short, where the long
you will see only this LED blink at 1Hz. If your board has no on-board LED, you interval is roughly 4 times as long as the short interval. The length of the
will see nothing. interval is not specified and differs for each platform.
Background Background
========== ==========
All boards in RIOT define at least two macros for accessing two selected Running this test shows if all the direct access macros for all on-board LEDs
on-board LEDs directly. These are called LED_RED and LED_GREEN, independent if are working correctly (xx_ON, xx_OFF, xx_TOGGLE). This test is intentionally not
the actual color of those LED is red or green. using any timers, so it can also be used early on in the porting process, where
timers might not yet be available.

View File

@ -21,38 +21,183 @@
#include <stdio.h> #include <stdio.h>
#include "board.h" #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) int main(void)
{ {
puts("On-board LED test\n"); int numof = 0;
puts("You should now see the 'red' and the 'green' LED lighting up in a\n"
"500ms interval, alternating of each other."); /* 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) { while (1) {
LED_RED_ON; #ifdef LED0_ON
puts("LED_RED_ON"); LED0_ON;
xtimer_usleep(WAIT_INTERVAL); dumb_delay(DELAY_LONG);
LED_RED_OFF; LED0_OFF;
LED_GREEN_ON; dumb_delay(DELAY_LONG);
puts("LED_GREEN_ON"); LED0_TOGGLE;
xtimer_usleep(WAIT_INTERVAL); dumb_delay(DELAY_SHORT);
LED_GREEN_OFF; LED0_TOGGLE;
dumb_delay(DELAY_SHORT);
LED_RED_TOGGLE; LED0_TOGGLE;
puts("LED_RED_TOGGLE"); dumb_delay(DELAY_SHORT);
xtimer_usleep(WAIT_INTERVAL); LED0_TOGGLE;
LED_RED_TOGGLE; dumb_delay(DELAY_LONG);
LED_GREEN_TOGGLE; #endif
puts("LED_GREEN_TOGGLE"); #ifdef LED1_ON
xtimer_usleep(WAIT_INTERVAL); LED1_ON;
LED_GREEN_TOGGLE; 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; return 0;