Fix LED control logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2773 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
0de5b52564
commit
d0bf8e8fb3
@ -13,7 +13,7 @@ Contents
|
||||
IDEs
|
||||
NuttX buildroot Toolchain
|
||||
USB Device Controller Functions
|
||||
OLED
|
||||
LEDs
|
||||
Nucleus 2G Configuration Options
|
||||
Configurations
|
||||
|
||||
@ -208,6 +208,57 @@ NuttX buildroot Toolchain
|
||||
|
||||
NOTE: This is an OABI toolchain.
|
||||
|
||||
LEDs
|
||||
^^^^
|
||||
|
||||
If CONFIG_ARCH_LEDS is defined, then support for the Nucleus-2G LEDs will be
|
||||
included in the build. See:
|
||||
|
||||
- configs/nucleus2g/include/board.h - Defines LED constants, types and
|
||||
prototypes the LED interface functions.
|
||||
|
||||
- configs/nucleus2g/src/nucleus2g_internal.h - GPIO settings for the LEDs.
|
||||
|
||||
- configs/nucleus2g/src/up_leds.c - LED control logic.
|
||||
|
||||
The Nucleus2G has 3 LEDs... two on the Babel CAN board and a "heartbeat" LED."
|
||||
The LEDs on the Babel CAN board are capabl of OFF/GREEN/RED/AMBER status.
|
||||
In normal usage, the two LEDs on the Babel CAN board would show CAN status, but if
|
||||
CONFIG_ARCH_LEDS is defined, these 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 HEARTBEAT */
|
||||
#define LED_STARTED 0 /* OFF OFF OFF */
|
||||
#define LED_HEAPALLOCATE 1 /* GREEN OFF OFF */
|
||||
#define LED_IRQSENABLED 2 /* OFF GREEN OFF */
|
||||
#define LED_STACKCREATED 3 /* OFF OFF OFF */
|
||||
|
||||
#define LED_INIRQ 4 /* NC NC ON (momentary) */
|
||||
#define LED_SIGNAL 5 /* NC NC ON (momentary) */
|
||||
#define LED_ASSERTION 6 /* NC NC ON (momentary) */
|
||||
#define LED_PANIC 7 /* NC NC ON (1Hz flashing) */
|
||||
|
||||
After the system is booted, this logic will no longer use LEDs 1 and 2. They
|
||||
are then available for use the application software using lpc17_led1() and
|
||||
lpc17_led2():
|
||||
|
||||
enum lpc17_ledstate_e
|
||||
{
|
||||
LPC17_LEDSTATE_OFF = 0,
|
||||
LPC17_LEDSTATE_GREEN = 1,
|
||||
LPC17_LEDSTATE_RED = 2,
|
||||
LPC17_LEDSTATE_AMBER = (LPC17_LEDSTATE_GREEN|LPC17_LEDSTATE_RED),
|
||||
};
|
||||
|
||||
EXTERN void lpc17_led1(enum lpc17_ledstate_e state);
|
||||
EXTERN void lpc17_led2(enum lpc17_ledstate_e state);
|
||||
|
||||
The heartbeat LED is illuminated during all interrupt and signal procressing.
|
||||
Normally, it will glow dimly to inicate that the LPC17xx is taking interrupts.
|
||||
On an assertion PANIC, it will flash at 1Hz.
|
||||
|
||||
Nucleus 2G Configuration Options
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -127,17 +127,24 @@
|
||||
* In normal usage, the two LEDs on the Babel CAN board would show CAN status, but if
|
||||
* CONFIG_ARCH_LEDS is defined, these 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 HEARTBEAT */
|
||||
#define LED_STARTED 0 /* OFF OFF OFF */
|
||||
#define LED_HEAPALLOCATE 1 /* GREEN OFF OFF */
|
||||
#define LED_IRQSENABLED 2 /* OFF GREEN OFF */
|
||||
#define LED_STACKCREATED 3 /* GREEN GREEN OFF */
|
||||
#define LED_STACKCREATED 3 /* OFF OFF OFF */
|
||||
|
||||
#define LED_INIRQ 4 /* NC NC ON */
|
||||
#define LED_SIGNAL 5 /* NC RED NC */
|
||||
#define LED_ASSERTION 6 /* RED NC NC */
|
||||
#define LED_PANIC 7 /* RED RED NC (1Hz flashing) */
|
||||
/* After the system is booted, this logic will no longer use LEDs 1 and 2. They
|
||||
* are available for use the application software using lpc17_led1() and lpc17_led2()
|
||||
* (prototyped below)
|
||||
*/
|
||||
/* LED1 LED2 HEARTBEAT */
|
||||
#define LED_INIRQ 4 /* NC NC ON (momentary) */
|
||||
#define LED_SIGNAL 5 /* NC NC ON (momentary) */
|
||||
#define LED_ASSERTION 6 /* NC NC ON (momentary) */
|
||||
#define LED_PANIC 7 /* NC NC ON (1Hz flashing) */
|
||||
|
||||
/* Alternate pin selections *********************************************************/
|
||||
/* UART1 -- Not connected */
|
||||
@ -175,10 +182,23 @@
|
||||
#define GPIO_SSP1_SCK GPIO_SSP1_SCK_1
|
||||
|
||||
/************************************************************************************
|
||||
* Public Data
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifdef CONFIG_ARCH_LEDS
|
||||
enum lpc17_ledstate_e
|
||||
{
|
||||
LPC17_LEDSTATE_OFF = 0,
|
||||
LPC17_LEDSTATE_GREEN = 1,
|
||||
LPC17_LEDSTATE_RED = 2,
|
||||
LPC17_LEDSTATE_AMBER = (LPC17_LEDSTATE_GREEN|LPC17_LEDSTATE_RED),
|
||||
};
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Public Data
|
||||
************************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
@ -203,6 +223,19 @@ extern "C" {
|
||||
|
||||
EXTERN void lpc17_boardinitialize(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: lpc17_led1 and 2
|
||||
*
|
||||
* Description:
|
||||
* Once the system has booted, these functions can be used to control LEDs 1 and 2
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_LEDS
|
||||
EXTERN void lpc17_led1(enum lpc17_ledstate_e state);
|
||||
EXTERN void lpc17_led2(enum lpc17_ledstate_e state);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
@ -113,12 +113,12 @@
|
||||
#define NUCLEUS2G_232_ENABLE (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT2 | GPIO_PIN5)
|
||||
#define NUCLEUS2G_232_POWERSAVE (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT2 | GPIO_PIN5)
|
||||
#define NUCLEUS2G_232_VALID (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN5)
|
||||
#define NUCLEUS2G_HEARTBEAT (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT2 | GPIO_PIN11)
|
||||
#define NUCLEUS2G_HEARTBEAT (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT2 | GPIO_PIN11)
|
||||
#define NUCLEUS2G_EXTRA_LED (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT2 | GPIO_PIN12)
|
||||
#define NUCLEUS2G_5V_ENABLE (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT2 | GPIO_PIN13)
|
||||
#define NUCLEUS2G_5V_ENABLE (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT2 | GPIO_PIN13)
|
||||
#define NUCLEUS2G_5V_DISABLE (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT2 | GPIO_PIN13)
|
||||
|
||||
#define NUCLEUS2G_MMCSD_CS (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN16)
|
||||
#define NUCLEUS2G_MMCSD_CS (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN16)
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
|
@ -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,195 +103,20 @@
|
||||
* 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 */
|
||||
|
Loading…
Reference in New Issue
Block a user