Mbed OS Reference
Loading...
Searching...
No Matches
LowPowerTimeout.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2015 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
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_LOWPOWERTIMEOUT_H
18#define MBED_LOWPOWERTIMEOUT_H
19
20#include "platform/platform.h"
21
22#if DEVICE_LPTICKER || defined(DOXYGEN_ONLY)
23
24#include "drivers/LowPowerClock.h"
25#include "drivers/Timeout.h"
26
27namespace mbed {
28/**
29 * \defgroup drivers_LowPowerTimeout LowPowerTimeout class
30 * \ingroup drivers-public-api-ticker
31 * @{
32 */
33
34/** Low Power Timout
35 *
36 * @note Synchronization level: Interrupt safe
37 */
39public:
41
42 /** Clock to use with attach_absolute, guaranteeing running only while attached or manually locked */
44
45 /** Clock to use with attach_absolute, running always */
47
48 /** Return scheduled callback time
49 *
50 * @return scheduled callback time
51 *
52 * @note if the callback is overdue, or has already run, the returned value will be in the past
53 */
54 LowPowerClock::time_point scheduled_time() const
55 {
56 /* Massage from virtual TickerDataClock::time_point used internally to true LowPowerClock::time_point */
57 return LowPowerClock::time_point{TimeoutBase::scheduled_time().time_since_epoch()};
58 }
59
60 /** Attach a function to be called by the Timeout, specifying the absolute time
61 *
62 * @param func pointer to the function to be called
63 * @param abs_time the absolute time for the call, referenced to LowPowerClock
64 *
65 * @note setting @a abs_time to a time in the past means the event will be scheduled immediately
66 * resulting in an instant call to the function.
67 */
68 template <class F>
69 void attach_absolute(F &&func, LowPowerClock::time_point abs_time)
70 {
71 /* Massage from true LowPowerClock::time_point to virtual TickerDataClock::time_point used internally */
72 TimeoutBase::attach_absolute(std::forward<F>(func), TickerDataClock::time_point{abs_time.time_since_epoch()});
73 }
74};
75
76/** @}*/
77
78} // namespace mbed
79
80#endif
81
82#endif
A C++11 Clock representing the HAL lp_ticker.
Definition: LowPowerClock.h:38
Low Power Timout.
LowPowerClock::time_point scheduled_time() const
Return scheduled callback time.
void attach_absolute(F &&func, LowPowerClock::time_point abs_time)
Attach a function to be called by the Timeout, specifying the absolute time.
A Timeout is used to call a function at a point in the future.
Definition: Timeout.h:60