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.
Diff: TimeoutAbs.cpp
- Revision:
- 0:900163d530ae
diff -r 000000000000 -r 900163d530ae TimeoutAbs.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TimeoutAbs.cpp Mon Nov 26 14:22:55 2018 -0800 @@ -0,0 +1,37 @@ + +#include "TimeoutAbs.h" +#include "drivers/TimerEvent.h" +#include "platform/FunctionPointer.h" +#include "hal/ticker_api.h" +#include "platform/mbed_critical.h" + +namespace mbed { + +void TimeoutAbs::detach() +{ + core_util_critical_section_enter(); + remove(); + // unlocked only if we were attached (we locked it) and this is not low power ticker + if (_function && _lock_deepsleep) { + sleep_manager_unlock_deep_sleep(); + } + _function = 0; + core_util_critical_section_exit(); +} + +void TimeoutAbs::abs_setup(us_timestamp_t t) +{ + core_util_critical_section_enter(); + remove(); + insert_absolute(t); + core_util_critical_section_exit(); +} + +void TimeoutAbs::handler() +{ + Callback<void()> local = _function; + detach(); + local.call(); +} + +} // namespace mbed