LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
watchdog.c
Go to the documentation of this file.
1
/*
2
* @brief WWDT example
3
*
4
* @note
5
* Copyright(C) NXP Semiconductors, 2012
6
* All rights reserved.
7
*
8
* @par
9
* Software that is described herein is for illustrative purposes only
10
* which provides customers with programming information regarding the
11
* LPC products. This software is supplied "AS IS" without any warranties of
12
* any kind, and NXP Semiconductors and its licensor disclaim any and
13
* all warranties, express or implied, including all implied warranties of
14
* merchantability, fitness for a particular purpose and non-infringement of
15
* intellectual property rights. NXP Semiconductors assumes no responsibility
16
* or liability for the use of the software, conveys no license or rights under any
17
* patent, copyright, mask work right, or any other intellectual property rights in
18
* or to any products. NXP Semiconductors reserves the right to make changes
19
* in the software without notification. NXP Semiconductors also makes no
20
* representation or warranty that such application will be suitable for the
21
* specified use without further testing or modification.
22
*
23
* @par
24
* Permission to use, copy, modify, and distribute this software and its
25
* documentation is hereby granted, under NXP Semiconductors' and its
26
* licensor's relevant copyrights in the software, without fee, provided that it
27
* is used in conjunction with NXP Semiconductors microcontrollers. This
28
* copyright, permission, and disclaimer notice must appear in all copies of
29
* this code.
30
*/
31
32
#include "board.h"
33
75
/*****************************************************************************
76
* Private types/enumerations/variables
77
****************************************************************************/
78
79
static
volatile
int
wdtFeedState
;
80
static
volatile
bool
On
=
false
,
On1
=
false
;
81
82
/*****************************************************************************
83
* Public types/enumerations/variables
84
****************************************************************************/
85
86
/*****************************************************************************
87
* Private functions
88
****************************************************************************/
89
90
/* WDT interrupt handler */
91
static
void
wdt_handle
(
void
) {
92
uint32_t
wdtStatus =
Chip_WWDT_GetStatus
(
LPC_WWDT
);
93
94
On
= (bool) !
On
;
95
96
/* The chip will reset before this happens, but if the WDT doesn't
97
have WWDT_WDMOD_WDRESET enabled, this will hit once */
98
if
(wdtStatus &
WWDT_WDMOD_WDTOF
) {
99
/* A watchdog feed didn't occur prior to window timeout */
100
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
, WWDT_WDMOD_WDTOF);
101
102
if
(
wdtFeedState
== 2) {
103
Chip_WWDT_Start
(
LPC_WWDT
);
/* Needs restart */
104
}
105
}
106
107
/* Handle warning interrupt */
108
if
(wdtStatus &
WWDT_WDMOD_WDINT
) {
109
/* A watchdog feed didn't occur prior to warning timeout */
110
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
, WWDT_WDMOD_WDINT);
111
112
if
(
wdtFeedState
== 1) {
113
Chip_WWDT_Feed
(
LPC_WWDT
);
114
}
115
}
116
}
117
118
/*****************************************************************************
119
* Public functions
120
****************************************************************************/
121
127
void
EVRT_IRQHandler
(
void
)
128
{
129
On1
= !
On1
;
130
131
/* Clear watchdog timer interrupt in event router (ok to clear before
132
watchdog clear on edge based event router events) */
133
Chip_EVRT_ClrPendIntSrc
(
EVRT_SRC_WWDT
);
134
135
wdt_handle
();
136
}
137
143
void
WDT_IRQHandler
(
void
)
144
{
145
wdt_handle
();
146
}
147
153
void
SysTick_Handler
(
void
)
154
{
155
if
(
wdtFeedState
== 0) {
156
On
= (bool) !
On
;
157
Chip_WWDT_Feed
(
LPC_WWDT
);
158
}
159
}
160
165
int
main
(
void
)
166
{
167
uint8_t ch;
168
169
Board_Init
();
170
171
/* Watchdog will be fed on each watchdog interrupt */
172
wdtFeedState
= 0;
173
174
/* Initialize WWDT and event router */
175
Chip_WWDT_Init
(
LPC_WWDT
);
176
Chip_EVRT_Init
();
177
178
/* Set watchdog feed time constant to 0.1s
179
Set watchdog warning time to 512 ticks after feed time constant
180
Set watchdog window time to 0.9s */
181
Chip_WWDT_SetTimeOut
(
LPC_WWDT
,
WDT_OSC
/ 10);
182
Chip_WWDT_SetWarning
(
LPC_WWDT
, 512);
183
Chip_WWDT_SetWindow
(
LPC_WWDT
,
WDT_OSC
- (
WDT_OSC
/ 10));
184
185
/* Configure WWDT to reset on timeout */
186
Chip_WWDT_SetOption
(
LPC_WWDT
,
WWDT_WDMOD_WDRESET
);
187
188
/* Clear watchdog warning and timeout interrupts */
189
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
,
WWDT_WDMOD_WDTOF
|
WWDT_WDMOD_WDINT
);
190
191
/* Initiate EVRT, route interrupt signal from WWDT to EVRT,
192
enable EVRT WWDT interrupt */
193
Chip_EVRT_ConfigIntSrcActiveType
(
EVRT_SRC_WWDT
,
EVRT_SRC_ACTIVE_RISING_EDGE
);
194
Chip_EVRT_SetUpIntSrc
(
EVRT_SRC_WWDT
,
ENABLE
);
195
196
/* Start watchdog */
197
Chip_WWDT_Start
(
LPC_WWDT
);
198
199
/* Setup Systick for a 10Hz tick rate. Systick clock is clocked at
200
CPU core clock speed */
201
SysTick_Config(
Chip_Clock_GetRate
(
CLK_MX_MXCORE
) / 20);
202
203
/* Enable watchdog interrupt */
204
NVIC_EnableIRQ(WWDT_IRQn);
205
206
/* Watchdog test options */
207
DEBUGOUT
(
"Press '1' to enable watchdog feed on systick interrupt\n\r"
);
208
DEBUGOUT
(
"Press '2' to enable watchdog feed on warning interrupt\n\r"
);
209
DEBUGOUT
(
"Press '3' to disable watchdog feed (will reset device)\n\r"
);
210
DEBUGOUT
(
"Press '4' to switch from WDT interrupt to event router handler\n\r"
);
211
212
while
(1) {
213
do
{
214
ch =
DEBUGIN
();
215
Board_LED_Set
(0,
On
);
216
Board_LED_Set
(1,
On1
);
217
}
while
((ch <
'1'
) || (ch >
'4'
));
218
219
switch
(ch) {
220
case
'1'
:
221
default
:
222
wdtFeedState
= 0;
223
DEBUGOUT
(
"Watchdog feed on systick interrupt\r\n"
);
224
break
;
225
226
case
'2'
:
227
wdtFeedState
= 1;
228
DEBUGOUT
(
"Watchdog feed on warning interrupt\r\n"
);
229
break
;
230
231
case
'3'
:
232
wdtFeedState
= 2;
233
DEBUGOUT
(
"No feeding - board will reset\r\n"
);
234
break
;
235
236
case
'4'
:
237
DEBUGOUT
(
"using event router instead of WDT interrupt\r\n"
);
238
NVIC_DisableIRQ(WWDT_IRQn);
239
NVIC_EnableIRQ(EVENTROUTER_IRQn);
240
break
;
241
}
242
}
243
}
244
applications
lpc18xx_43xx
examples
periph
periph_watchdog
watchdog.c
Generated on Fri May 10 2013 10:42:08 for LPCOpen Platform by
1.8.2