demostration for TimeoutAbs
Demo absolute timeout.
Event occurs at absolute time instead of relative to when attach()
called. Random delay is added to show independence from when attach()
is called.
Revision 0:3985faffb331, committed 2018-11-26
- Comitter:
- Wayne Roberts
- Date:
- Mon Nov 26 14:37:06 2018 -0800
- Commit message:
- initial commit
Changed in this revision
diff -r 000000000000 -r 3985faffb331 TimeoutAbs.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TimeoutAbs.lib Mon Nov 26 14:37:06 2018 -0800 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/dudmuck/code/TimeoutAbs/#900163d530ae
diff -r 000000000000 -r 3985faffb331 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 26 14:37:06 2018 -0800 @@ -0,0 +1,40 @@ +#include "mbed.h" +#include "LowPowerTimeoutAbs.h" + +volatile bool ev; +Timer t; + +LowPowerTimeoutAbs tabs; + +void my_callback() +{ + ev = true; +} + +us_timestamp_t tabs_started_at; + +int main() +{ + unsigned prev; + t.start(); + tabs_started_at = tabs.read_us(); + tabs.attach_us(my_callback, tabs_started_at + 100000); + prev = t.read_us(); + printf("tabs_started_at:%llu prev:%u\r\n", tabs_started_at, prev); + for (;;) { + unsigned now; + if (ev) { + unsigned late; + now = t.read_us(); + tabs_started_at += 1000000; + late = rand() % 200000; + printf("time %u\t", now - prev); + fflush(stdout); + wait_us(late); + printf("late:%u\r\n", late); + tabs.attach_us(my_callback, tabs_started_at); + prev = now; + ev = false; + } + } +}
diff -r 000000000000 -r 3985faffb331 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Mon Nov 26 14:37:06 2018 -0800 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#2fd0c5cfbd83fce62da6308f9d64c0ab64e1f0d6