Contiki-NG
watchdog.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Nordic Semiconductor
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  */
30 /**
31  * \addtogroup nrf52832-dev Device drivers
32  * @{
33  *
34  * \addtogroup nrf52832-watchdog Watchdog driver
35  * @{
36  *
37  * \file
38  * Contiki compatible watchdog driver implementation.
39  * \author
40  * Wojciech Bober <wojciech.bober@nordicsemi.no>
41  */
42 #include <nrf_drv_wdt.h>
43 #include "app_error.h"
44 #include "contiki.h"
45 
46 static nrf_drv_wdt_channel_id wdt_channel_id;
47 static uint8_t wdt_initialized = 0;
48 
49 /**
50  * \brief WDT events handler.
51  */
52 static void wdt_event_handler(void)
53 {
54  LEDS_OFF(LEDS_MASK);
55 }
56 
57 /*---------------------------------------------------------------------------*/
58 void
60 {
61  ret_code_t err_code;
62  err_code = nrf_drv_wdt_init(NULL, &wdt_event_handler);
63  APP_ERROR_CHECK(err_code);
64  err_code = nrf_drv_wdt_channel_alloc(&wdt_channel_id);
65  APP_ERROR_CHECK(err_code);
66  wdt_initialized = 1;
67 }
68 /*---------------------------------------------------------------------------*/
69 void
71 {
72  if(wdt_initialized) {
73  nrf_drv_wdt_enable();
74  }
75 }
76 /*---------------------------------------------------------------------------*/
77 void
79 {
80  if(wdt_initialized) {
81  nrf_drv_wdt_channel_feed(wdt_channel_id);
82  }
83 }
84 /*---------------------------------------------------------------------------*/
85 void
87 {
88  NVIC_SystemReset();
89 }
90 /**
91  * @}
92  * @}
93  */
void watchdog_reboot(void)
Keeps control until the WDT throws a reset signal.
Definition: watchdog.c:94
static void wdt_event_handler(void)
WDT events handler.
Definition: watchdog.c:52
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:72
void watchdog_init(void)
Initialisation function for the WDT.
Definition: watchdog.c:63
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:85