mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/sleep.c@30:91c1d09ada54, 2013-09-25 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Sep 25 10:30:04 2013 +0100
- Revision:
- 30:91c1d09ada54
- Child:
- 268:402bcc0c870b
Synchronized with git revision 8f57c1e84759991fa81ede0da2b4aabe8530fa09
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 30:91c1d09ada54 | 1 | /* mbed Microcontroller Library |
mbed_official | 30:91c1d09ada54 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 30:91c1d09ada54 | 3 | * |
mbed_official | 30:91c1d09ada54 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 30:91c1d09ada54 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 30:91c1d09ada54 | 6 | * You may obtain a copy of the License at |
mbed_official | 30:91c1d09ada54 | 7 | * |
mbed_official | 30:91c1d09ada54 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 30:91c1d09ada54 | 9 | * |
mbed_official | 30:91c1d09ada54 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 30:91c1d09ada54 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 30:91c1d09ada54 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 30:91c1d09ada54 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 30:91c1d09ada54 | 14 | * limitations under the License. |
mbed_official | 30:91c1d09ada54 | 15 | */ |
mbed_official | 30:91c1d09ada54 | 16 | #include "sleep_api.h" |
mbed_official | 30:91c1d09ada54 | 17 | #include "cmsis.h" |
mbed_official | 30:91c1d09ada54 | 18 | #include "mbed_interface.h" |
mbed_official | 30:91c1d09ada54 | 19 | |
mbed_official | 30:91c1d09ada54 | 20 | void sleep(void) { |
mbed_official | 30:91c1d09ada54 | 21 | #if DEVICE_SEMIHOST |
mbed_official | 30:91c1d09ada54 | 22 | // ensure debug is disconnected |
mbed_official | 30:91c1d09ada54 | 23 | mbed_interface_disconnect(); |
mbed_official | 30:91c1d09ada54 | 24 | #endif |
mbed_official | 30:91c1d09ada54 | 25 | |
mbed_official | 30:91c1d09ada54 | 26 | // PCON[DPDEN] set to sleep |
mbed_official | 30:91c1d09ada54 | 27 | LPC_PMU->PCON = 0x0; |
mbed_official | 30:91c1d09ada54 | 28 | |
mbed_official | 30:91c1d09ada54 | 29 | // SRC[SLEEPDEEP] set to 0 = sleep |
mbed_official | 30:91c1d09ada54 | 30 | SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; |
mbed_official | 30:91c1d09ada54 | 31 | |
mbed_official | 30:91c1d09ada54 | 32 | // wait for interrupt |
mbed_official | 30:91c1d09ada54 | 33 | __WFI(); |
mbed_official | 30:91c1d09ada54 | 34 | } |
mbed_official | 30:91c1d09ada54 | 35 | |
mbed_official | 30:91c1d09ada54 | 36 | /* |
mbed_official | 30:91c1d09ada54 | 37 | * The mbed lpc1768 does not support the deepsleep mode |
mbed_official | 30:91c1d09ada54 | 38 | * as a debugger is connected to it (the mbed interface). |
mbed_official | 30:91c1d09ada54 | 39 | * |
mbed_official | 30:91c1d09ada54 | 40 | * As mentionned in an application note from NXP: |
mbed_official | 30:91c1d09ada54 | 41 | * |
mbed_official | 30:91c1d09ada54 | 42 | * http://www.po-star.com/public/uploads/20120319123122_141.pdf |
mbed_official | 30:91c1d09ada54 | 43 | * |
mbed_official | 30:91c1d09ada54 | 44 | * {{{ |
mbed_official | 30:91c1d09ada54 | 45 | * The user should be aware of certain limitations during debugging. |
mbed_official | 30:91c1d09ada54 | 46 | * The most important is that, due to limitations of the Cortex-M3 |
mbed_official | 30:91c1d09ada54 | 47 | * integration, the LPC17xx cannot wake up in the usual manner from |
mbed_official | 30:91c1d09ada54 | 48 | * Deep Sleep and Power-down modes. It is recommended not to use these |
mbed_official | 30:91c1d09ada54 | 49 | * modes during debug. Once an application is downloaded via JTAG/SWD |
mbed_official | 30:91c1d09ada54 | 50 | * interface, the USB to SWD/JTAG debug adapter (Keil ULINK2 for example) |
mbed_official | 30:91c1d09ada54 | 51 | * should be removed from the target board, and thereafter, power cycle |
mbed_official | 30:91c1d09ada54 | 52 | * the LPC17xx to allow wake-up from deep sleep and power-down modes |
mbed_official | 30:91c1d09ada54 | 53 | * }}} |
mbed_official | 30:91c1d09ada54 | 54 | * |
mbed_official | 30:91c1d09ada54 | 55 | * As the interface firmware does not reset the target when a |
mbed_official | 30:91c1d09ada54 | 56 | * mbed_interface_disconnect() semihosting call is made, the |
mbed_official | 30:91c1d09ada54 | 57 | * core cannot wake-up from deepsleep. |
mbed_official | 30:91c1d09ada54 | 58 | * |
mbed_official | 30:91c1d09ada54 | 59 | * We treat a deepsleep() as a normal sleep(). |
mbed_official | 30:91c1d09ada54 | 60 | */ |
mbed_official | 30:91c1d09ada54 | 61 | |
mbed_official | 30:91c1d09ada54 | 62 | void deepsleep(void) { |
mbed_official | 30:91c1d09ada54 | 63 | #if DEVICE_SEMIHOST |
mbed_official | 30:91c1d09ada54 | 64 | // ensure debug is disconnected |
mbed_official | 30:91c1d09ada54 | 65 | mbed_interface_disconnect(); |
mbed_official | 30:91c1d09ada54 | 66 | #endif |
mbed_official | 30:91c1d09ada54 | 67 | |
mbed_official | 30:91c1d09ada54 | 68 | // PCON[DPDEN] set to deepsleep |
mbed_official | 30:91c1d09ada54 | 69 | LPC_PMU->PCON = 0x2; |
mbed_official | 30:91c1d09ada54 | 70 | |
mbed_official | 30:91c1d09ada54 | 71 | // SRC[SLEEPDEEP] set to 1 = deep sleep |
mbed_official | 30:91c1d09ada54 | 72 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mbed_official | 30:91c1d09ada54 | 73 | |
mbed_official | 30:91c1d09ada54 | 74 | // Power up everything after powerdown |
mbed_official | 30:91c1d09ada54 | 75 | LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800; |
mbed_official | 30:91c1d09ada54 | 76 | |
mbed_official | 30:91c1d09ada54 | 77 | // wait for interrupt |
mbed_official | 30:91c1d09ada54 | 78 | __WFI(); |
mbed_official | 30:91c1d09ada54 | 79 | } |