diff --git a/cpu/msp430/watchdog.c b/cpu/msp430/watchdog.c index 421a6006a..404b23355 100644 --- a/cpu/msp430/watchdog.c +++ b/cpu/msp430/watchdog.c @@ -28,13 +28,16 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: watchdog.c,v 1.9 2010/08/24 16:23:20 joxe Exp $ + * @(#)$Id: watchdog.c,v 1.10 2010/09/22 22:12:37 adamdunkels Exp $ */ #include #include #include "dev/watchdog.h" -static int stopped = 0; +static int counter = 0; + +#define PRINT_STACK_ON_REBOOT 1 + /*---------------------------------------------------------------------------*/ #ifdef CONTIKI_TARGET_SKY static void @@ -69,20 +72,18 @@ interrupt(WDT_VECTOR) watchdog_interrupt(void) { #ifdef CONTIKI_TARGET_SKY +#if PRINT_STACK_ON_REBOOT uint8_t dummy; static uint8_t *ptr; static int i; ptr = &dummy; printstring("Watchdog reset"); - /* printstring("Watchdog reset at PC $"); - hexprint(ptr[3]); - hexprint(ptr[2]);*/ printstring("\nStack at $"); hexprint(((int)ptr) >> 8); hexprint(((int)ptr) & 0xff); printstring(":\n"); - + for(i = 0; i < 64; ++i) { hexprint(ptr[i]); printchar(' '); @@ -91,7 +92,8 @@ watchdog_interrupt(void) } } printchar('\n'); -#endif +#endif /* PRINT_STACK_ON_REBOOT */ +#endif /* CONTIKI_TARGET_SKY */ watchdog_reboot(); } @@ -101,7 +103,7 @@ watchdog_init(void) { /* The MSP430 watchdog is enabled at boot-up, so we stop it during initialization. */ - stopped = 0; + counter = 0; watchdog_stop(); IFG1 &= ~WDTIFG; @@ -113,8 +115,8 @@ watchdog_start(void) { /* We setup the watchdog to reset the device after one second, unless watchdog_periodic() is called. */ - stopped--; - if(!stopped) { + counter--; + if(counter == 0) { WDTCTL = WDTPW | WDTCNTCL | WDT_ARST_1000 | WDTTMSEL; } } @@ -124,16 +126,18 @@ watchdog_periodic(void) { /* This function is called periodically to restart the watchdog timer. */ - if(!stopped) { - WDTCTL = (WDTCTL & 0xff) | WDTPW | WDTCNTCL | WDTTMSEL;; - } + /* if(counter < 0) {*/ + WDTCTL = (WDTCTL & 0xff) | WDTPW | WDTCNTCL | WDTTMSEL; + /* }*/ } /*---------------------------------------------------------------------------*/ void watchdog_stop(void) { - WDTCTL = WDTPW | WDTHOLD; - stopped++; + counter++; + if(counter == 1) { + WDTCTL = WDTPW | WDTHOLD; + } } /*---------------------------------------------------------------------------*/ void