User Documentation
The example code for setting cyclic, single shot timeouts and for handling timer loop is provided below:
Example for setting cyclic and single shot timeouts:
* void
* TaskContext::scheduleCyclic(
* Timeout& timeout,
* const uint32_t period,
* const TimeUnitType unit)
* {
* if (!_timer.isActive(timeout))
* {
* if (_timer.setCyclic(timeout, period * unit, getSystemTimeUs32Bit()))
* {
* _timerEventPolicy.setEvent(); // OS and HW dependent
* }
* }
* }
*
* void
* TaskContext::schedule(
* Timeout& timeout,
* const uint32_t delay,
* const TimeUnitType unit)
* {
* if (!_timer.isActive(timeout))
* {
* if (_timer.set(timeout, delay * unit, getSystemTimeUs32Bit()))
* {
* _timerEventPolicy.setEvent(); // OS and HW dependent
* }
* }
* }
Example for handling timer loop:
* void
* TaskContext::handleTimeout()
* {
* while (_timer.processNextTimeout(getSystemTimeUs32Bit()))
* {}
* uint32_t nextDelta;
* if (_timer.getNextDelta(getSystemTimeUs32Bit(), nextDelta))
* {
* setTimeout(nextDelta); // OS and HW dependent
* }
* }
*
* TaskContext::cancel(Timeout& timeout)
* {
* _timer.cancel(timeout);
* }