Contiki-NG
watchdog.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
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  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup cc2538
33  * @{
34  *
35  * \defgroup cc2538-wdt cc2538 watchdog timer driver
36  *
37  * Driver for the cc2538 Watchdog Timer
38  * @{
39  *
40  * \file
41  * Implementation of the cc2538 watchdog driver. The peripheral runs in
42  * watchdog mode.
43  */
44 #include "contiki.h"
45 #include "reg.h"
46 #include "cpu.h"
47 #include "dev/smwdthrosc.h"
48 /*---------------------------------------------------------------------------*/
49 /* Enabled by default */
50 #ifndef WATCHDOG_CONF_ENABLE
51 #define WATCHDOG_CONF_ENABLE 1
52 #endif
53 
54 #if WATCHDOG_CONF_ENABLE
55 #define WATCHDOG_ENABLE SMWDTHROSC_WDCTL_EN
56 #else
57 #define WATCHDOG_ENABLE 0
58 #endif
59 /*---------------------------------------------------------------------------*/
60 /** \brief Initialisation function for the WDT. Currently simply explicitly
61  * sets the WDT interval to max interval */
62 void
64 {
65  /* Max interval, don't enable yet */
66  REG(SMWDTHROSC_WDCTL) = 0;
67 }
68 /*---------------------------------------------------------------------------*/
69 /** \brief Starts the WDT in watchdog mode if enabled by user configuration,
70  * maximum interval */
71 void
73 {
74  /* Max interval (32768), watchdog mode, enable if configured to do so */
75  REG(SMWDTHROSC_WDCTL) = WATCHDOG_ENABLE;
76 }
77 /*---------------------------------------------------------------------------*/
78 /**
79  * \brief Writes the WDT clear sequence.
80  *
81  * Due to how the SMWDTHROSC_WDCTL works, it is OK to simply write these bits
82  * rather than use RMW operations.
83  */
84 void
86 {
89 }
90 /*---------------------------------------------------------------------------*/
91 /** \brief Keeps control until the WDT throws a reset signal. Starts the WDT
92  * if not already started. */
93 void
95 {
97 
98  /*
99  * If the WDT is not started, set minimum interval and start
100  * If the WDT is started, this will have no effect
101  */
103 
104  while(1);
105 }
106 /**
107  * @}
108  * @}
109  */
#define SMWDTHROSC_WDCTL_CLR_2
Clear timer mask[2].
Definition: smwdthrosc.h:69
void watchdog_reboot(void)
Keeps control until the WDT throws a reset signal.
Definition: watchdog.c:94
#define INTERRUPTS_DISABLE()
Disables all CPU interrupts.
Definition: cpu.h:54
Header file with register manipulation macro definitions.
#define SMWDTHROSC_WDCTL_EN
Enable mask.
Definition: smwdthrosc.h:72
#define SMWDTHROSC_WDCTL_CLR_0
Clear timer mask[0].
Definition: smwdthrosc.h:71
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:72
#define SMWDTHROSC_WDCTL_INT
Interval Select mask.
Definition: smwdthrosc.h:74
#define SMWDTHROSC_WDCTL
Watchdog Control.
Definition: smwdthrosc.h:50
Header file with prototypes for interrupt control on the cc2538 Cortex-M3 micro.
#define SMWDTHROSC_WDCTL_CLR_1
Clear timer mask[1].
Definition: smwdthrosc.h:70
void watchdog_init(void)
Initialisation function for the WDT.
Definition: watchdog.c:63
Header file with register declarations and bit masks for the cc2538 Sleep Timer and Watchdog...
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:85
#define SMWDTHROSC_WDCTL_CLR_3
Clear timer mask[3].
Definition: smwdthrosc.h:68