]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/sleep.c
remove experimental return, cleanup slash_question key
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_NXP / TARGET_LPC11U6X / sleep.c
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "sleep_api.h"
17 #include "cmsis.h"
18 #include "mbed_interface.h"
19
20 #if DEVICE_SLEEP
21
22 void sleep(void) {
23
24 #if (DEVICE_SEMIHOST == 1)
25 // ensure debug is disconnected
26 mbed_interface_disconnect();
27 #endif
28
29 // PCON[PM] (bits 2:0) set to 0
30 LPC_PMU->PCON &= ~0x03;
31
32 // SRC[SLEEPDEEP] set to 0 = sleep
33 SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
34
35 // wait for interrupt
36 __WFI();
37 }
38
39
40 void deepsleep(void) {
41
42 #if (DEVICE_SEMIHOST == 1)
43 // ensure debug is disconnected
44 mbed_interface_disconnect();
45 #endif
46
47 // PCON[PM] (bits 2:0) set to 1
48 LPC_PMU->PCON &= ~0x03;
49 LPC_PMU->PCON |= 0x01;
50
51 //According to user manual it is kinda picky about reserved bits, so we follow that nicely
52 //Keep WDOSC and BOD in same state as they are now during deepsleep
53 LPC_SYSCON->PDSLEEPCFG = 0x00000037 | (LPC_SYSCON->PDRUNCFG & (0x00000048));
54
55 // Power up same as before powerdown
56 LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG;
57
58 // All interrupts can wake
59 LPC_SYSCON->STARTERP0 = 0xFF;
60 LPC_SYSCON->STARTERP1 = 0xFFFFFFFF;
61
62 // SRC[SLEEPDEEP] set to 1 = deep sleep
63 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
64
65 // wait for interrupt
66 __WFI();
67 }
68
69 #endif
Imprint / Impressum