From 19b7bd921777f6d47370159850cb2ffdb94aaf14 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Sat, 17 Nov 2007 10:16:48 +0000 Subject: [PATCH] Fixed watchdog support for the MSP430. It now works as intended --- cpu/msp430/watchdog.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/cpu/msp430/watchdog.c b/cpu/msp430/watchdog.c index b33984323..f00d2f58f 100644 --- a/cpu/msp430/watchdog.c +++ b/cpu/msp430/watchdog.c @@ -28,27 +28,39 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: watchdog.c,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $ + * @(#)$Id: watchdog.c,v 1.2 2007/11/17 10:16:48 adamdunkels Exp $ */ #include #include "dev/watchdog.h" -/*------------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ void watchdog_init(void) { - WDTCTL = WDT_ARST_1000 + WDTNMI + WDTNMIES; + /* The MSP430 watchdog is enabled at boot-up, so we stop it during + initialization. */ + watchdog_stop(); } -/*------------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ void -watchdog_restart(void) +watchdog_start(void) { - WDTCTL = WDT_ARST_1000 + WDTNMI + WDTNMIES; + /* We setup the watchdog to reset the device after one second, + unless watchdog_periodic() is called. */ + WDTCTL = WDTPW | WDTCNTCL | WDT_ARST_1000; } -/*------------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ +void +watchdog_periodic(void) +{ + /* This function is called periodically to restart the watchdog + timer. */ + WDTCTL = (WDTCTL & 0xff) | WDTPW | WDTCNTCL; +} +/*---------------------------------------------------------------------------*/ void watchdog_stop(void) { - WDTCTL = WDTPW + WDTHOLD + WDTNMI + WDTNMIES; + WDTCTL = WDTPW | WDTHOLD; } -/*------------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/