Timer#
Hardware Interface#
Defined in namespace hal
#include <libhal/timer.hpp>
-
class timer#
Timer hardware abstraction interface.
Use this interface for devices and peripherals that have timer like capabilities, such that, when a timerβs time has expired, an event, interrupt, or signal is generated.
Timer drivers tick period must be an integer multiple of 1 nanosecond, meaning that the only tick period allowed are 1ns, 2ns, up to the maximum holdable in a std::chrono::nanosecond type. sub-nanosecond tick periods are not allowed.
Subclassed by hal::soft::inert_timer
Public Functions
-
inline bool is_running()#
Determine if the timer is currently running.
- Returns:
true - if a callback has been scheduled and has not been invoked yet, false otherwise.
-
inline void cancel()#
Stops a scheduled event from happening.
Does nothing if the timer is not currently running.
Note that there must be sufficient time between the this call finishing and the scheduled eventβs termination. If this call is too close to when the schedule event expires, this function may not complete before the hardware calls the callback.
-
inline void schedule(hal::callback<void(void)> p_callback, hal::time_duration p_delay)#
Schedule an callback be be executed after the delay time.
If this is called and the timer has already scheduled an event (in other words,
is_running()
returns true), then the previous scheduled event will be canceled and the new scheduled event will be started.If the delay time result in a tick period of 0, then the timer will execute after 1 tick period. For example, if the tick period is 1ms and the requested time delay is 500us, then the event will be scheduled for 1ms.
If the tick period is 1ms and the requested time is 2.5ms then the event will be scheduled after 2 tick periods or in 2ms.
- Parameters:
p_callback β - callback function to be called when the timer expires
p_delay β - the amount of time until the timer expires
- Throws:
hal::argument_out_of_domain β - if p_interval is greater than what can be cannot be achieved.
-
inline bool is_running()#