Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
watchdog.c
1
/*
2
* Copyright (c) 2005, Swedish Institute of Computer Science
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
* This file is part of the Contiki operating system.
30
*
31
*/
32
33
#include "contiki.h"
34
#include "dev/watchdog.h"
35
#include "isr_compat.h"
36
37
static
int
counter = 0;
38
39
#define PRINT_STACK_ON_REBOOT 0
40
41
/*---------------------------------------------------------------------------*/
42
#if PRINT_STACK_ON_REBOOT
43
#ifdef CONTIKI_TARGET_SKY
44
static
void
45
printchar(
char
c)
46
{
47
/* Transmit the data. */
48
TXBUF1 = c;
49
50
/* Loop until the transmission buffer is available. */
51
while
((IFG2 & UTXIFG1) == 0);
52
53
}
54
/*---------------------------------------------------------------------------*/
55
static
void
56
hexprint(uint8_t v)
57
{
58
const
char
hexconv[] =
"0123456789abcdef"
;
59
printchar(hexconv[v >> 4]);
60
printchar(hexconv[v & 0x0f]);
61
}
62
/*---------------------------------------------------------------------------*/
63
static
void
64
printstring(
char
*s)
65
{
66
while
(*s) {
67
printchar(*s++);
68
}
69
}
70
#endif
/* CONTIKI_TARGET_SKY */
71
#endif
/* PRINT_STACK_ON_REBOOT */
72
/*---------------------------------------------------------------------------*/
73
ISR(WDT, watchdog_interrupt)
74
{
75
#ifdef CONTIKI_TARGET_SKY
76
#if PRINT_STACK_ON_REBOOT
77
uint8_t dummy;
78
static
uint8_t *ptr;
79
static
int
i;
80
81
ptr = &dummy;
82
printstring(
"Watchdog reset"
);
83
printstring(
"\nStack at $"
);
84
hexprint(((
int
)ptr) >> 8);
85
hexprint(((
int
)ptr) & 0xff);
86
printstring(
":\n"
);
87
88
for
(i = 0; i < 64; ++i) {
89
hexprint(ptr[i]);
90
printchar(
' '
);
91
if
((i & 0x0f) == 0x0f) {
92
printchar(
'\n'
);
93
}
94
}
95
printchar(
'\n'
);
96
#endif
/* PRINT_STACK_ON_REBOOT */
97
#endif
/* CONTIKI_TARGET_SKY */
98
99
watchdog_reboot
();
100
}
101
/*---------------------------------------------------------------------------*/
102
void
103
watchdog_init
(
void
)
104
{
105
/* The MSP430 watchdog is enabled at boot-up, so we stop it during
106
initialization. */
107
counter = 0;
108
watchdog_stop
();
109
#if CONTIKI_TARGET_WISMOTE
110
SFRIFG1 &= ~WDTIFG;
111
SFRIE1 |= WDTIE;
112
#else
113
IFG1 &= ~WDTIFG;
114
IE1 |= WDTIE;
115
#endif
116
}
117
/*---------------------------------------------------------------------------*/
118
void
119
watchdog_start
(
void
)
120
{
121
/* We setup the watchdog to reset the device after one second,
122
unless watchdog_periodic() is called. */
123
counter--;
124
if
(counter == 0) {
125
WDTCTL = WDTPW | WDTCNTCL | WDT_ARST_1000 | WDTTMSEL;
126
}
127
}
128
/*---------------------------------------------------------------------------*/
129
void
130
watchdog_periodic
(
void
)
131
{
132
/* This function is called periodically to restart the watchdog
133
timer. */
134
/* if(counter < 0) {*/
135
WDTCTL = (WDTCTL & 0xff) | WDTPW | WDTCNTCL | WDTTMSEL;
136
/* }*/
137
}
138
/*---------------------------------------------------------------------------*/
139
void
140
watchdog_stop
(
void
)
141
{
142
counter++;
143
if
(counter == 1) {
144
WDTCTL = WDTPW | WDTHOLD;
145
}
146
}
147
/*---------------------------------------------------------------------------*/
148
void
149
watchdog_reboot
(
void
)
150
{
151
WDTCTL = 0;
152
}
153
/*---------------------------------------------------------------------------*/
watchdog_reboot
void watchdog_reboot(void)
Keeps control until the WDT throws a reset signal.
Definition
watchdog.c:94
watchdog_start
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition
watchdog.c:72
watchdog_periodic
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition
watchdog.c:85
watchdog_init
void watchdog_init(void)
Initialisation function for the WDT.
Definition
watchdog.c:63
watchdog_stop
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.
Definition
watchdog.c:140
arch
cpu
msp430
watchdog.c
Generated on
for Contiki-NG by
1.17.0