forked

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_sleep.h Source File

mbed_sleep.h

00001 
00002 /** \addtogroup platform */
00003 /** @{*/
00004 /* mbed Microcontroller Library
00005  * Copyright (c) 2006-2017 ARM Limited
00006  *
00007  * Licensed under the Apache License, Version 2.0 (the "License");
00008  * you may not use this file except in compliance with the License.
00009  * You may obtain a copy of the License at
00010  *
00011  *     http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  * Unless required by applicable law or agreed to in writing, software
00014  * distributed under the License is distributed on an "AS IS" BASIS,
00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  * See the License for the specific language governing permissions and
00017  * limitations under the License.
00018  */
00019 #ifndef MBED_SLEEP_H
00020 #define MBED_SLEEP_H
00021 
00022 #include "sleep_api.h"
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /** Send the microcontroller to sleep
00029  *
00030  * @note This function can be a noop if not implemented by the platform.
00031  * @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined).
00032  * @note This function will be a noop while uVisor is in use.
00033  *
00034  * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
00035  * system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
00036  * dynamic power used by the processor, memory systems and buses. The processor, peripheral and
00037  * memory state are maintained, and the peripherals continue to work and can generate interrupts.
00038  *
00039  * The processor can be woken up by any internal peripheral interrupt or external pin interrupt.
00040  *
00041  * @note
00042  *  The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
00043  * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
00044  * able to access the LocalFileSystem
00045  */
00046 __INLINE static void sleep(void)
00047 {
00048 #if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
00049 #ifndef MBED_DEBUG
00050 #if DEVICE_SLEEP
00051     hal_sleep();
00052 #endif /* DEVICE_SLEEP */
00053 #endif /* MBED_DEBUG */
00054 #endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
00055 }
00056 
00057 /** Send the microcontroller to deep sleep
00058  *
00059  * @note This function can be a noop if not implemented by the platform.
00060  * @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined)
00061  * @note This function will be a noop while uVisor is in use.
00062  *
00063  * This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode
00064  * has the same sleep features as sleep plus it powers down peripherals and clocks. All state
00065  * is still maintained.
00066  *
00067  * The processor can only be woken up by an external interrupt on a pin or a watchdog timer.
00068  *
00069  * @note
00070  *  The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
00071  * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
00072  * able to access the LocalFileSystem
00073  */
00074 __INLINE static void deepsleep(void)
00075 {
00076 #if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
00077 #ifndef MBED_DEBUG
00078 #if DEVICE_SLEEP
00079     hal_deepsleep();
00080 #endif /* DEVICE_SLEEP */
00081 #endif /* MBED_DEBUG */
00082 #endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
00083 }
00084 
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088 
00089 #endif
00090 
00091 /** @}*/