Contiki-NG
watchdog-arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
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/**
32 * \addtogroup gecko
33 * @{
34 *
35 * \addtogroup gecko-dev Device drivers
36 * @{
37 *
38 * \addtogroup gecko-watchdog Watchdog driver
39 * @{
40 *
41 * \file
42 * Watchdog implementation for the gecko.
43 * \author
44 * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
45 *
46 */
47/*---------------------------------------------------------------------------*/
48#include "contiki.h"
49
50#include "em_device.h"
51#include "em_wdog.h"
52#include "em_cmu.h"
53#include "em_rmu.h"
54/*---------------------------------------------------------------------------*/
55void
57{
58 /* Enable LE interface */
59#if !defined(_SILICON_LABS_32B_SERIES_2)
60 CMU_ClockEnable(cmuClock_HFLE, true);
61 CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
62#endif
63
64#if defined(_SILICON_LABS_32B_SERIES_2_CONFIG_2)
65 CMU_ClockEnable(cmuClock_WDOG0, true);
66#endif
67
68 /* Make sure FULL reset is used on WDOG timeout */
69#if defined(_RMU_CTRL_WDOGRMODE_MASK)
70 RMU_ResetControl(rmuResetWdog, rmuResetModeFull);
71#endif
72
73 WDOG_Init_TypeDef init = WDOG_INIT_DEFAULT;
74 init.enable = false;
75
76#if defined(_WDOG_CTRL_CLKSEL_MASK)
77 init.clkSel = wdogClkSelLFRCO;
78#else
79 /* Series 2 devices select watchdog oscillator with the CMU. */
80 CMU_ClockSelectSet(cmuClock_WDOG0, cmuSelect_LFRCO);
81#endif
82
83 WDOGn_Init(DEFAULT_WDOG, &init);
84}
85/*---------------------------------------------------------------------------*/
86void
88{
89 WDOGn_Enable(WDOG0, true);
90}
91/*---------------------------------------------------------------------------*/
92void
94{
95#if defined(_CMU_HFBUSCLKEN0_LE_MASK)
96 if((CMU->HFBUSCLKEN0 & _CMU_HFBUSCLKEN0_LE_MASK) != 0) {
97 WDOGn_Feed(DEFAULT_WDOG);
98 }
99#elif defined(_CMU_CLKEN0_WDOG0_MASK)
100 if((CMU->CLKEN0 & _CMU_CLKEN0_WDOG0_MASK) != 0) {
101 WDOGn_Feed(DEFAULT_WDOG);
102 }
103#else
104 WDOGn_Feed(DEFAULT_WDOG);
105#endif
106}
107/*---------------------------------------------------------------------------*/
108void
110{
112
113 while(1);
114}
115/**
116 * @}
117 * @}
118 * @}
119 */
void watchdog_reboot(void)
Keeps control until the WDT throws a reset signal.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog-arch.c:87
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog-arch.c:93
void watchdog_init(void)
Initialisation function for the WDT.
Definition: watchdog-arch.c:56