mbed library sources, mbed-dev only for TYBLE16

Fork of mbed-dev by mbed official

Please refer flowing link.
/users/kenjiArai/notebook/tyble16-module-will-become-a-mbed-family--mbedliza/

Committer:
AnnaBridge
Date:
Thu Nov 23 11:57:25 2017 +0000
Revision:
178:79309dc6340a
Parent:
176:447f873cad2f
mbed-dev library. Release version 156

Who changed what in which revision?

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