mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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