mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

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 LPC_SC->PCON = 0x0;
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 // SRC[SLEEPDEEP] set to 0 = sleep
elessair 0:f269e3021894 24 SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
elessair 0:f269e3021894 25
elessair 0:f269e3021894 26 // wait for interrupt
elessair 0:f269e3021894 27 __WFI();
elessair 0:f269e3021894 28 }
elessair 0:f269e3021894 29
elessair 0:f269e3021894 30 /*
elessair 0:f269e3021894 31 * The mbed lpc1768 does not support the deepsleep mode
elessair 0:f269e3021894 32 * as a debugger is connected to it (the mbed interface).
elessair 0:f269e3021894 33 *
elessair 0:f269e3021894 34 * As mentionned in an application note from NXP:
elessair 0:f269e3021894 35 *
elessair 0:f269e3021894 36 * http://www.po-star.com/public/uploads/20120319123122_141.pdf
elessair 0:f269e3021894 37 *
elessair 0:f269e3021894 38 * {{{
elessair 0:f269e3021894 39 * The user should be aware of certain limitations during debugging.
elessair 0:f269e3021894 40 * The most important is that, due to limitations of the Cortex-M3
elessair 0:f269e3021894 41 * integration, the LPC17xx cannot wake up in the usual manner from
elessair 0:f269e3021894 42 * Deep Sleep and Power-down modes. It is recommended not to use these
elessair 0:f269e3021894 43 * modes during debug. Once an application is downloaded via JTAG/SWD
elessair 0:f269e3021894 44 * interface, the USB to SWD/JTAG debug adapter (Keil ULINK2 for example)
elessair 0:f269e3021894 45 * should be removed from the target board, and thereafter, power cycle
elessair 0:f269e3021894 46 * the LPC17xx to allow wake-up from deep sleep and power-down modes
elessair 0:f269e3021894 47 * }}}
elessair 0:f269e3021894 48 *
elessair 0:f269e3021894 49 * As the interface firmware does not reset the target when a
elessair 0:f269e3021894 50 * mbed_interface_disconnect() semihosting call is made, the
elessair 0:f269e3021894 51 * core cannot wake-up from deepsleep.
elessair 0:f269e3021894 52 *
elessair 0:f269e3021894 53 * We treat a deepsleep() as a normal sleep().
elessair 0:f269e3021894 54 */
elessair 0:f269e3021894 55 void deepsleep(void) {
elessair 0:f269e3021894 56 sleep();
elessair 0:f269e3021894 57 }