LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wwdt.c
Go to the documentation of this file.
1 /*
2  * @brief Windowed Watchdog Timer (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 
58 /*****************************************************************************
59  * Private types/enumerations/variables
60  ****************************************************************************/
61 
62 /*****************************************************************************
63  * Public types/enumerations/variables
64  ****************************************************************************/
65 
66 /*****************************************************************************
67  * Private functions
68  ****************************************************************************/
69 
70 /*****************************************************************************
71  * Public functions
72  ****************************************************************************/
78 void WDT_IRQHandler(void)
79 {
81 
83 
84  /* The chip will reset before this happens, but if the WDT doesn't
85  have WWDT_WDMOD_WDRESET enabled, this will hit once */
86  if (wdtStatus & WWDT_WDMOD_WDTOF) {
87  /* A watchdog feed didn't occur prior to window timeout */
89  Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF);
90  Chip_WWDT_Start(LPC_WWDT); /* Needs restart */
91  }
92 
93  /* Handle warning interrupt */
94  if (wdtStatus & WWDT_WDMOD_WDINT) {
95  /* A watchdog feed didn't occur prior to warning timeout */
96  Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDINT);
98  }
99 }
100 
105 int main(void)
106 {
107  uint32_t wdtFreq;
108 
109  Board_Init();
110 
111  /* Freq = 0.6Mhz, divided by 64. WDT_OSC should be 9.375khz */
113 
114  /* Enable the power to the WDT */
116 
117  /* The WDT divides the input frequency into it by 4 */
118  wdtFreq = Chip_Clock_GetWDTOSCRate() / 4;
119 
120  Board_LED_Set(0, false);
121 
122  /* Initialize WWDT (also enables WWDT clock) */
124 
125  /* Set watchdog feed time constant to approximately 2s
126  Set watchdog warning time to 512 ticks after feed time constant
127  Set watchdog window time to 3s */
128  Chip_WWDT_SetTimeOut(LPC_WWDT, wdtFreq * 2);
130  Chip_WWDT_SetWindow(LPC_WWDT, wdtFreq * 3);
131 
132  /* Configure WWDT to reset on timeout */
134 
135  /* Clear watchdog warning and timeout interrupts */
137 
138  /* Clear and enable watchdog interrupt */
139  NVIC_ClearPendingIRQ(WDT_IRQn);
140  NVIC_EnableIRQ(WDT_IRQn);
141 
142  /* Start watchdog */
144 
145  while (1) {
146  __WFI();
147  }
148  return 0;
149 }
150