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     // ensure debug is disconnected
00022     mbed_interface_disconnect();
00023     
00024     // PCON[PD] set to sleep
00025     LPC_PMU->PCON = 0x0;
00026     
00027     // SRC[SLEEPDEEP] set to 0 = sleep
00028     SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
00029     
00030     // wait for interrupt
00031     __WFI();
00032 }
00033 
00034 /*
00035 * The mbed lpc1768 does not support the deepsleep mode
00036 * as a debugger is connected to it (the mbed interface).
00037 *
00038 * As mentionned in an application note from NXP:
00039 *
00040 *       http://www.po-star.com/public/uploads/20120319123122_141.pdf
00041 *
00042 *       {{{
00043 *       The user should be aware of certain limitations during debugging.
00044 *       The most important is that, due to limitations of the Cortex-M3
00045 *       integration, the LPC17xx cannot wake up in the usual manner from
00046 *       Deep Sleep and Power-down modes. It is recommended not to use these
00047 *       modes during debug. Once an application is downloaded via JTAG/SWD
00048 *       interface, the USB to SWD/JTAG debug adapter (Keil ULINK2 for example)
00049 *       should be removed from the target board, and thereafter, power cycle
00050 *       the LPC17xx to allow wake-up from deep sleep and power-down modes
00051 *       }}}
00052 *
00053 *       As the interface firmware does not reset the target when a
00054 *       mbed_interface_disconnect() semihosting call is made, the
00055 *       core cannot wake-up from deepsleep.
00056 *
00057 *       We treat a deepsleep() as a normal sleep().
00058 */
00059 
00060 void deepsleep(void) {
00061     // ensure debug is disconnected
00062     mbed_interface_disconnect();
00063     
00064     // PCON[PD] set to deepsleep
00065     LPC_PMU->PCON = 0x1;
00066     
00067     // SRC[SLEEPDEEP] set to 1 = deep sleep
00068     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
00069     
00070     // Power up everything after powerdown
00071     LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
00072     
00073     // wait for interrupt
00074     __WFI();
00075 }