5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef MBED_POWER_MGMT_H
18#define MBED_POWER_MGMT_H
19
20
21#include "platform/mbed_toolchain.h"
22#include "hal/ticker_api.h"
23#include <stdbool.h>
24
25#ifdef __cplusplus
26extern"C" {
27#endif
28
29/** \addtogroup platform-public-api */
30/** @{*/
31
32/**
33 * \defgroup platform_power_mgmt Power management functions
34 * @{
35 */
36
37/**
38 * @defgroup hal_sleep_manager Sleep manager API
39 * The sleep manager provides API to automatically select sleep mode.
40 *
41 * There are two sleep modes:
42 * - sleep
43 * - deepsleep
44 *
45 * Use locking/unlocking deepsleep for drivers that depend on features that
46 * are not allowed (=disabled) during the deepsleep. For instance, high frequency
47 * clocks.
48 *
49 * # Defined behavior
50 * * The lock is a counter
51 * * The lock can be locked up to USHRT_MAX - Verified by ::test_lock_eq_ushrt_max
52 * * The lock has to be equally unlocked as locked - Verified by ::test_lock_eq_ushrt_max
53 * * The function sleep_manager_lock_deep_sleep_internal() locks the automatic deep mode selection - Verified by ::test_lock_unlock
54 * * The function sleep_manager_unlock_deep_sleep_internal() unlocks the automatic deep mode selection - Verified by ::test_lock_unlock
55 * * The function sleep_manager_sleep_auto() chooses the sleep or deep sleep modes based on the lock - Verified by ::test_sleep_auto
56 * * The function sleep_manager_lock_deep_sleep_internal() is IRQ and thread safe - Verified by ::sleep_manager_multithread_test and ::sleep_manager_irq_test
57 * * The function sleep_manager_unlock_deep_sleep_internal() is IRQ and thread safe - Verified by ::sleep_manager_multithread_test and ::sleep_manager_irq_test
58 * * The function sleep_manager_sleep_auto() is IRQ and thread safe
59 *
60 * Example:
61 * @code
62 *
63 * void driver::handler()
64 * {
65 * if (_sensor.get_event()) {
66 * // any event - we are finished, unlock the deepsleep
67 * sleep_manager_unlock_deep_sleep();
68 * _callback();
69 * }
70 * }
71 *
72 * int driver::measure(event_t event, callback_t& callback)
73 * {
74 * _callback = callback;
75 * sleep_manager_lock_deep_sleep();
76 * // start async transaction, we are waiting for an event
77 * return _sensor.start(event, callback);
78 * }
79 * @endcode
80 * @{
81 */
82
83/**
84 * @defgroup hal_sleep_manager_tests Sleep manager API tests
85 * Tests to validate the proper implementation of the sleep manager
86 *
87 * To run the sleep manager hal tests use the command:
88 *
89 * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-sleep_manager*
90 *
91 */
92
93#ifdef MBED_SLEEP_TRACING_ENABLED
94
95void sleep_tracker_lock(constchar *const filename, int line);
96void sleep_tracker_unlock(constchar *const filename, int line);
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.