rau cha / mbed-src-I2CWaitFix

Fork of mbed-src by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sleep.c Source File

sleep.c

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "sleep_api.h"
00017 #include "cmsis.h"
00018 #include "mbed_interface.h"
00019 
00020 void sleep(void) {
00021     LPC_SC->PCON = 0x0;
00022     
00023     // SRC[SLEEPDEEP] set to 0 = sleep
00024     SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
00025     
00026     // wait for interrupt
00027     __WFI();
00028 }
00029 
00030 /*
00031 * The mbed lpc1768 does not support the deepsleep mode
00032 * as a debugger is connected to it (the mbed interface).
00033 *
00034 * As mentionned in an application note from NXP:
00035 *
00036 *       http://www.po-star.com/public/uploads/20120319123122_141.pdf
00037 *
00038 *       {{{
00039 *       The user should be aware of certain limitations during debugging.
00040 *       The most important is that, due to limitations of the Cortex-M3
00041 *       integration, the LPC17xx cannot wake up in the usual manner from
00042 *       Deep Sleep and Power-down modes. It is recommended not to use these
00043 *       modes during debug. Once an application is downloaded via JTAG/SWD
00044 *       interface, the USB to SWD/JTAG debug adapter (Keil ULINK2 for example)
00045 *       should be removed from the target board, and thereafter, power cycle
00046 *       the LPC17xx to allow wake-up from deep sleep and power-down modes
00047 *       }}}
00048 *
00049 *       As the interface firmware does not reset the target when a
00050 *       mbed_interface_disconnect() semihosting call is made, the
00051 *       core cannot wake-up from deepsleep.
00052 *
00053 *       We treat a deepsleep() as a normal sleep().
00054 */
00055 void deepsleep(void) {
00056     sleep();
00057 }