Timeout driver for event at absolute time
Dependents: demo_TimeoutAbs i2c_lora_slave
Timeout driver for generating event at absolute time, i.e. alarm at 12:00PM instead of alarm in 5 minutes.
This is the same concept as TIMER_ABSTIME in clock_nanosleep().
The purpose is to remove dependency on when attach()
is called, so the event occurs at correct time regardless of any latency in calling attach()
.
This driver doesnt add any functionality over mbed-os library; it only skips the call to ticker_read_us()
in Ticker::setup()
, which just changes a relative time to absolute time.
example use here.
TimeoutAbs.cpp@1:ae6b29794806, 2018-12-07 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Fri Dec 07 17:49:32 2018 -0800
- Revision:
- 1:ae6b29794806
- Parent:
- 0:900163d530ae
ifdef for header multiple inclusion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:900163d530ae | 1 | |
Wayne Roberts |
0:900163d530ae | 2 | #include "TimeoutAbs.h" |
Wayne Roberts |
0:900163d530ae | 3 | #include "drivers/TimerEvent.h" |
Wayne Roberts |
0:900163d530ae | 4 | #include "platform/FunctionPointer.h" |
Wayne Roberts |
0:900163d530ae | 5 | #include "hal/ticker_api.h" |
Wayne Roberts |
0:900163d530ae | 6 | #include "platform/mbed_critical.h" |
Wayne Roberts |
0:900163d530ae | 7 | |
Wayne Roberts |
0:900163d530ae | 8 | namespace mbed { |
Wayne Roberts |
0:900163d530ae | 9 | |
Wayne Roberts |
0:900163d530ae | 10 | void TimeoutAbs::detach() |
Wayne Roberts |
0:900163d530ae | 11 | { |
Wayne Roberts |
0:900163d530ae | 12 | core_util_critical_section_enter(); |
Wayne Roberts |
0:900163d530ae | 13 | remove(); |
Wayne Roberts |
0:900163d530ae | 14 | // unlocked only if we were attached (we locked it) and this is not low power ticker |
Wayne Roberts |
0:900163d530ae | 15 | if (_function && _lock_deepsleep) { |
Wayne Roberts |
0:900163d530ae | 16 | sleep_manager_unlock_deep_sleep(); |
Wayne Roberts |
0:900163d530ae | 17 | } |
Wayne Roberts |
0:900163d530ae | 18 | _function = 0; |
Wayne Roberts |
0:900163d530ae | 19 | core_util_critical_section_exit(); |
Wayne Roberts |
0:900163d530ae | 20 | } |
Wayne Roberts |
0:900163d530ae | 21 | |
Wayne Roberts |
0:900163d530ae | 22 | void TimeoutAbs::abs_setup(us_timestamp_t t) |
Wayne Roberts |
0:900163d530ae | 23 | { |
Wayne Roberts |
0:900163d530ae | 24 | core_util_critical_section_enter(); |
Wayne Roberts |
0:900163d530ae | 25 | remove(); |
Wayne Roberts |
0:900163d530ae | 26 | insert_absolute(t); |
Wayne Roberts |
0:900163d530ae | 27 | core_util_critical_section_exit(); |
Wayne Roberts |
0:900163d530ae | 28 | } |
Wayne Roberts |
0:900163d530ae | 29 | |
Wayne Roberts |
0:900163d530ae | 30 | void TimeoutAbs::handler() |
Wayne Roberts |
0:900163d530ae | 31 | { |
Wayne Roberts |
0:900163d530ae | 32 | Callback<void()> local = _function; |
Wayne Roberts |
0:900163d530ae | 33 | detach(); |
Wayne Roberts |
0:900163d530ae | 34 | local.call(); |
Wayne Roberts |
0:900163d530ae | 35 | } |
Wayne Roberts |
0:900163d530ae | 36 | |
Wayne Roberts |
0:900163d530ae | 37 | } // namespace mbed |