2010-06-05 22:04:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* configs/nucleus2g/src/up_leds.c
|
|
|
|
* arch/arm/src/board/up_leds.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
|
|
#include "chip.h"
|
|
|
|
#include "up_arch.h"
|
|
|
|
#include "up_internal.h"
|
2010-06-13 02:57:56 +02:00
|
|
|
|
2010-06-05 22:04:21 +02:00
|
|
|
#include "lpc17_internal.h"
|
2010-06-13 02:57:56 +02:00
|
|
|
|
2010-06-05 22:04:21 +02:00
|
|
|
#include "nucleus2g_internal.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_LEDS
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-06-13 02:57:56 +02:00
|
|
|
#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
|
|
|
|
|
2010-06-05 22:04:21 +02:00
|
|
|
/* Enables debug output from this file (needs CONFIG_DEBUG with
|
|
|
|
* CONFIG_DEBUG_VERBOSE too)
|
|
|
|
*/
|
|
|
|
|
2010-07-03 03:35:53 +02:00
|
|
|
#undef LED_DEBUG /* Define to enable debug */
|
|
|
|
#undef LED_VERBOSE /* Define to enable verbose debug */
|
2010-06-05 22:04:21 +02:00
|
|
|
|
|
|
|
#ifdef LED_DEBUG
|
|
|
|
# define leddbg lldbg
|
2010-07-03 03:35:53 +02:00
|
|
|
# ifdef LED_VERBOSE
|
|
|
|
# define ledvdbg lldbg
|
|
|
|
# else
|
|
|
|
# define ledvdbg(x...)
|
|
|
|
# endif
|
2010-06-05 22:04:21 +02:00
|
|
|
#else
|
2010-07-03 03:35:53 +02:00
|
|
|
# undef LED_VERBOSE
|
2010-06-05 22:04:21 +02:00
|
|
|
# define leddbg(x...)
|
|
|
|
# define ledvdbg(x...)
|
|
|
|
#endif
|
|
|
|
|
2010-07-03 03:35:53 +02:00
|
|
|
/* Dump GPIO registers */
|
|
|
|
|
|
|
|
#ifdef LED_VERBOSE
|
|
|
|
# define led_dumpgpio(m) lpc17_dumpgpio(NUCLEUS2G_LED1_A, m)
|
|
|
|
#else
|
|
|
|
# define led_dumpgpio(m)
|
|
|
|
#endif
|
|
|
|
|
2010-06-05 22:04:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-06-13 17:42:11 +02:00
|
|
|
/* 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").
|
|
|
|
*
|
|
|
|
* LED1 LED2 HEARTBEAT
|
|
|
|
* +------- ------ -----------------------
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
|
2010-06-13 02:57:56 +02:00
|
|
|
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;
|
|
|
|
|
2010-06-05 22:04:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-06-13 02:57:56 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2010-06-24 00:00:29 +02:00
|
|
|
* Name: up_ledhb
|
2010-06-13 02:57:56 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void up_ledhb(uint8_t newstate)
|
|
|
|
{
|
|
|
|
bool ledhb = false;
|
|
|
|
|
|
|
|
switch (newstate)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case LED_OFF:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LED_ON:
|
|
|
|
ledhb = true;
|
|
|
|
break;
|
2010-06-24 00:00:29 +02:00
|
|
|
|
|
|
|
case LED_NC:
|
|
|
|
return;
|
2010-06-13 02:57:56 +02:00
|
|
|
}
|
2010-06-24 00:00:29 +02:00
|
|
|
|
2010-06-13 02:57:56 +02:00
|
|
|
lpc17_gpiowrite(NUCLEUS2G_HEARTBEAT, ledhb);
|
|
|
|
}
|
|
|
|
|
2010-06-05 22:04:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_ledinit
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void up_ledinit(void)
|
|
|
|
{
|
2010-06-13 02:57:56 +02:00
|
|
|
/* Configure all LED GPIO lines */
|
|
|
|
|
2010-07-03 03:35:53 +02:00
|
|
|
led_dumpgpio("up_ledinit() Entry)");
|
|
|
|
|
2010-06-13 02:57:56 +02:00
|
|
|
lpc17_configgpio(NUCLEUS2G_LED1_A);
|
|
|
|
lpc17_configgpio(NUCLEUS2G_LED1_B);
|
|
|
|
lpc17_configgpio(NUCLEUS2G_LED2_A);
|
|
|
|
lpc17_configgpio(NUCLEUS2G_LED2_B);
|
|
|
|
lpc17_configgpio(NUCLEUS2G_HEARTBEAT);
|
|
|
|
lpc17_configgpio(NUCLEUS2G_EXTRA_LED);
|
2010-07-03 03:35:53 +02:00
|
|
|
|
|
|
|
led_dumpgpio("up_ledinit() Exit");
|
2010-06-05 22:04:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_ledon
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void up_ledon(int led)
|
|
|
|
{
|
2010-06-13 02:57:56 +02:00
|
|
|
up_led1(g_led1on[led]);
|
|
|
|
up_led2(g_led2on[led]);
|
|
|
|
up_ledhb(g_ledhbon[led]);
|
2010-07-03 03:35:53 +02:00
|
|
|
|
|
|
|
#ifdef LED_VERBOSE
|
|
|
|
if (led != LED_INIRQ)
|
|
|
|
{
|
2010-07-03 06:58:51 +02:00
|
|
|
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);
|
2010-07-03 03:35:53 +02:00
|
|
|
}
|
|
|
|
#endif
|
2010-06-05 22:04:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_ledoff
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void up_ledoff(int led)
|
|
|
|
{
|
2010-06-13 02:57:56 +02:00
|
|
|
up_led1(g_led1off[led]);
|
|
|
|
up_led2(g_led2off[led]);
|
|
|
|
up_ledhb(g_ledhboff[led]);
|
2010-07-03 03:35:53 +02:00
|
|
|
|
|
|
|
#ifdef LED_VERBOSE
|
|
|
|
if (led != LED_INIRQ)
|
|
|
|
{
|
2010-07-03 06:58:51 +02:00
|
|
|
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);
|
2010-07-03 03:35:53 +02:00
|
|
|
}
|
|
|
|
#endif
|
2010-06-05 22:04:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_ARCH_LEDS */
|