9
0
Fork 0

Add logic to sleep in lpc17xx idle loop

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3329 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2011-03-02 14:43:28 +00:00
parent 3dc8584574
commit 835392d0f1
11 changed files with 187 additions and 35 deletions

View File

@ -1483,6 +1483,9 @@
5.19 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* arch/arm/stm32/stm32_idle.c -- During idle times, the STM32 now uses the
WFI instruction to sleep in a reduced power mode until the next interrupt
occurs (Contributed by Uros Platise).
* NSH: 'mem' command renamed to 'free'. Output is now more similar to the
Linux 'free' command.
* NSH: Correct a redirection bug in NSH. The following would not work; it
@ -1500,7 +1503,13 @@
nsh> cat test.txt
This is a test
* drvers/pipes/pipe_common.c: Driver open method eas not returning an EINTR
* drivers/pipes/pipe_common.c: Driver open method eas not returning an EINTR
error when it received a signal. Instead, it just re-started the wait. This
makes it impossible to kill a background pipe operation from NSH.
* include/stdint.h -- Correct some errors in conditional compilation (submitted
by Johannes Hampel).
* arch/arm/lpc17xx/lp17_idle.c -- Uses the same logic as the STM32: uses the
WFI instruction to sleep in a reduced power mode until the next interrupt
occurs.
* configs/olimex-lpc1766stk -- Added an LED encoded to indicate if the LPC1766
is in sleeping.

View File

@ -2085,6 +2085,9 @@ buildroot-1.9 2011-02-10 &lt;spudmonkey@racsa.co.cr&gt;
<ul><pre>
nuttx-5.19 2011-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
* arch/arm/stm32/stm32_idle.c -- During idle times, the STM32 now uses the
WFI instruction to sleep in a reduced power mode until the next interrupt
occurs (Contributed by Uros Platise).
* NSH: 'mem' command renamed to 'free'. Output is now more similar to the
Linux 'free' command.
* NSH: Correct a redirection bug in NSH. The following would not work; it
@ -2102,9 +2105,16 @@ nuttx-5.19 2011-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
nsh> cat test.txt
This is a test
* drvers/pipes/pipe_common.c: Driver open method eas not returning an EINTR
* drivers/pipes/pipe_common.c -- Driver open method eas not returning an EINTR
error when it received a signal. Instead, it just re-started the wait. This
makes it impossible to kill a background pipe operation from NSH.
* include/stdint.h -- Correct some errors in conditional compilation (submitted
by Johannes Hampel).
* arch/arm/lpc17xx/lp17_idle.c -- Uses the same logic as the STM32: uses the
WFI instruction to sleep in a reduced power mode until the next interrupt
occurs.
* configs/olimex-lpc1766stk -- Added an LED encoded to indicate if the LPC1766
is in sleeping.
pascal-2.1 2011-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;

View File

@ -87,6 +87,10 @@ o Memory Managment (mm/)
Description: Add an option to free all memory allocated by a task when the
task exits. This is probably not be worth the overhead for a
deeply embedded system.
There would be complexities with this implementation as well
because often one task allocates memory and then passes the
memory to another: The task that "owns" the memory may not
be the same as the task that allocated the memory.
Status: Open
Priority: Medium/Low, a good feature to prevent memory leaks but would
have negative impact on memory usage and code size.

View File

@ -1,7 +1,7 @@
############################################################################
# arch/arm/src/lpc17xx/Make.defs
#
# Copyright (C) 2010 Gregory Nutt. All rights reserved.
# Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
#
# Redistribution and use in source and binary forms, with or without
@ -41,7 +41,7 @@ HEAD_ASRC = lpc17_vectors.S
CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S
CMN_CSRCS = up_assert.c up_blocktask.c up_copystate.c up_createstack.c \
up_mdelay.c up_udelay.c up_exit.c up_idle.c up_initialize.c \
up_mdelay.c up_udelay.c up_exit.c up_initialize.c \
up_initialstate.c up_interruptcontext.c up_modifyreg8.c \
up_modifyreg16.c up_modifyreg32.c up_releasepending.c \
up_releasestack.c up_reprioritizertr.c up_schedulesigaction.c \
@ -52,8 +52,8 @@ CMN_CSRCS = up_assert.c up_blocktask.c up_copystate.c up_createstack.c \
CHIP_ASRCS =
CHIP_CSRCS = lpc17_allocateheap.c lpc17_clockconfig.c lpc17_clrpend.c \
lpc17_gpio.c lpc17_irq.c lpc17_lowputc.c lpc17_serial.c \
lpc17_spi.c lpc17_ssp.c lpc17_start.c lpc17_timerisr.c
lpc17_gpio.c lpc17_idle.c lpc17_irq.c lpc17_lowputc.c \
lpc17_serial.c lpc17_spi.c lpc17_ssp.c lpc17_start.c lpc17_timerisr.c
# Configuration-dependent LPC17xx files

