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:
bogdanm
Date:
Mon Aug 19 18:17:02 2013 +0300
Revision:
19:398f4c622e1b
Sync with official mbed library release 66

Who changed what in which revision?

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