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
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
{
80
uint32_t
wdtStatus =
Chip_WWDT_GetStatus
(
LPC_WWDT
);
81
82
Board_LED_Toggle
(0);
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 */
88
Chip_WWDT_UnsetOption
(
LPC_WWDT
,
WWDT_WDMOD_WDEN
);
/* Stop WDT */
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);
97
Chip_WWDT_Feed
(
LPC_WWDT
);
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 */
112
Chip_Clock_SetWDTOSC
(
WDTLFO_OSC_0_60
, 64);
113
114
/* Enable the power to the WDT */
115
Chip_SYSCTL_PowerUp
(
SYSCTL_SLPWAKE_WDTOSC_PD
);
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) */
123
Chip_WWDT_Init
(
LPC_WWDT
);
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);
129
Chip_WWDT_SetWarning
(
LPC_WWDT
, 512);
130
Chip_WWDT_SetWindow
(
LPC_WWDT
, wdtFreq * 3);
131
132
/* Configure WWDT to reset on timeout */
133
Chip_WWDT_SetOption
(
LPC_WWDT
,
WWDT_WDMOD_WDRESET
);
134
135
/* Clear watchdog warning and timeout interrupts */
136
Chip_WWDT_ClearStatusFlag
(
LPC_WWDT
,
WWDT_WDMOD_WDTOF
|
WWDT_WDMOD_WDINT
);
137
138
/* Clear and enable watchdog interrupt */
139
NVIC_ClearPendingIRQ(WDT_IRQn);
140
NVIC_EnableIRQ(WDT_IRQn);
141
142
/* Start watchdog */
143
Chip_WWDT_Start
(
LPC_WWDT
);
144
145
while
(1) {
146
__WFI();
147
}
148
return
0;
149
}
150
applications
lpc8xx
examples
periph
periph_wwdt
wwdt.c
Generated on Fri May 10 2013 10:42:09 for LPCOpen Platform by
1.8.2