View File

@ -0,0 +1,104 @@
/****************************************************************************
* arch/arm/src/lpc17/lpc17_idle.c
*
* Copyright (C) 2011 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 <arch/board/board.h>
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include "up_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Does the board support an IDLE LED to indicate that the board is in the
* IDLE state?
*/
#if defined(CONFIG_ARCH_LEDS) && defined(LED_IDLE)
# define BEGIN_IDLE() up_ledon(LED_IDLE)
# define END_IDLE() up_ledoff(LED_IDLE)
#else
# define BEGIN_IDLE()
# define END_IDLE()
#endif
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_idle
*
* Description:
* up_idle() is the logic that will be executed when their is no other
* ready-to-run task. This is processor idle time and will continue until
* some interrupt occurs to cause a context switch from the idle task.
*
* Processing in this state may be processor-specific. e.g., this is where
* power management operations might be performed.
*
****************************************************************************/
void up_idle(void)
{
#if defined(CONFIG_SUPPRESS_INTERRUPTS) || defined(CONFIG_SUPPRESS_TIMER_INTS)
/* If the system is idle and there are no timer interrupts, then process
* "fake" timer interrupts. Hopefully, something will wake up.
*/
sched_process_timer();
#else
/* Sleep until an interrupt occurs to save power */
BEGIN_IDLE();
asm("WFI");
END_IDLE();
#endif
}

View File

@ -250,6 +250,7 @@ LEDs
#define LED_SIGNAL 5 /* NC NC ON (momentary) */
#define LED_ASSERTION 6 /* NC NC ON (momentary) */
#define LED_PANIC 7 /* NC NC ON (0.5Hz flashing) */
#undef LED_IDLE /* Sleep mode indication not supported */
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

View File

