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