t

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Nov 08 13:50:44 2017 +0000
Revision:
178:d650f5d4c87a
Parent:
177:447f873cad2f
This updates the lib to the mbed lib v 155

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 160:d5399cc887bb 1
<> 160:d5399cc887bb 2 /** \addtogroup platform */
<> 160:d5399cc887bb 3 /** @{*/
<> 160:d5399cc887bb 4 /* mbed Microcontroller Library
<> 160:d5399cc887bb 5 * Copyright (c) 2006-2017 ARM Limited
<> 160:d5399cc887bb 6 *
<> 160:d5399cc887bb 7 * Licensed under the Apache License, Version 2.0 (the "License");
<> 160:d5399cc887bb 8 * you may not use this file except in compliance with the License.
<> 160:d5399cc887bb 9 * You may obtain a copy of the License at
<> 160:d5399cc887bb 10 *
<> 160:d5399cc887bb 11 * http://www.apache.org/licenses/LICENSE-2.0
<> 160:d5399cc887bb 12 *
<> 160:d5399cc887bb 13 * Unless required by applicable law or agreed to in writing, software
<> 160:d5399cc887bb 14 * distributed under the License is distributed on an "AS IS" BASIS,
<> 160:d5399cc887bb 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 160:d5399cc887bb 16 * See the License for the specific language governing permissions and
<> 160:d5399cc887bb 17 * limitations under the License.
<> 160:d5399cc887bb 18 */
<> 160:d5399cc887bb 19 #ifndef MBED_SLEEP_H
<> 160:d5399cc887bb 20 #define MBED_SLEEP_H
<> 160:d5399cc887bb 21
<> 160:d5399cc887bb 22 #include "sleep_api.h"
AnnaBridge 175:b96e65c34a4d 23 #include "mbed_toolchain.h"
AnnaBridge 175:b96e65c34a4d 24 #include <stdbool.h>
<> 160:d5399cc887bb 25
<> 160:d5399cc887bb 26 #ifdef __cplusplus
<> 160:d5399cc887bb 27 extern "C" {
<> 160:d5399cc887bb 28 #endif
<> 160:d5399cc887bb 29
AnnaBridge 175:b96e65c34a4d 30 /** Sleep manager API
AnnaBridge 175:b96e65c34a4d 31 * The sleep manager provides API to automatically select sleep mode.
AnnaBridge 175:b96e65c34a4d 32 *
AnnaBridge 175:b96e65c34a4d 33 * There are two sleep modes:
AnnaBridge 175:b96e65c34a4d 34 * - sleep
AnnaBridge 175:b96e65c34a4d 35 * - deepsleep
AnnaBridge 175:b96e65c34a4d 36 *
AnnaBridge 175:b96e65c34a4d 37 * Use locking/unlocking deepsleep for drivers that depend on features that
AnnaBridge 175:b96e65c34a4d 38 * are not allowed (=disabled) during the deepsleep. For instance, high frequency
AnnaBridge 175:b96e65c34a4d 39 * clocks.
AnnaBridge 175:b96e65c34a4d 40 *
AnnaBridge 175:b96e65c34a4d 41 * Example:
AnnaBridge 175:b96e65c34a4d 42 * @code
AnnaBridge 175:b96e65c34a4d 43 *
AnnaBridge 175:b96e65c34a4d 44 * void driver::handler()
AnnaBridge 175:b96e65c34a4d 45 * {
AnnaBridge 175:b96e65c34a4d 46 * if (_sensor.get_event()) {
AnnaBridge 175:b96e65c34a4d 47 * // any event - we are finished, unlock the deepsleep
AnnaBridge 175:b96e65c34a4d 48 * sleep_manager_unlock_deep_sleep();
AnnaBridge 175:b96e65c34a4d 49 * _callback();
AnnaBridge 175:b96e65c34a4d 50 * }
AnnaBridge 175:b96e65c34a4d 51 * }
AnnaBridge 175:b96e65c34a4d 52 *
AnnaBridge 175:b96e65c34a4d 53 * int driver::measure(event_t event, callback_t& callback)
AnnaBridge 175:b96e65c34a4d 54 * {
AnnaBridge 175:b96e65c34a4d 55 * _callback = callback;
AnnaBridge 175:b96e65c34a4d 56 * sleep_manager_lock_deep_sleep();
AnnaBridge 175:b96e65c34a4d 57 * // start async transaction, we are waiting for an event
AnnaBridge 175:b96e65c34a4d 58 * return _sensor.start(event, callback);
AnnaBridge 175:b96e65c34a4d 59 * }
AnnaBridge 175:b96e65c34a4d 60 * @endcode
AnnaBridge 175:b96e65c34a4d 61 */
AnnaBridge 175:b96e65c34a4d 62
AnnaBridge 175:b96e65c34a4d 63 /** Lock the deep sleep mode
AnnaBridge 175:b96e65c34a4d 64 *
AnnaBridge 177:447f873cad2f 65 * This locks the automatic deep mode selection.
AnnaBridge 175:b96e65c34a4d 66 * sleep_manager_sleep_auto() will ignore deepsleep mode if
AnnaBridge 175:b96e65c34a4d 67 * this function is invoked at least once (the internal counter is non-zero)
AnnaBridge 175:b96e65c34a4d 68 *
AnnaBridge 175:b96e65c34a4d 69 * Use this locking mechanism for interrupt driven API that are
AnnaBridge 175:b96e65c34a4d 70 * running in the background and deepsleep could affect their functionality
AnnaBridge 177:447f873cad2f 71 *
AnnaBridge 175:b96e65c34a4d 72 * The lock is a counter, can be locked up to USHRT_MAX
AnnaBridge 175:b96e65c34a4d 73 * This function is IRQ and thread safe
AnnaBridge 175:b96e65c34a4d 74 */
AnnaBridge 175:b96e65c34a4d 75 void sleep_manager_lock_deep_sleep(void);
AnnaBridge 175:b96e65c34a4d 76
AnnaBridge 175:b96e65c34a4d 77 /** Unlock the deep sleep mode
AnnaBridge 175:b96e65c34a4d 78 *
AnnaBridge 177:447f873cad2f 79 * Use unlocking in pair with sleep_manager_lock_deep_sleep().
AnnaBridge 177:447f873cad2f 80 *
AnnaBridge 175:b96e65c34a4d 81 * The lock is a counter, should be equally unlocked as locked
AnnaBridge 175:b96e65c34a4d 82 * This function is IRQ and thread safe
AnnaBridge 175:b96e65c34a4d 83 */
AnnaBridge 175:b96e65c34a4d 84 void sleep_manager_unlock_deep_sleep(void);
AnnaBridge 175:b96e65c34a4d 85
AnnaBridge 175:b96e65c34a4d 86 /** Get the status of deep sleep allowance for a target
AnnaBridge 175:b96e65c34a4d 87 *
AnnaBridge 175:b96e65c34a4d 88 * @return true if a target can go to deepsleep, false otherwise
AnnaBridge 175:b96e65c34a4d 89 */
AnnaBridge 175:b96e65c34a4d 90 bool sleep_manager_can_deep_sleep(void);
AnnaBridge 175:b96e65c34a4d 91
AnnaBridge 175:b96e65c34a4d 92 /** Enter auto selected sleep mode. It chooses the sleep or deeepsleep modes based
AnnaBridge 175:b96e65c34a4d 93 * on the deepsleep locking counter
AnnaBridge 175:b96e65c34a4d 94 *
AnnaBridge 175:b96e65c34a4d 95 * This function is IRQ and thread safe
AnnaBridge 175:b96e65c34a4d 96 *
AnnaBridge 175:b96e65c34a4d 97 * @note
AnnaBridge 175:b96e65c34a4d 98 * If MBED_DEBUG is defined, only hal_sleep is allowed. This ensures the debugger
AnnaBridge 175:b96e65c34a4d 99 * to be active for debug modes.
AnnaBridge 177:447f873cad2f 100 *
AnnaBridge 175:b96e65c34a4d 101 */
AnnaBridge 175:b96e65c34a4d 102 void sleep_manager_sleep_auto(void);
AnnaBridge 175:b96e65c34a4d 103
<> 160:d5399cc887bb 104 /** Send the microcontroller to sleep
<> 160:d5399cc887bb 105 *
<> 160:d5399cc887bb 106 * @note This function can be a noop if not implemented by the platform.
AnnaBridge 168:e84263d55307 107 * @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined).
AnnaBridge 168:e84263d55307 108 * @note This function will be a noop while uVisor is in use.
AnnaBridge 177:447f873cad2f 109 * @note This function will be a noop if the following conditions are met:
AnnaBridge 177:447f873cad2f 110 * - The RTOS is present
AnnaBridge 177:447f873cad2f 111 * - The processor turn off the Systick clock during sleep
AnnaBridge 177:447f873cad2f 112 * - The target does not implement tickless mode
<> 160:d5399cc887bb 113 *
<> 160:d5399cc887bb 114 * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
<> 160:d5399cc887bb 115 * system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
<> 160:d5399cc887bb 116 * dynamic power used by the processor, memory systems and buses. The processor, peripheral and
<> 160:d5399cc887bb 117 * memory state are maintained, and the peripherals continue to work and can generate interrupts.
<> 160:d5399cc887bb 118 *
<> 160:d5399cc887bb 119 * The processor can be woken up by any internal peripheral interrupt or external pin interrupt.
<> 160:d5399cc887bb 120 *
<> 160:d5399cc887bb 121 * @note
<> 160:d5399cc887bb 122 * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
<> 160:d5399cc887bb 123 * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
<> 160:d5399cc887bb 124 * able to access the LocalFileSystem
<> 160:d5399cc887bb 125 */
<> 160:d5399cc887bb 126 __INLINE static void sleep(void)
<> 160:d5399cc887bb 127 {
AnnaBridge 168:e84263d55307 128 #if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
<> 160:d5399cc887bb 129 #if DEVICE_SLEEP
AnnaBridge 177:447f873cad2f 130 #if (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_STCLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS)
AnnaBridge 175:b96e65c34a4d 131 sleep_manager_sleep_auto();
AnnaBridge 177:447f873cad2f 132 #endif /* (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_STCLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS) */
<> 160:d5399cc887bb 133 #endif /* DEVICE_SLEEP */
AnnaBridge 168:e84263d55307 134 #endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
<> 160:d5399cc887bb 135 }
<> 160:d5399cc887bb 136
<> 160:d5399cc887bb 137 /** Send the microcontroller to deep sleep
<> 160:d5399cc887bb 138 *
<> 160:d5399cc887bb 139 * @note This function can be a noop if not implemented by the platform.
AnnaBridge 168:e84263d55307 140 * @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined)
AnnaBridge 168:e84263d55307 141 * @note This function will be a noop while uVisor is in use.
<> 160:d5399cc887bb 142 *
AnnaBridge 175:b96e65c34a4d 143 * This processor is setup ready for deep sleep, and sent to sleep. This mode
<> 160:d5399cc887bb 144 * has the same sleep features as sleep plus it powers down peripherals and clocks. All state
<> 160:d5399cc887bb 145 * is still maintained.
<> 160:d5399cc887bb 146 *
<> 160:d5399cc887bb 147 * The processor can only be woken up by an external interrupt on a pin or a watchdog timer.
<> 160:d5399cc887bb 148 *
<> 160:d5399cc887bb 149 * @note
<> 160:d5399cc887bb 150 * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
<> 160:d5399cc887bb 151 * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
<> 160:d5399cc887bb 152 * able to access the LocalFileSystem
<> 160:d5399cc887bb 153 */
AnnaBridge 175:b96e65c34a4d 154
AnnaBridge 175:b96e65c34a4d 155 MBED_DEPRECATED_SINCE("mbed-os-5.6", "One entry point for an application, use sleep()")
<> 160:d5399cc887bb 156 __INLINE static void deepsleep(void)
<> 160:d5399cc887bb 157 {
AnnaBridge 168:e84263d55307 158 #if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
<> 160:d5399cc887bb 159 #if DEVICE_SLEEP
AnnaBridge 175:b96e65c34a4d 160 sleep_manager_sleep_auto();
<> 160:d5399cc887bb 161 #endif /* DEVICE_SLEEP */
AnnaBridge 168:e84263d55307 162 #endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
<> 160:d5399cc887bb 163 }
<> 160:d5399cc887bb 164
<> 160:d5399cc887bb 165 #ifdef __cplusplus
<> 160:d5399cc887bb 166 }
<> 160:d5399cc887bb 167 #endif
<> 160:d5399cc887bb 168
<> 160:d5399cc887bb 169 #endif
<> 160:d5399cc887bb 170
<> 160:d5399cc887bb 171 /** @}*/