Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2010, Loughborough University - Computer Science 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 */ 00031 00032 /** 00033 * \file 00034 * Hardware-dependent functions used for the cc2430 watchdog timer. 00035 * 00036 * This file contains an ISR and must reside in the HOME bank. 00037 * 00038 * \author 00039 * George Oikonomou - <oikonomou@users.sourceforge.net> 00040 */ 00041 00042 #include "sys/energest.h" 00043 #include "cc2430_sfr.h" 00044 #include "contiki-conf.h" 00045 #include "dev/watchdog-cc2430.h" 00046 00047 /*---------------------------------------------------------------------------*/ 00048 /* The watchdog only throws interrupts in timer mode */ 00049 #if WDT_TIMER_MODE 00050 void 00051 cc4230_watchdog_ISR(void) __interrupt (WDT_VECTOR) 00052 { 00053 EA = 0; 00054 ENERGEST_ON(ENERGEST_TYPE_IRQ); 00055 /* Do something */ 00056 IRCON2 &= ~WDTIF; 00057 ENERGEST_OFF(ENERGEST_TYPE_IRQ); 00058 EA = 1; 00059 } 00060 #endif 00061 /*---------------------------------------------------------------------------*/ 00062 void 00063 watchdog_init(void) 00064 { 00065 WDCTL = WDT_TIMER_MODE | WDT_INTERVAL; 00066 00067 #if WDT_TIMER_MODE 00068 /* Enable the watchdog interrupts in timer mode */ 00069 IEN2 |= WDTIE; 00070 #endif 00071 return; 00072 } 00073 /*---------------------------------------------------------------------------*/ 00074 void 00075 watchdog_start(void) 00076 { 00077 WDCTL |= WDT_EN; 00078 } 00079 /*---------------------------------------------------------------------------*/ 00080 void 00081 watchdog_periodic(void) 00082 { 00083 #if WDT_TIMER_MODE 00084 /* In timer mode, all we need to do is write 1 to WDT:CLR[0] */ 00085 WDCTL |= WDT_CLR0; 00086 #else 00087 /* Write the 'clear' sequence while maintaining mode and interval setting */ 00088 WDCTL = (WDCTL & 0x0F) | WDT_CLR3 | WDT_CLR1; 00089 WDCTL = (WDCTL & 0x0F) | WDT_CLR2 | WDT_CLR0; 00090 #endif 00091 } 00092 /*---------------------------------------------------------------------------*/ 00093 void 00094 watchdog_stop(void) 00095 { 00096 #if WDT_TIMER_MODE 00097 /* In timer mode, the watchdog can actually be stopped */ 00098 WDCTL &= ~WDT_EN; 00099 IRCON2 &= ~WDTIF; 00100 #else 00101 /* In watchdog mode, stopping is impossible so we just reset the timer */ 00102 watchdog_periodic(); 00103 #endif 00104 } 00105 /*---------------------------------------------------------------------------*/ 00106 void 00107 watchdog_reboot(void) 00108 { 00109 #if WDT_TIMER_MODE 00110 /* Switch modes to watchdog, minimum interval, enable */ 00111 WDCTL = WDT_EN | WDT_TIMEOUT_2_MSEC; 00112 #else 00113 /* Let's get this over with ASAP */ 00114 WDCTL = WDT_TIMEOUT_2_MSEC; 00115 #endif 00116 /* Dis-acknowledge all interrupts while we wait for the dog to bark */ 00117 DISABLE_INTERRUPTS(); 00118 /* NOP till the dog barks... */ 00119 while(1) { 00120 __asm 00121 nop 00122 __endasm; 00123 } 00124 }