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 nrf52840-dev Device drivers
32 * @{
33 *
34 * \addtogroup nrf52840-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 "contiki.h"
43#include <nrfx_wdt.h>
44#include "app_error.h"
45
46#include "sys/log.h"
47#define LOG_MODULE "WATCHDOG"
48#define LOG_LEVEL LOG_LEVEL_INFO
49
50static nrfx_wdt_channel_id wdt_channel_id;
51static uint8_t wdt_initialized = 0;
52
53/**
54 * \brief WDT events handler.
55 */
56static void
58{
59 LEDS_OFF(LEDS_MASK);
60}
61/*---------------------------------------------------------------------------*/
62void
64{
65 ret_code_t err_code;
66 nrfx_wdt_config_t config = NRFX_WDT_DEAFULT_CONFIG;
67 err_code = nrfx_wdt_init(&config, &wdt_event_handler);
68 APP_ERROR_CHECK(err_code);
69 err_code = nrfx_wdt_channel_alloc(&wdt_channel_id);
70 APP_ERROR_CHECK(err_code);
71 wdt_initialized = 1;
72}
73/*---------------------------------------------------------------------------*/
74void
76{
77 if(wdt_initialized) {
78 nrfx_wdt_enable();
79 }
80}
81/*---------------------------------------------------------------------------*/
82void
84{
85 if(wdt_initialized) {
86 nrfx_wdt_channel_feed(wdt_channel_id);
87 }
88}
89/*---------------------------------------------------------------------------*/
90void
92{
93 NVIC_SystemReset();
94}
95/**
96 * @}
97 * @}
98 */
void watchdog_reboot(void)
Keeps control until the WDT throws a reset signal.
Definition: watchdog.c:94
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:72
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:85
void watchdog_init(void)
Initialisation function for the WDT.
Definition: watchdog.c:63
static void wdt_event_handler(void)
WDT events handler.
Definition: watchdog.c:57
Header file for the logging system.