@ -329,6 +329,9 @@ LEDs
if you see this at all, it probably means that the system is hanging up
somewhere in the initialization phases.
- ON means that the OS completed initialization.
- Glowing means that the LPC17 is running in a reduced power mode: LED1 is
turned off when the processor enters sleep mode and back on when it wakesup
up.
LED2:
- ON/OFF toggles means that various events are happening.
@ -341,25 +344,32 @@ LEDs
NOTE: LED2 is controlled by a jumper labeled: ACC_IRQ/LED2. That jump must be
in the LED2 position in order to support LED2.
LED1 LED2 Meaning
----- -------- --------------------------------------------------------------------
OFF OFF Still initializing and there is no interrupt activity.
Initialization is very fast so if you see this, it probably means
that the system is hung up somewhere in the initialization phases.
OFF Glowing Still initializing (see above) but taking interrupts.
OFF ON This would mean that (1) initialization did not complete but the
software is hung, perhaps in an infinite loop, somewhere inside
of an interrupt handler.
OFF Flashing Ooops! We crashed before finishing initialization.
LED1 LED2 Meaning
------- -------- --------------------------------------------------------------------
OFF OFF Still initializing and there is no interrupt activity.
Initialization is very fast so if you see this, it probably means
that the system is hung up somewhere in the initialization phases.
OFF Glowing Still initializing (see above) but taking interrupts.
OFF ON This would mean that (1) initialization did not complete but the
software is hung, perhaps in an infinite loop, somewhere inside
of an interrupt handler.
OFF Flashing Ooops! We crashed before finishing initialization (or, perhaps
after initialization, during an interrupt while the LPC17xx was
sleeping -- see below).
ON OFF The system has completed initialization, but is apparently not taking
any interrupts.
ON Glowing This is the normal healthy state: The OS successfully initialized
and is taking interrupts.
ON ON This would mean that (1) the OS complete initialization, but (2)
the software is hung, perhaps in an infinite loop, somewhere inside
of a signal or interrupt handler.
ON Flashing Ooops! We crashed sometime after initialization.
ON OFF The system has completed initialization, but is apparently not taking
any interrupts.
ON Glowing The OS successfully initialized and is taking interrupts (but, for
some reason, is never entering a reduced power mode -- perhaps the
CPU is very busy?).
ON ON This would mean that (1) the OS complete initialization, but (2)
the software is hung, perhaps in an infinite loop, somewhere inside
of a signal or interrupt handler.
Glowing Glowing This is also a normal healthy state: The OS successfully initialized,
is running in reduced power mode, but taking interrupts. The glow
is very faint and you may have to dim the lights to see that LEDs are
active at all!
ON Flashing Ooops! We crashed sometime after initialization.
Using OpenOCD and GDB with an FT2232 JTAG emulator
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -136,11 +136,12 @@
#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 /* NC ON = In an interrupt handler */
#define LED_SIGNAL 2 /* NC ON = In a signal handler */
#define LED_ASSERTION 2 /* NC ON = In an assertion */
#define LED_PANIC 2 /* NC ON = Oops! We crashed. (flashing) */
#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) */
/* Alternate pin selections *********************************************************/
/* CAN1 GPIO PIN SIGNAL NAME

View File

@ -2,7 +2,7 @@
* configs/olimex-lpc1766stk/src/up_leds.c
* arch/arm/src/board/up_leds.c
*
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -92,6 +92,8 @@
* Private Data
****************************************************************************/
static bool g_uninitialized = true;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -132,11 +134,16 @@ void up_ledon(int led)
case 1 : /* STACKCREATED */
lpc17_gpiowrite(LPC1766STK_LED1, false);
lpc17_gpiowrite(LPC1766STK_LED2, true);
g_uninitialized = false;
break;
case 2 : /* INIRQ, SIGNAL, ASSERTION, PANIC */
lpc17_gpiowrite(LPC1766STK_LED2, false);
break;
case 3 : /* IDLE */
lpc17_gpiowrite(LPC1766STK_LED1, true);
break;
}
}
@ -152,9 +159,14 @@ void up_ledoff(int led)
case 0 : /* STARTED, HEAPALLOCATE, IRQSENABLED */
case 1 : /* STACKCREATED */
lpc17_gpiowrite(LPC1766STK_LED1, true);
case 2 : /* INIRQ, SIGNAL, ASSERTION, PANIC */
lpc17_gpiowrite(LPC1766STK_LED2, true);
break;
case 3 : /* IDLE */
lpc17_gpiowrite(LPC1766STK_LED1, g_uninitialized);
break;
}
}
#endif /* CONFIG_ARCH_LEDS */

View File

@ -228,6 +228,7 @@ They are encoded as follows:
LED_SIGNAL In a signal handler*** N/C ON N/C OFF
LED_ASSERTION An assertion failed ON ON N/C OFF
LED_PANIC The system has crashed N/C N/C N/C ON
LED_IDLE STM32 is is sleep mode (Optional, not used)
* If LED1, LED2, LED3 are statically on, then NuttX probably failed to boot
and these LEDs will give you some indication of where the failure was

View File

@ -1,7 +1,7 @@
/****************************************************************************
* include/stdint.h
*
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -60,7 +60,7 @@
#define INT16_MAX 0x7fff
#define UINT16_MAX 0xffff
#ifdef __INT64_DEFINED
#ifdef __INT24_DEFINED
# define INT24_MIN 0x800000
# define INT24_MAX 0x7fffff
# define UINT24_MAX 0xffffff
@ -86,7 +86,7 @@
#define INT16_LEASTN_MAX 0x7fff
#define UINT16_LEASTN_MAX 0xffff
#ifdef __INT64_DEFINED
#ifdef __INT24_DEFINED
# define INT24_LEASTN_MIN 0x800000
# define INT24_LEASTN_MAX 0x7fffff
# define UINT24_LEASTN_MAX 0xffffff
@ -112,7 +112,7 @@
#define INT16_FASTN_MAX 0x7fff
#define UINT16_FASTN_MAX 0xffff
#ifdef __INT64_DEFINED
#ifdef __INT24_DEFINED
# define INT24_FASTN_MIN 0x800000
# define INT24_FASTN_MAX 0x7fffff
# define UINT24_FASTN_MAX 0xffffff