]>
git.gir.st - tmk_keyboard.git/blob - 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
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "sleep_api.h"
18 #include "mbed_interface.h"
24 #if (DEVICE_SEMIHOST == 1)
25 // ensure debug is disconnected
26 mbed_interface_disconnect();
29 // PCON[PM] (bits 2:0) set to 0
30 LPC_PMU
->PCON
&= ~0x03;
32 // SRC[SLEEPDEEP] set to 0 = sleep
33 SCB
->SCR
&= ~SCB_SCR_SLEEPDEEP_Msk
;
40 void deepsleep(void) {
42 #if (DEVICE_SEMIHOST == 1)
43 // ensure debug is disconnected
44 mbed_interface_disconnect();
47 // PCON[PM] (bits 2:0) set to 1
48 LPC_PMU
->PCON
&= ~0x03;
49 LPC_PMU
->PCON
|= 0x01;
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));
55 // Power up same as before powerdown
56 LPC_SYSCON
->PDAWAKECFG
= LPC_SYSCON
->PDRUNCFG
;
58 // All interrupts can wake
59 LPC_SYSCON
->STARTERP0
= 0xFF;
60 LPC_SYSCON
->STARTERP1
= 0xFFFFFFFF;
62 // SRC[SLEEPDEEP] set to 1 = deep sleep
63 SCB
->SCR
|= SCB_SCR_SLEEPDEEP_Msk
;