|
14 | 14 | * See the License for the specific language governing permissions and
|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
| 17 | +<<<<<<< HEAD |
| 18 | +======= |
| 19 | +#ifndef MBED_SLEEP_H |
| 20 | +#define MBED_SLEEP_H |
| 21 | + |
| 22 | +#include "sleep_api.h" |
| 23 | +#include "mbed_toolchain.h" |
| 24 | +#include <stdbool.h> |
| 25 | + |
| 26 | +#ifdef __cplusplus |
| 27 | +extern "C" { |
| 28 | +#endif |
| 29 | + |
| 30 | +/** Sleep manager API |
| 31 | + * The sleep manager provides API to automatically select sleep mode. |
| 32 | + * |
| 33 | + * There are two sleep modes: |
| 34 | + * - sleep |
| 35 | + * - deepsleep |
| 36 | + * |
| 37 | + * Use locking/unlocking deepsleep for drivers that depend on features that |
| 38 | + * are not allowed (=disabled) during the deepsleep. For instance, high frequency |
| 39 | + * clocks. |
| 40 | + * |
| 41 | + * Example: |
| 42 | + * @code |
| 43 | + * |
| 44 | + * void driver::handler() |
| 45 | + * { |
| 46 | + * if (_sensor.get_event()) { |
| 47 | + * // any event - we are finished, unlock the deepsleep |
| 48 | + * sleep_manager_unlock_deep_sleep(); |
| 49 | + * _callback(); |
| 50 | + * } |
| 51 | + * } |
| 52 | + * |
| 53 | + * int driver::measure(event_t event, callback_t& callback) |
| 54 | + * { |
| 55 | + * _callback = callback; |
| 56 | + * sleep_manager_lock_deep_sleep(); |
| 57 | + * // start async transaction, we are waiting for an event |
| 58 | + * return _sensor.start(event, callback); |
| 59 | + * } |
| 60 | + * @endcode |
| 61 | + */ |
| 62 | +#ifdef MBED_SLEEP_STATS_ENABLED |
| 63 | + |
| 64 | +#define sleep_manager_lock_deep_sleep() \ |
| 65 | + do \ |
| 66 | + { \ |
| 67 | + sleep_manager_lock_deep_sleep_internal(); \ |
| 68 | + sleep_tracker_lock(__FILE__, __LINE__); \ |
| 69 | + } while (0); |
| 70 | + |
| 71 | +#define sleep_manager_unlock_deep_sleep() \ |
| 72 | + do \ |
| 73 | + { \ |
| 74 | + sleep_manager_unlock_deep_sleep_internal(); \ |
| 75 | + sleep_tracker_unlock(__FILE__, __LINE__); \ |
| 76 | + } while (0); |
| 77 | + |
| 78 | +void sleep_tracker_lock(const char *const filename, int line); |
| 79 | +void sleep_tracker_unlock(const char *const filename, int line); |
| 80 | + |
| 81 | +#else |
| 82 | + |
| 83 | +#define sleep_manager_lock_deep_sleep() \ |
| 84 | + sleep_manager_lock_deep_sleep_internal() |
| 85 | + |
| 86 | +#define sleep_manager_unlock_deep_sleep() \ |
| 87 | + sleep_manager_lock_deep_sleep_internal() |
| 88 | + |
| 89 | +#endif // MBED_SLEEP_STATS_ENABLED |
| 90 | + |
| 91 | +/** Lock the deep sleep mode |
| 92 | + * |
| 93 | + * This locks the automatic deep mode selection. |
| 94 | + * sleep_manager_sleep_auto() will ignore deepsleep mode if |
| 95 | + * this function is invoked at least once (the internal counter is non-zero) |
| 96 | + * |
| 97 | + * Use this locking mechanism for interrupt driven API that are |
| 98 | + * running in the background and deepsleep could affect their functionality |
| 99 | + * |
| 100 | + * The lock is a counter, can be locked up to USHRT_MAX |
| 101 | + * This function is IRQ and thread safe |
| 102 | + */ |
| 103 | +void sleep_manager_lock_deep_sleep_internal(void); |
| 104 | + |
| 105 | +/** Unlock the deep sleep mode |
| 106 | + * |
| 107 | + * Use unlocking in pair with sleep_manager_lock_deep_sleep(). |
| 108 | + * |
| 109 | + * The lock is a counter, should be equally unlocked as locked |
| 110 | + * This function is IRQ and thread safe |
| 111 | + */ |
| 112 | +void sleep_manager_unlock_deep_sleep_internal(void); |
| 113 | +>>>>>>> Rename SLEEP_PROFILING_ENABLED to MBED_SLEEP_STATS_ENABLED |
17 | 114 |
|
18 | 115 | #ifndef MBED_MBED_SLEEP_H
|
19 | 116 | #define MBED_MBED_SLEEP_H
|
|
0 commit comments