From a8a395338ce83c97e5ec1114777b64201c67a1af Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 23 Sep 2013 07:47:56 -0600 Subject: ZKIT-ARM-1769: LED1 is now user controllable. From Rashid Fatah --- nuttx/ChangeLog | 2 + nuttx/configs/zkit-arm-1769/include/board.h | 40 +++++++--- nuttx/configs/zkit-arm-1769/src/up_leds.c | 113 ++++++++++++++++++++-------- 3 files changed, 113 insertions(+), 42 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 15b158a99..589dd5c86 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -5617,4 +5617,6 @@ endpoint from 0xff (invalid) to 10. This is not a critical change but will avoid a complaint from the Linux driver when it overrides the 0xff value (2013-9-22). + * configs/zkit-arm-1769: LED1 is not user controllable after booting. + From Rashid Fatah (2013-9-23). diff --git a/nuttx/configs/zkit-arm-1769/include/board.h b/nuttx/configs/zkit-arm-1769/include/board.h index 63dd4d914..fbaeff6d4 100644 --- a/nuttx/configs/zkit-arm-1769/include/board.h +++ b/nuttx/configs/zkit-arm-1769/include/board.h @@ -161,16 +161,22 @@ * on board the ZKIT-ARM-1769. The following definitions * describe how NuttX controls the LEDs: */ - /* LED1 LED2 */ -#define LED_STARTED 0 /* OFF OFF = Still initializing */ -#define LED_HEAPALLOCATE 0 /* OFF OFF = Still initializing */ -#define LED_IRQSENABLED 0 /* OFF OFF = Still initializing */ -#define LED_STACKCREATED 1 /* ON OFF = Initialization complete */ -#define LED_INIRQ 2 /* N/C ON = In an interrupt handler */ -#define LED_SIGNAL 2 /* N/C ON = In a signal handler (glowing) */ -#define LED_ASSERTION 2 /* N/C ON = In an assertion */ -#define LED_PANIC 2 /* N/C ON = Oops! We crashed. (flashing) */ -#define LED_IDLE 3 /* OFF N/C = LPC17 in sleep mode (LED1 glowing) */ + + /* LED1 LED2 */ +#define LED_STARTED 0 /* OFF OFF */ +#define LED_HEAPALLOCATE 1 /* ON OFF */ +#define LED_IRQSENABLED 2 /* OFF ON */ +#define LED_STACKCREATED 3 /* OFF OFF */ + +/* After the system is booted, this logic will no longer use LED 1. + * LED 1 is available for use by application software using lpc17_led + * (prototyped below) + */ + /* LED1 LED2 */ +#define LED_INIRQ 4 /* NC ON (momentary) */ +#define LED_SIGNAL 5 /* NC ON (momentary) */ +#define LED_ASSERTION 6 /* NC ON (momentary) */ +#define LED_PANIC 7 /* NC ON (1Hz flashing) */ /* Button definitions ***************************************************************/ /* The ZKIT-ARM-1769 supports several buttons. All will read "1" when open and "0" @@ -231,7 +237,7 @@ #define GPIO_CAN1_RD GPIO_CAN1_RD_1 #define GPIO_CAN1_TD GPIO_CAN1_TD_1 -#define GPIO_CAN2_RD GPIO_CAN2_RD_2 +#define GPIO_CAN2_RD GPIO_CAN2_RD_2 #define GPIO_CAN2_TD GPIO_CAN2_TD_2 #define GPIO_I2C1_SDA GPIO_I2C0_SDA #define GPIO_I2C1_SCL GPIO_I2C0_SCL @@ -336,6 +342,18 @@ extern "C" { void lpc17_boardinitialize(void); +/************************************************************************************ + * Name: lpc17_led + * + * Description: + * Once the system has booted, these functions can be used to control LEDs 1 + * + ************************************************************************************/ + +#ifdef CONFIG_ARCH_LEDS +void lpc17_led(int lednum, int state); +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/configs/zkit-arm-1769/src/up_leds.c b/nuttx/configs/zkit-arm-1769/src/up_leds.c index 2b2dfb1e4..875c61fd7 100644 --- a/nuttx/configs/zkit-arm-1769/src/up_leds.c +++ b/nuttx/configs/zkit-arm-1769/src/up_leds.c @@ -48,6 +48,8 @@ #include #include +#include + #include "up_arch.h" #include "up_internal.h" @@ -80,7 +82,30 @@ * Private Data ****************************************************************************/ -static bool g_ncstate; +/* LED definitions ****************************************************************** + +/* The ZKit-ARM-1769 has 2 LEDs along the bottom of the board. Red or off. + * If CONFIG_ARCH_LEDS is defined, the LEDs will be controlled as follows for NuttX + * debug functionality (where NC means "No Change"). + * + * During the boot phases. LED1 and LED2 will show boot status. + * + * LED1 LED2 + * STARTED OFF OFF + * HEAPALLOCATE BLUE OFF + * IRQSENABLED OFF BLUE + * STACKCREATED OFF OFF + * + * After the system is booted, this logic will no longer use LED 1. LED 1 + * is available for use by applications using lpc17_led (prototyped below) + */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static bool g_initialized; +static int g_nestcount; /**************************************************************************** * Private Functions @@ -100,7 +125,6 @@ void up_ledinit(void) lpc17_configgpio(ZKITARM_LED1); lpc17_configgpio(ZKITARM_LED2); - g_ncstate = true; } /**************************************************************************** @@ -109,26 +133,48 @@ void up_ledinit(void) void up_ledon(int led) { - bool off; + /* We will control LED1 and LED2 not yet completed the boot sequence. */ - switch (led) + if (!g_initialized) { - case 0: - case 2: - off = true; - break; + bool led1 = false; + bool led2 = false; + + switch (led) + { + case LED_STACKCREATED: + g_initialized = true; + case LED_STARTED: + default: + break; + + case LED_HEAPALLOCATE: + led1 = true; + break; + + case LED_IRQSENABLED: + led2 = true; + break; + } + + lpc17_led(ZKITARM_LED1, led1); + lpc17_led(ZKITARM_LED2, led2); + } - case 1: - off = false; - g_ncstate = false; - break; + /* We will always control the HB LED */ + + switch (led) + { + case LED_INIRQ: + case LED_SIGNAL: + case LED_ASSERTION: + case LED_PANIC: + lpc17_gpiowrite(ZKITARM_LED2, false); + g_nestcount++; default: - return; + break; } - - lpc17_gpiowrite(ZKITARM_LED1, off); - lpc17_gpiowrite(ZKITARM_LED2, off); } /**************************************************************************** @@ -137,25 +183,30 @@ void up_ledon(int led) void up_ledoff(int led) { - bool off; + /* In all states, OFF can only mean turning off the HB LED */ - switch (led) + if (g_nestcount <= 1) { - case 0: - case 1: - off = false; - break; - - case 2: - off = g_ncstate; - break; - - default: - return; + lpc17_led(ZKITARM_LED2, true); + g_nestcount = 0; + } + else + { + g_nestcount--; } +} - lpc17_gpiowrite(ZKITARM_LED1, off); - lpc17_gpiowrite(ZKITARM_LED2, off); +/************************************************************************************ + * Name: lpc17_led + * + * Description: + * Once the system has booted, this functions can be used to control LED 1 + * + ************************************************************************************/ + +void lpc17_led(int lednum, int state) +{ + lpc17_gpiowrite(ZKITARM_LED1, state); } #endif /* CONFIG_ARCH_LEDS */ -- cgit v1.2.3