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
70
/*****************************************************************************
71
* Private types/enumerations/variables
72
****************************************************************************/
73
74
/* Comment this define to let the watchdog timeout. In this case, the board
75
will continuously drop via to the WDT warning. */
76
#define DISABLE_WDT_TIMEOUT
77
78
/*****************************************************************************
79
* Public types/enumerations/variables
80
****************************************************************************/
81
82
/*****************************************************************************
83
* Private functions
84
****************************************************************************/
85
86
/*****************************************************************************
87
* Public functions
88
****************************************************************************/
89
95
void
WDT_IRQHandler
(
void
)
96
{
97
uint32_t
wdtStatus =
Chip_WWDT_GetStatus
(
LPC_WWDT
);
98
99
#if defined(CHIP_LPC11CXX)
100
if
(wdtStatus &
WWDT_WDMOD_WDTOF
) {
101
Board_LED_Toggle
(0);
102
while
(
Chip_WWDT_GetStatus
(
LPC_WWDT
) & WWDT_WDMOD_WDTOF) {
103
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
, WWDT_WDMOD_WDTOF);
104
}
105
Chip_WWDT_Start
(
LPC_WWDT
);
/* Needs restart */
106
}
107
#else
108
Board_LED_Toggle
(0);
109
110
/* The chip will reset before this happens, but if the WDT doesn't
111
have WWDT_WDMOD_WDRESET enabled, this will hit once */
112
if
(wdtStatus & WWDT_WDMOD_WDTOF) {
113
/* A watchdog feed didn't occur prior to window timeout */
114
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
, WWDT_WDMOD_WDTOF);
115
Chip_WWDT_Start
(
LPC_WWDT
);
/* Needs restart */
116
}
117
118
/* Handle warning interrupt */
119
if
(wdtStatus &
WWDT_WDMOD_WDINT
) {
120
/* A watchdog feed didn't occur prior to warning timeout */
121
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
, WWDT_WDMOD_WDINT);
122
Chip_WWDT_Feed
(
LPC_WWDT
);
123
}
124
#endif
125
}
126
132
void
SysTick_Handler
(
void
)
133
{
134
#if !defined(DISABLE_WDT_TIMEOUT)
135
Chip_WWDT_Feed
(
LPC_WWDT
);
136
#endif
137
}
138
143
int
main
(
void
)
144
{
145
uint32_t
wdtFreq;
146
147
/* Board Setup */
148
Board_Init
();
149
150
/* Initialize WWDT (also enables WWDT clock) */
151
Chip_WWDT_Init
(
LPC_WWDT
);
152
153
/* Prior to initializing the watchdog driver, the clocking for the
154
watchdog must be enabled. This example uses the watchdog oscillator
155
set at a 50KHz (1Mhz / 20) clock rate. */
156
Chip_SYSCTL_PowerUp
(
SYSCTL_POWERDOWN_WDTOSC_PD
);
157
Chip_Clock_SetWDTOSC
(
WDTLFO_OSC_1_05
, 20);
158
159
/* The WDT divides the input frequency into it by 4 */
160
wdtFreq =
Chip_Clock_GetWDTOSCRate
() / 4;
161
162
/* LPC1102/4, LPC11XXLV, and LPC11CXX devices select the watchdog
163
clock source from the SYSCLK block, while LPC11AXX, LPC11EXX, and
164
LPC11UXX devices select the clock as part of the watchdog block. */
165
/* Select watchdog oscillator for WDT clock source */
166
#if defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX)
167
Chip_Clock_SetWDTClockSource(SYSCTL_WDTCLKSRC_WDTOSC, 1);
168
#else
169
Chip_WWDT_SelClockSource(
LPC_WWDT
, WWDT_CLKSRC_WATCHDOG_WDOSC);
170
#endif
171
172
Board_LED_Set
(0,
false
);
173
174
/* Set watchdog feed time constant to approximately 2s
175
Set watchdog warning time to 512 ticks after feed time constant
176
Set watchdog window time to 3s */
177
Chip_WWDT_SetTimeOut
(
LPC_WWDT
, wdtFreq * 2);
178
#if !defined(CHIP_LPC11CXX)
179
Chip_WWDT_SetWarning
(
LPC_WWDT
, 512);
180
Chip_WWDT_SetWindow
(
LPC_WWDT
, wdtFreq * 3);
181
#endif
182
183
#if !defined(CHIP_LPC11CXX)
184
/* Configure WWDT to reset on timeout */
185
Chip_WWDT_SetOption
(
LPC_WWDT
,
WWDT_WDMOD_WDRESET
);
186
#endif
187
188
/* Setup Systick to feed the watchdog timer. This needs to be done
189
* at a rate faster than the WDT warning. */
190
SysTick_Config(
Chip_Clock_GetSystemClockRate
() / 50);
191
192
/* Clear watchdog warning and timeout interrupts */
193
#if !defined(CHIP_LPC11CXX)
194
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
,
WWDT_WDMOD_WDTOF
|
WWDT_WDMOD_WDINT
);
195
#else
196
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
,
WWDT_WDMOD_WDTOF
);
197
#endif
198
199
/* Clear and enable watchdog interrupt */
200
NVIC_ClearPendingIRQ(WDT_IRQn);
201
NVIC_EnableIRQ(WDT_IRQn);
202
203
/* Start watchdog */
204
Chip_WWDT_Start
(
LPC_WWDT
);
205
206
/* Idle while waiting */
207
while
(1) {
208
__WFI();
209
}
210
}
211
applications
lpc11xx
examples
periph
periph_watchdog
watchdog.c
Generated on Fri May 10 2013 10:42:08 for LPCOpen Platform by
1.8.2