mbed SDK library sources

Fork of mbed-src by mbed official

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Sep 19 10:00:04 2013 +0100
Revision:
27:3315632cc01d
Parent:
20:4263a77256ae
Synchronized with git revision 38ed9eb6a079e6355789c73ed0ec3ecd482826b6

Who changed what in which revision?

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