Contiki-NG
watchdog-arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, 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  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30  /**
31  * \addtogroup cc13xx-cc26xx-cpu
32  * @{
33  *
34  * \defgroup cc13xx-cc26xx-watchdog CC13xx/CC26xx watchdog timer driver
35  *
36  * Driver for the CC13xx/CC26xx Watchdog Timer
37  *
38  * This file is not called watchdog.c because the filename is in use by
39  * TI CC26xxware/CC13xxware
40  * @{
41  *
42  * \file
43  * Implementation of the CC13xx/CC26xx watchdog driver.
44  */
45 /*---------------------------------------------------------------------------*/
46 #include "contiki.h"
47 #include "dev/watchdog.h"
48 /*---------------------------------------------------------------------------*/
49 #include <Board.h>
50 
51 #include <ti/drivers/Watchdog.h>
52 /*---------------------------------------------------------------------------*/
53 #include <stdbool.h>
54 #include <stdint.h>
55 /*---------------------------------------------------------------------------*/
56 #define WATCHDOG_DISABLE WATCHDOG_CONF_DISABLE
57 #define WATCHDOG_TIMER_TOP WATCHDOG_CONF_TIMER_TOP
58 /*---------------------------------------------------------------------------*/
59 static Watchdog_Handle wdt_handle;
60 /*---------------------------------------------------------------------------*/
61 /**
62  * \brief Initialises the Watchdog module.
63  *
64  * Simply sets the reload counter to a default value. The WDT is not
65  * started yet. To start it, watchdog_start() must be called.
66  */
67 void
69 {
70  if(WATCHDOG_DISABLE) {
71  return;
72  }
73 
74  Watchdog_init();
75 
76  Watchdog_Params wdt_params;
77  Watchdog_Params_init(&wdt_params);
78 
79  wdt_params.resetMode = Watchdog_RESET_ON;
80  wdt_params.debugStallMode = Watchdog_DEBUG_STALL_ON;
81 
82  wdt_handle = Watchdog_open(Board_WATCHDOG0, &wdt_params);
83 }
84 /*---------------------------------------------------------------------------*/
85 /**
86  * \brief Start the Watchdog.
87  */
88 void
90 {
91  if(WATCHDOG_DISABLE) {
92  return;
93  }
94 
96 }
97 /*---------------------------------------------------------------------------*/
98 /**
99  * \brief Refresh (feed) the Watchdog.
100  */
101 void
103 {
104  if(WATCHDOG_DISABLE) {
105  return;
106  }
107 
108  Watchdog_setReload(wdt_handle, WATCHDOG_TIMER_TOP);
109 }
110 /*---------------------------------------------------------------------------*/
111 /**
112  * \brief Stop the Watchdog such that it won't timeout and cause a
113  * system reset.
114  */
115 void
117 {
118  if(WATCHDOG_DISABLE) {
119  return;
120  }
121 
122  Watchdog_clear(wdt_handle);
123 }
124 /*---------------------------------------------------------------------------*/
125 /**
126  * \brief Manually trigger a Watchdog timeout.
127  */
128 void
130 {
131  if(WATCHDOG_DISABLE) {
132  return;
133  }
134 
135  watchdog_start();
136 
137  /* Busy loop until watchdog times out */
138  for (;;) { /* hang */ }
139 }
140 /*---------------------------------------------------------------------------*/
141 /**
142  * @}
143  * @}
144  */
void watchdog_reboot(void)
Manually trigger a Watchdog timeout.
void watchdog_init(void)
Initialises the Watchdog module.
Definition: watchdog-arch.c:68
void watchdog_periodic(void)
Refresh (feed) the Watchdog.
void watchdog_stop(void)
Stop the Watchdog such that it won&#39;t timeout and cause a system reset.
void watchdog_start(void)
Start the Watchdog.
Definition: watchdog-arch.c:89