diff options
Diffstat (limited to 'nuttx/configs/nucleus2g/src/up_leds.c')
-rwxr-xr-x | nuttx/configs/nucleus2g/src/up_leds.c | 291 |
1 files changed, 76 insertions, 215 deletions
diff --git a/nuttx/configs/nucleus2g/src/up_leds.c b/nuttx/configs/nucleus2g/src/up_leds.c index fbc5a30af..64eaad65e 100755 --- a/nuttx/configs/nucleus2g/src/up_leds.c +++ b/nuttx/configs/nucleus2g/src/up_leds.c @@ -60,17 +60,6 @@ * Definitions ****************************************************************************/ -#define LED_OFF 0 -#define LED_ON 1 -#define LED_GREEN 2 -#define LED_PLUSGREEN 3 -#define LED_MINUSGREEN 4 -#define LED_RED 5 -#define LED_PLUSRED 6 -#define LED_MINUSRED 7 -#define LED_NC 8 -#define LED_PREV 9 - /* Enables debug output from this file (needs CONFIG_DEBUG with * CONFIG_DEBUG_VERBOSE too) */ @@ -114,196 +103,21 @@ * LED_STARTED | OFF OFF OFF * LED_HEAPALLOCATE | GREEN OFF OFF * LED_IRQSENABLED | OFF GREEN OFF - * LED_STACKCREATED | GREEN GREEN OFF - * LED_INIRQ | NC NC ON - * LED_SIGNAL | NC RED NC - * LED_ASSERTION | RED NC NC - * LED_PANIC | RED RED NC (1Hz flashing) + * LED_STACKCREATED | OFF OFF OFF + * LED_INIRQ | NC NC ON (momentary) + * LED_SIGNAL | NC NC ON (momentary) + * LED_ASSERTION | NC NC ON (momentary) + * LED_PANIC | NC NC ON (1Hz flashing) */ -static const uint8_t g_led1on[8] = -{ - LED_OFF, LED_GREEN, LED_OFF, LED_GREEN, - LED_NC, LED_NC, LED_PLUSRED, LED_PLUSRED -}; - -static const uint8_t g_led1off[8] = -{ - LED_OFF, LED_OFF, LED_GREEN, LED_OFF, - LED_NC, LED_NC, LED_MINUSRED, LED_PREV -}; - -static const uint8_t g_led2on[8] = -{ - LED_OFF, LED_OFF, LED_GREEN, LED_GREEN, - LED_NC, LED_PLUSRED, LED_NC, LED_PLUSRED -}; - -static const uint8_t g_led2off[8] = -{ - LED_OFF, LED_OFF, LED_OFF, LED_GREEN, - LED_NC, LED_MINUSRED, LED_NC, LED_PREV -}; - -static const uint8_t g_ledhbon[8] = -{ - LED_OFF, LED_OFF, LED_OFF, LED_OFF, - LED_ON, LED_NC, LED_NC, LED_NC -}; - -static const uint8_t g_ledhboff[8] = -{ - LED_OFF, LED_OFF, LED_OFF, LED_OFF, - LED_OFF, LED_NC, LED_NC, LED_NC -}; - -static bool g_prevled1a; -static bool g_currled1a; -static bool g_prevled1b; -static bool g_currled1b; -static bool g_prevled2a; -static bool g_currled2a; -static bool g_prevled2b; -static bool g_currled2b; +static bool g_initialized; +static int g_nestcount; /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: up_led1 - ****************************************************************************/ - -void up_led1(uint8_t newstate) -{ - bool led1a = false; - bool led1b = false; - - switch (newstate) - { - default: - case LED_OFF: - case LED_ON: - break; - - case LED_GREEN: - led1b = true; - break; - - case LED_PLUSGREEN: - led1b = true; - case LED_MINUSGREEN: - led1a = g_currled1a; - break; - - case LED_RED: - break; - - case LED_PLUSRED: - led1a = true; - case LED_MINUSRED: - led1b = g_currled1b; - break; - - case LED_NC: - led1a = g_currled1a; - led1b = g_currled1b; - break; - - case LED_PREV: - led1a = g_prevled1a; - led1b = g_prevled1b; - break; - } - - lpc17_gpiowrite(NUCLEUS2G_LED1_A, led1a); - lpc17_gpiowrite(NUCLEUS2G_LED1_B, led1b); - g_prevled1a = g_currled1a; - g_currled1a = led1a; - g_prevled1b = g_currled1b; - g_currled1b = led1b; -} - -/**************************************************************************** - * Name: up_led2 - ****************************************************************************/ - -void up_led2(uint8_t newstate) -{ - bool led2a = false; - bool led2b = false; - - switch (newstate) - { - default: - case LED_OFF: - case LED_ON: - break; - - case LED_GREEN: - led2b = true; - break; - - case LED_PLUSGREEN: - led2b = true; - case LED_MINUSGREEN: - led2a = g_currled2a; - break; - - case LED_RED: - break; - - case LED_PLUSRED: - led2a = true; - case LED_MINUSRED: - led2b = g_currled2b; - break; - - case LED_NC: - led2a = g_currled2a; - led2b = g_currled2b; - break; - - case LED_PREV: - led2a = g_prevled2a; - led2b = g_prevled2b; - break; - } - - lpc17_gpiowrite(NUCLEUS2G_LED2_A, led2a); - lpc17_gpiowrite(NUCLEUS2G_LED2_B, led2b); - g_prevled2a = g_currled2a; - g_currled2a = led2a; - g_prevled2b = g_currled2b; - g_currled2b = led2b; -} - -/**************************************************************************** - * Name: up_ledhb - ****************************************************************************/ - -void up_ledhb(uint8_t newstate) -{ - bool ledhb = false; - - switch (newstate) - { - default: - case LED_OFF: - break; - - case LED_ON: - ledhb = true; - break; - - case LED_NC: - return; - } - - lpc17_gpiowrite(NUCLEUS2G_HEARTBEAT, ledhb); -} - -/**************************************************************************** * Public Functions ****************************************************************************/ @@ -333,20 +147,45 @@ void up_ledinit(void) void up_ledon(int led) { - up_led1(g_led1on[led]); - up_led2(g_led2on[led]); - up_ledhb(g_ledhbon[led]); + /* We will control LED1 and LED2 not yet completed the boot sequence. */ -#ifdef LED_VERBOSE - if (led != LED_INIRQ) + if (!g_initialized) { - ledvdbg("led: %d LED1: %d LED2: %d HB: %d\n", - led, g_led1on[led], g_led2on[led], g_ledhbon[led]); - ledvdbg("LED1: {(%d,%d), (%d,%d)} LED2: {(%d,%d), (%d,%d)}\n", - g_prevled1a, g_currled1a, g_prevled1b, g_currled1b, - g_prevled2a, g_currled2a, g_prevled2b, g_currled2b); + enum lpc17_ledstate_e led1 = LPC17_LEDSTATE_OFF; + enum lpc17_ledstate_e led2 = LPC17_LEDSTATE_OFF; + switch (led) + { + case LED_STACKCREATED: + g_initialized = true; + case LED_STARTED: + default: + break; + + case LED_HEAPALLOCATE: + led1 = LPC17_LEDSTATE_GREEN; + break; + + case LED_IRQSENABLED: + led2 = LPC17_LEDSTATE_GREEN; + } + lpc17_led1(led1); + lpc17_led2(led2); + } + + /* We will always control the HB LED */ + + switch (led) + { + default: + break; + + case LED_INIRQ: + case LED_SIGNAL: + case LED_ASSERTION: + case LED_PANIC: + lpc17_gpiowrite(NUCLEUS2G_HEARTBEAT, false); + g_nestcount++; } -#endif } /**************************************************************************** @@ -355,20 +194,42 @@ void up_ledon(int led) void up_ledoff(int led) { - up_led1(g_led1off[led]); - up_led2(g_led2off[led]); - up_ledhb(g_ledhboff[led]); + /* In all states, OFF can only mean turning off the HB LED */ -#ifdef LED_VERBOSE - if (led != LED_INIRQ) + if (g_nestcount <= 1) { - ledvdbg("led: %d LED1: %d LED2: %d HB: %d\n", - led, g_led1off[led], g_led2off[led], g_ledhboff[led]); - ledvdbg("LED1: {(%d,%d), (%d,%d)} LED2: {(%d,%d), (%d,%d)}\n", - g_prevled1a, g_currled1a, g_prevled1b, g_currled1b, - g_prevled2a, g_currled2a, g_prevled2b, g_currled2b); + lpc17_gpiowrite(NUCLEUS2G_HEARTBEAT, true); + g_nestcount = 0; + } + else + { + g_nestcount--; } -#endif } +/************************************************************************************ + * Name: lpc17_led1 and 2 + * + * Description: + * Once the system has booted, these functions can be used to control LEDs 1 and 2 + * + ************************************************************************************/ + +void lpc17_led1(enum lpc17_ledstate_e state) +{ + bool red = (((unsigned int)state & LPC17_LEDSTATE_RED) != 0); + bool green = (((unsigned int)state & LPC17_LEDSTATE_GREEN) != 0); + + lpc17_gpiowrite(NUCLEUS2G_LED1_A, red); + lpc17_gpiowrite(NUCLEUS2G_LED1_B, green); +} + +void lpc17_led2(enum lpc17_ledstate_e state) +{ + bool red = (((unsigned int)state & LPC17_LEDSTATE_RED) != 0); + bool green = (((unsigned int)state & LPC17_LEDSTATE_GREEN) != 0); + + lpc17_gpiowrite(NUCLEUS2G_LED2_A, red); + lpc17_gpiowrite(NUCLEUS2G_LED2_B, green); +} #endif /* CONFIG_ARCH_LEDS */ |