| 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
wkt.c
Go to the documentation of this file.
1 /*
2 * @brief Self Wake-up Timer (WKT) 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
64 /*****************************************************************************
65 * Private types/enumerations/variables
66 ****************************************************************************/
67
68 #define TICKRATE_HZ (10)/* 10 tick per second */
69
70 #define WAKEUP_COUNT_5s (5 * 10000) /* 5 seconds (using 10Khz clock) */
71
72 /*****************************************************************************
73 * Public types/enumerations/variables
74 ****************************************************************************/
75
76 /*****************************************************************************
77 * Private functions
78 ****************************************************************************/
79
80 /*****************************************************************************
81 * Public functions
82 ****************************************************************************/
83
88 void WKT_IRQHandler(void)
89 {
90 Chip_WKT_ClearIntStatus(LPC_WKT);
91 }
92
97 int main(void)
98 {
99 bool port0_6;
100 uint32_t i = 0, sleepCnt = 0x30000;
101 CHIP_PMU_MCUPOWER_T powerTest = PMU_MCU_SLEEP;
102
103 /* Generic Initialization */
104 Board_Init();
105
106 /* Enable AHB clock to the GPIO domain to trigger test mode. */
107 Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO);
108
109 /* Alarm/wake timer as wakeup source */
110 Chip_SYSCTL_EnablePeriphWakeup(SYSCTL_WAKEUP_WKTINT);
111
112 /* Enable WKT clock */
113 Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_WKT);
114
115 /* Reset WKT */
116 Chip_SYSCTL_PeriphReset(RESET_WKT);
117
118 /* configure PIN0.6 as an input */
119 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, LPC8XX_PORT_NUM, PIO6, false);
120
121 /* configure PIN0.6 with pull-up */
122 Chip_IOCON_PinSetMode(LPC_IOCON, PIO6, PIN_MODE_PULLUP);
123
124 /* Enable WKT interrupt */
125 NVIC_DisableIRQ(WKT_IRQn);
126 NVIC_EnableIRQ(WKT_IRQn);
127
128 while (1) {
129 /* waiting for PIO0_6 going LOW to start Sleep test */
130 do {
131 port0_6 = Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, LPC8XX_PORT_NUM, PIO6);
132 i++;
133 if (i > sleepCnt) {
134 i = 0;
135 Board_LED_Toggle(0);
136 }
137 } while (port0_6 == ENABLE);
138
139 if (powerTest == PMU_MCU_SLEEP) {
140
141 Chip_WKT_Start(LPC_WKT, WKT_CLKSRC_10KHZ, WAKEUP_COUNT_5s);
142 Chip_PMU_Sleep(LPC_PMU, powerTest);
143
144 Chip_WKT_Stop(LPC_WKT);
145 powerTest = PMU_MCU_DEEP_SLEEP;
146 sleepCnt = 0x50000;
147 }
148 else if (powerTest == PMU_MCU_DEEP_SLEEP) {
149
150 Chip_WKT_Start(LPC_WKT, WKT_CLKSRC_10KHZ, WAKEUP_COUNT_5s);
151 Chip_PMU_Sleep(LPC_PMU, powerTest);
152
153 Chip_WKT_Stop(LPC_WKT);
154 powerTest = PMU_MCU_POWER_DOWN;
155 sleepCnt = 0x70000;
156 }
157 else if (powerTest == PMU_MCU_POWER_DOWN) {
158
159 Chip_WKT_Start(LPC_WKT, WKT_CLKSRC_10KHZ, WAKEUP_COUNT_5s);
160 Chip_PMU_Sleep(LPC_PMU, powerTest);
161
162 Chip_WKT_Stop(LPC_WKT);
163 powerTest = PMU_MCU_DEEP_PWRDOWN;
164 sleepCnt = 0x90000;
165 }
166 else if (powerTest == PMU_MCU_DEEP_PWRDOWN) {
167
168 Chip_WKT_Start(LPC_WKT, WKT_CLKSRC_10KHZ, WAKEUP_COUNT_5s);
169 Chip_PMU_Sleep(LPC_PMU, powerTest);
170
171 Chip_WKT_Stop(LPC_WKT);
172 powerTest = PMU_MCU_SLEEP;
173 sleepCnt = 0x30000;
174 }
175 }
176 return 0;
177 }
178