The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Mon Oct 02 15:20:36 2017 +0100
Revision:
152:235179ab3f27
Parent:
145:64910690c574
Child:
154:fb8e0ae1cceb
Release 152 of the mbed library.

Who changed what in which revision?

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