Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
contiki-watchdog.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2014, 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 cc26xx-clocks
32
* @{
33
*
34
* \defgroup cc26xx-wdt 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
#include "contiki.h"
46
#include "dev/watchdog.h"
47
#include "
ti-lib.h
"
48
49
#include <stdbool.h>
50
#include <stdint.h>
51
/*---------------------------------------------------------------------------*/
52
/* Watchdog timer interval, in milliseconds */
53
#ifdef CONTIKI_WATCHDOG_CONF_TIMER_TOP
54
#define CONTIKI_WATCHDOG_TIMER_TOP CONTIKI_WATCHDOG_CONF_TIMER_TOP
55
#else
56
#define CONTIKI_WATCHDOG_TIMER_TOP 1100
57
#endif
58
59
#ifdef CONTIKI_WATCHDOG_CONF_LOCK_CONFIG
60
#define CONTIKI_WATCHDOG_LOCK_CONFIG CONTIKI_WATCHDOG_CONF_LOCK_CONFIG
61
#else
62
#define CONTIKI_WATCHDOG_LOCK_CONFIG 1
63
#endif
64
65
/* Convert timer interval from ms to ticks. Clock runs at 48 MHz / 32 */
66
#define WATCHDOG_TIMER_TOP_TICK ((48000 / 32) * CONTIKI_WATCHDOG_TIMER_TOP)
67
68
#define LOCK_INTERRUPTS_DISABLED 0x01
69
#define LOCK_REGISTERS_UNLOCKED 0x02
70
/*---------------------------------------------------------------------------*/
71
static
uint32_t
72
unlock_config(
void
)
73
{
74
uint32_t ret = 0;
75
bool
int_status
;
76
77
if
(CONTIKI_WATCHDOG_LOCK_CONFIG) {
78
int_status
= ti_lib_int_master_disable();
79
80
if
(ti_lib_watchdog_lock_state()) {
81
ret |= LOCK_REGISTERS_UNLOCKED;
82
ti_lib_watchdog_unlock();
83
}
84
85
ret |= (
int_status
) ? (0) : (LOCK_INTERRUPTS_DISABLED);
86
}
87
88
return
ret;
89
}
90
/*---------------------------------------------------------------------------*/
91
static
void
92
lock_config(uint32_t status)
93
{
94
if
(CONTIKI_WATCHDOG_LOCK_CONFIG) {
95
96
if
(status & LOCK_REGISTERS_UNLOCKED) {
97
ti_lib_watchdog_lock();
98
}
99
if
(status & LOCK_INTERRUPTS_DISABLED) {
100
ti_lib_int_master_enable();
101
}
102
}
103
}
104
/*---------------------------------------------------------------------------*/
105
/**
106
* \brief Initialises the CC13xx/CC26xx WDT
107
*
108
* Simply locks the config so that future calls will lock properly.
109
* The WDT is not started yet. To start it, watchdog_start() must be called.
110
*/
111
void
112
watchdog_init
(
void
)
113
{
114
lock_config(LOCK_REGISTERS_UNLOCKED);
115
}
116
/*---------------------------------------------------------------------------*/
117
/**
118
* \brief Starts the CC13xx/CC26xx WDT
119
*/
120
void
121
watchdog_start
(
void
)
122
{
123
uint32_t lock_status = unlock_config();
124
125
ti_lib_watchdog_reload_set(WATCHDOG_TIMER_TOP_TICK);
126
ti_lib_watchdog_reset_enable();
127
ti_lib_watchdog_enable();
128
129
lock_config(lock_status);
130
}
131
/*---------------------------------------------------------------------------*/
132
/**
133
* \brief Refreshes the CC13xx/CC26xx WDT
134
*/
135
void
136
watchdog_periodic
(
void
)
137
{
138
/* Clearing interrupt also resets counter */
139
ti_lib_watchdog_int_clear();
140
}
141
/*---------------------------------------------------------------------------*/
142
/**
143
* \brief Stops the WDT such that it won't timeout and cause MCU reset
144
*/
145
void
146
watchdog_stop
(
void
)
147
{
148
uint32_t lock_status = unlock_config();
149
150
ti_lib_watchdog_reset_disable();
151
152
lock_config(lock_status);
153
}
154
/*---------------------------------------------------------------------------*/
155
/**
156
* \brief Manually trigger a WDT reboot
157
*/
158
void
159
watchdog_reboot
(
void
)
160
{
161
watchdog_start
();
162
while
(1);
163
}
164
/*---------------------------------------------------------------------------*/
165
/**
166
* @}
167
* @}
168
*/
watchdog_reboot
void watchdog_reboot(void)
Manually trigger a WDT reboot.
Definition
contiki-watchdog.c:159
watchdog_stop
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.
Definition
contiki-watchdog.c:146
watchdog_start
void watchdog_start(void)
Starts the CC13xx/CC26xx WDT.
Definition
contiki-watchdog.c:121
watchdog_periodic
void watchdog_periodic(void)
Refreshes the CC13xx/CC26xx WDT.
Definition
contiki-watchdog.c:136
watchdog_init
void watchdog_init(void)
Initialises the CC13xx/CC26xx WDT.
Definition
contiki-watchdog.c:112
int_status
static uint8_t int_status(void)
Check whether a data or wake on motion interrupt has occurred.
Definition
mpu-9250-sensor.c:347
ti-lib.h
Header file with macros which rename TI CC26xxware functions.
arch
cpu
cc26x0-cc13x0
dev
contiki-watchdog.c
Generated on
for Contiki-NG by
1.17.0