From fbd527bc8f6a3a008c3fc8ad702258d6c465fdf4 Mon Sep 17 00:00:00 2001 From: bg- Date: Thu, 17 Aug 2006 15:42:42 +0000 Subject: [PATCH] Different and hopefully correct low power management. --- platform/sky/Makefile | 4 ++-- platform/sky/dhclient.c | 21 +++++++++++++++------ platform/sky/gateway.c | 33 +++++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/platform/sky/Makefile b/platform/sky/Makefile index 2ac29fe49..6f0503bbf 100644 --- a/platform/sky/Makefile +++ b/platform/sky/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.2 2006/08/11 13:37:21 bg- Exp $ +# $Id: Makefile,v 1.3 2006/08/17 15:42:42 bg- Exp $ # # This makefile requires GNU make! @@ -18,7 +18,7 @@ SRCDIRS = dev ../../cpu/msp430 ${addprefix $(CORE)/,sys dev net lib loader} ../ MCU=msp430x1611 -ARCH=msp430.o leds.o leds-arch.o watchdog.o lpm.o light.o button.o spi.o ds2411.o rom.o xmem.o +ARCH=msp430.o leds.o leds-arch.o watchdog.o light.o button.o spi.o ds2411.o rom.o xmem.o SYSTEM=process.o procinit.o service.o clock.o etimer.o timer.o \ elfloader.o symtab.o UIP=uip.o uiplib.o tcpip.o uip-fw.o uip-fw-service.o uipbuf.o \ diff --git a/platform/sky/dhclient.c b/platform/sky/dhclient.c index e5a1cc219..408ea544d 100644 --- a/platform/sky/dhclient.c +++ b/platform/sky/dhclient.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)$Id: dhclient.c,v 1.2 2006/08/09 16:13:40 bg- Exp $ + * @(#)$Id: dhclient.c,v 1.3 2006/08/17 15:42:42 bg- Exp $ */ /* @@ -52,6 +52,8 @@ #include #include +#include + #include "contiki.h" /* Also IP output. */ @@ -61,7 +63,6 @@ #include "dev/slip.h" #include "dev/cc2420.h" -#include "dev/lpm.h" #include "dev/ds2411.h" #include "dev/leds.h" #include "dev/light.h" @@ -100,7 +101,7 @@ main(int argc, char **argv) leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE); slip_arch_init(); /* Must come before first printf */ printf("Starting %s " - "($Id: dhclient.c,v 1.2 2006/08/09 16:13:40 bg- Exp $)\n", __FILE__); + "($Id: dhclient.c,v 1.3 2006/08/17 15:42:42 bg- Exp $)\n", __FILE__); ds2411_init(); sensors_light_init(); cc2420_init(); @@ -141,13 +142,21 @@ main(int argc, char **argv) * This is the scheduler loop. */ printf("process_run()...\n"); - lpm_on(); while (1) { do { /* Reset watchdog. */ } while(process_run() > 0); - /* Idle processing. */ - LPM_SLEEP(); + + /* + * Idle processing. + */ + int s = splhigh(); /* Disable interrupts. */ + if(process_nevents() != 0) { + splx(s); /* Re-enable interrupts. */ + } else { + /* Re-enable interrupts and go to sleep atomically. */ + _BIS_SR(GIE | SCG0 | CPUOFF); /* LPM1 sleep. */ + } } return 0; diff --git a/platform/sky/gateway.c b/platform/sky/gateway.c index ad2653040..3a8e8cd5a 100644 --- a/platform/sky/gateway.c +++ b/platform/sky/gateway.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)$Id: gateway.c,v 1.2 2006/08/09 16:13:40 bg- Exp $ + * @(#)$Id: gateway.c,v 1.3 2006/08/17 15:42:42 bg- Exp $ */ /* @@ -56,6 +56,8 @@ #include #include +#include + #include "contiki.h" /* Also IP output. */ @@ -64,7 +66,6 @@ #include "dev/slip.h" #include "dev/cc2420.h" -#include "dev/lpm.h" #include "dev/ds2411.h" #include "dev/leds.h" #include "dev/light.h" @@ -83,6 +84,18 @@ #include "net/psock.h" void *force_psock_inclusion = &psock_init; void *force_button_inclusion = &button_init; +#if 0 +int +force_float_inclusion() +{ + extern int __fixsfsi; + extern int __floatsisf; + extern int __mulsf3; + extern int __subsf3; + + return __fixsfsi + __floatsisf + __mulsf3 + __subsf3; +} +#endif void uip_log(char *msg) { puts(msg); } @@ -110,7 +123,7 @@ main(int argc, char **argv) leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE); slip_arch_init(); /* Must come before first printf */ printf("Starting %s " - "($Id: gateway.c,v 1.2 2006/08/09 16:13:40 bg- Exp $)\n", __FILE__); + "($Id: gateway.c,v 1.3 2006/08/17 15:42:42 bg- Exp $)\n", __FILE__); ds2411_init(); sensors_light_init(); cc2420_init(); @@ -156,13 +169,21 @@ main(int argc, char **argv) * This is the scheduler loop. */ printf("process_run()...\n"); - lpm_on(); while (1) { do { /* Reset watchdog. */ } while(process_run() > 0); - /* Idle processing. */ - LPM_SLEEP(); + + /* + * Idle processing. + */ + int s = splhigh(); /* Disable interrupts. */ + if(process_nevents() != 0) { + splx(s); /* Re-enable interrupts. */ + } else { + /* Re-enable interrupts and go to sleep atomically. */ + _BIS_SR(GIE | SCG0 | CPUOFF); /* LPM1 sleep. */ + } } return 0;