t

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Mon Oct 02 15:33:19 2017 +0100
Revision:
175:b96e65c34a4d
Parent:
168:e84263d55307
Child:
177:447f873cad2f
This updates the lib to the mbed lib v 152

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 175:b96e65c34a4d 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 175:b96e65c34a4d 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 175:b96e65c34a4d 79 * Use unlocking in pair with sleep_manager_lock_deep_sleep().
AnnaBridge 175:b96e65c34a4d 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 175:b96e65c34a4d 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.
<> 160:d5399cc887bb 109 *
<> 160:d5399cc887bb 110 * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
<> 160:d5399cc887bb 111 * system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
<> 160:d5399cc887bb 112 * dynamic power used by the processor, memory systems and buses. The processor, peripheral and
<> 160:d5399cc887bb 113 * memory state are maintained, and the peripherals continue to work and can generate interrupts.
<> 160:d5399cc887bb 114 *
<> 160:d5399cc887bb 115 * The processor can be woken up by any internal peripheral interrupt or external pin interrupt.
<> 160:d5399cc887bb 116 *
<> 160:d5399cc887bb 117 * @note
<> 160:d5399cc887bb 118 * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
<> 160:d5399cc887bb 119 * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
<> 160:d5399cc887bb 120 * able to access the LocalFileSystem
<> 160:d5399cc887bb 121 */
<> 160:d5399cc887bb 122 __INLINE static void sleep(void)
<> 160:d5399cc887bb 123 {
AnnaBridge 168:e84263d55307 124 #if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
<> 160:d5399cc887bb 125 #if DEVICE_SLEEP
AnnaBridge 175:b96e65c34a4d 126 sleep_manager_sleep_auto();
<> 160:d5399cc887bb 127 #endif /* DEVICE_SLEEP */
AnnaBridge 168:e84263d55307 128 #endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
<> 160:d5399cc887bb 129 }
<> 160:d5399cc887bb 130
<> 160:d5399cc887bb 131 /** Send the microcontroller to deep sleep
<> 160:d5399cc887bb 132 *
<> 160:d5399cc887bb 133 * @note This function can be a noop if not implemented by the platform.
AnnaBridge 168:e84263d55307 134 * @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined)
AnnaBridge 168:e84263d55307 135 * @note This function will be a noop while uVisor is in use.
<> 160:d5399cc887bb 136 *
AnnaBridge 175:b96e65c34a4d 137 * This processor is setup ready for deep sleep, and sent to sleep. This mode
<> 160:d5399cc887bb 138 * has the same sleep features as sleep plus it powers down peripherals and clocks. All state
<> 160:d5399cc887bb 139 * is still maintained.
<> 160:d5399cc887bb 140 *
<> 160:d5399cc887bb 141 * The processor can only be woken up by an external interrupt on a pin or a watchdog timer.
<> 160:d5399cc887bb 142 *
<> 160:d5399cc887bb 143 * @note
<> 160:d5399cc887bb 144 * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
<> 160:d5399cc887bb 145 * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
<> 160:d5399cc887bb 146 * able to access the LocalFileSystem
<> 160:d5399cc887bb 147 */
AnnaBridge 175:b96e65c34a4d 148
AnnaBridge 175:b96e65c34a4d 149 MBED_DEPRECATED_SINCE("mbed-os-5.6", "One entry point for an application, use sleep()")
<> 160:d5399cc887bb 150 __INLINE static void deepsleep(void)
<> 160:d5399cc887bb 151 {
AnnaBridge 168:e84263d55307 152 #if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
<> 160:d5399cc887bb 153 #if DEVICE_SLEEP
AnnaBridge 175:b96e65c34a4d 154 sleep_manager_sleep_auto();
<> 160:d5399cc887bb 155 #endif /* DEVICE_SLEEP */
AnnaBridge 168:e84263d55307 156 #endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
<> 160:d5399cc887bb 157 }
<> 160:d5399cc887bb 158
<> 160:d5399cc887bb 159 #ifdef __cplusplus
<> 160:d5399cc887bb 160 }
<> 160:d5399cc887bb 161 #endif
<> 160:d5399cc887bb 162
<> 160:d5399cc887bb 163 #endif
<> 160:d5399cc887bb 164
<> 160:d5399cc887bb 165 /** @}*/