Contiki 3.x
watchdog-cc2430.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Loughborough University - Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  */
31 
32 /**
33  * \file
34  * Hardware-dependent functions used for the cc2430 watchdog timer.
35  *
36  * This file contains an ISR and must reside in the HOME bank.
37  *
38  * \author
39  * George Oikonomou - <oikonomou@users.sourceforge.net>
40  */
41 
42 #include "sys/energest.h"
43 #include "cc2430_sfr.h"
44 #include "contiki-conf.h"
45 #include "dev/watchdog-cc2430.h"
46 
47 /*---------------------------------------------------------------------------*/
48 /* The watchdog only throws interrupts in timer mode */
49 #if WDT_TIMER_MODE
50 #pragma save
51 #if CC_CONF_OPTIMIZE_STACK_SIZE
52 #pragma exclude bits
53 #endif
54 void
55 cc4230_watchdog_ISR(void) __interrupt(WDT_VECTOR)
56 {
57  EA = 0;
58  ENERGEST_ON(ENERGEST_TYPE_IRQ);
59  /* Do something */
60  IRCON2 &= ~WDTIF;
61  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
62  EA = 1;
63 }
64 #pragma restore
65 #endif
66 /*---------------------------------------------------------------------------*/
67 void
69 {
70  WDCTL = WDT_TIMER_MODE | WDT_INTERVAL;
71 
72 #if WDT_TIMER_MODE
73  /* Enable the watchdog interrupts in timer mode */
74  IEN2 |= WDTIE;
75 #endif
76  return;
77 }
78 /*---------------------------------------------------------------------------*/
79 void
80 watchdog_start(void)
81 {
82  WDCTL |= WDT_EN;
83 }
84 /*---------------------------------------------------------------------------*/
85 void
87 {
88 #if WDT_TIMER_MODE
89  /* In timer mode, all we need to do is write 1 to WDT:CLR[0] */
90  WDCTL |= WDT_CLR0;
91 #else
92  /* Write the 'clear' sequence while maintaining mode and interval setting */
93  WDCTL = (WDCTL & 0x0F) | WDT_CLR3 | WDT_CLR1;
94  WDCTL = (WDCTL & 0x0F) | WDT_CLR2 | WDT_CLR0;
95 #endif
96 }
97 /*---------------------------------------------------------------------------*/
98 void
99 watchdog_stop(void)
100 {
101 #if WDT_TIMER_MODE
102  /* In timer mode, the watchdog can actually be stopped */
103  WDCTL &= ~WDT_EN;
104  IRCON2 &= ~WDTIF;
105 #else
106  /* In watchdog mode, stopping is impossible so we just reset the timer */
108 #endif
109 }
110 /*---------------------------------------------------------------------------*/
111 void
112 watchdog_reboot(void)
113 {
114 #if WDT_TIMER_MODE
115  /* Switch modes to watchdog, minimum interval, enable */
116  WDCTL = WDT_EN | WDT_TIMEOUT_2_MSEC;
117 #else
118  /* Let's get this over with ASAP */
119  WDCTL = WDT_TIMEOUT_2_MSEC;
120 #endif
121  /* Dis-acknowledge all interrupts while we wait for the dog to bark */
123  /* NOP till the dog barks... */
124  while(1) {
125  __asm
126  nop
127  __endasm;
128  }
129 }
CC2430 registers header file for CC2430.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:49
void watchdog_reboot(void)
Keeps control until the WDT throws a reset signal.
Definition: watchdog.c:128
Header file for the energy estimation mechanism
void watchdog_stop(void)
In watchdog mode, the WDT can not be stopped.
Definition: watchdog.c:58
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:64
Hardware-dependent header file for the cc2430 watchdog timer.
#define DISABLE_INTERRUPTS()
Disable interrupts, saving the previous state so it can be later restored with RESTORE_INTERRUPTS().
Definition: gnu.h:405
void watchdog_init(void)
Copyright (c) 2014, Analog Devices, Inc.
Definition: watchdog.c:42