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