Skip to content

Class hal::timer

ClassList > hal > timer

Timer hardware abstraction interface. More...

  • #include <timer.hpp>

Inherited by the following classes: hal::cortex_m::systick_timer, hal::mock::timer, hal::soft::inert_timer

Classes

Type Name
struct cancel_t
Feedback from cancelling a timer.
struct is_running_t
Feedback after checking if the timer is running.
struct out_of_bounds_error
Error type indicating that the desired time delay is not achievable with this timer.
struct schedule_t
Feedback from scheduling a timer.

Public Functions

Type Name
result< cancel_t > cancel ()
Stops a scheduled event from happening.
result< is_running_t > is_running ()
Determine if the timer is currently running.
result< schedule_t > schedule (hal::callback< void(void)> p_callback, hal::time_duration p_delay)
Schedule an callback be be executed after the delay time.
virtual ~timer () = default

Detailed Description

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.

Public Functions Documentation

function cancel

Stops a scheduled event from happening.

inline result< cancel_t > hal::timer::cancel () 

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.

Returns:

result<cancel_t> - success or failure

function is_running

Determine if the timer is currently running.

inline result< is_running_t > hal::timer::is_running () 

Returns:

result<is_running_t> - information about the timer

function schedule

Schedule an callback be be executed after the delay time.

inline result< schedule_t > hal::timer::schedule (
    hal::callback < void(void)> p_callback,
    hal::time_duration p_delay
) 

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

Returns:

result<schedule_t> - success or failure

Exception:

function ~timer

virtual hal::timer::~timer () = default

The documentation for this class was generated from the following file libraries/include/libhal/timer.hpp