Mark Gottscho / HardwareTimersLib

Fork of HardwareTimersLib by Mark Gottscho

Embed: (wiki syntax)

« Back to documentation index

HardwareTimer Class Reference

HardwareTimer Class Reference

This provides a base class from which actual hardware timers should derive their implementations. More...

#include <HardwareTimer.h>

Inherited by Timer_LPTMR, Timer_PIT, and Timer_TPM.

Public Member Functions

 HardwareTimer (uint32_t maxRolloverTick, float tickValue, tick_units_t tickUnits)
 Constructs a new HardwareTimer.
virtual ~HardwareTimer ()
 Destructs the HardwareTimer.
bool valid ()
bool enabled ()
bool running ()
float tickValue ()
float tickUnits ()
void enable (void(*fptr)(void))
 Enables the timer with a user-specified callback function that is called each time the timer expires.
template<typename T >
void enable (T *tptr, void(T::*mptr)(void))
 Enables the timer with a user-specified callback function that is called each time the timer expires.
void disable ()
 Stops and disables the timer.
void start (uint32_t callback_tick_count, bool periodic, uint32_t num_callbacks)
 Starts the timer.
uint32_t getMaxCallbackTickCount ()
PreciseTime getTime ()
 Gets the timer value in a nice form.
virtual uint32_t getTick ()=0
virtual void __timer_isr ()=0
 Interrupt service routine for the timer.

Protected Member Functions

virtual void __init_timer ()=0
 Initializes the particular hardware timer.
virtual void __start_timer ()=0
 Starts the particular hardware timer.
virtual void __stop_timer ()=0
 Stop and disable the particular hardware timer.

Detailed Description

This provides a base class from which actual hardware timers should derive their implementations.

This allows for a nice software interface regardless of the particular timer used.

Definition at line 17 of file HardwareTimer.h.


Constructor & Destructor Documentation

HardwareTimer ( uint32_t  maxRolloverTick,
float  tickValue,
tick_units_t  tickUnits 
)

Constructs a new HardwareTimer.

Parameters:
validif false, none of the timer functions can be used. This is intended to enforce only one object managing a unique hardware timer.
maxRolloverTickmaximum number of ticks in the hardware unit before it rolls over.
tickValuethe amount of time corresponding to each timer tick, in units given by tickUnits.
tickUnitsunits for tickValue

Definition at line 10 of file HardwareTimer.cpp.

~HardwareTimer (  ) [virtual]

Destructs the HardwareTimer.

Definition at line 25 of file HardwareTimer.cpp.


Member Function Documentation

virtual void __init_timer (  ) [protected, pure virtual]

Initializes the particular hardware timer.

virtual void __start_timer (  ) [protected, pure virtual]

Starts the particular hardware timer.

virtual void __stop_timer (  ) [protected, pure virtual]

Stop and disable the particular hardware timer.

virtual void __timer_isr (  ) [pure virtual]

Interrupt service routine for the timer.

This should do timer hardware-specific chores before calling the user callback function.

void disable (  )

Stops and disables the timer.

No user function callbacks will be made, and the tick value stops increasing.

Definition at line 99 of file HardwareTimer.cpp.

void enable ( void(*)(void)  fptr )

Enables the timer with a user-specified callback function that is called each time the timer expires.

Parameters:
fptrthe user callback function

Definition at line 65 of file HardwareTimer.cpp.

void enable ( T *  tptr,
void(T::*)(void)  mptr 
)

Enables the timer with a user-specified callback function that is called each time the timer expires.

Parameters:
tptrthe object
mptrmethod to call on the object

Definition at line 81 of file HardwareTimer.cpp.

bool enabled (  )
Returns:
true if the timer is ready to start.

Definition at line 35 of file HardwareTimer.cpp.

uint32_t getMaxCallbackTickCount (  )
Returns:
the maximum value of the user-settable callback tick count (via startTimer()). Some timers may support full 32-bit tick counts, while others may be less.

Definition at line 128 of file HardwareTimer.cpp.

virtual uint32_t getTick (  ) [pure virtual]
Returns:
the current tick number. Convert to seconds by multiplying the return value with tickValue(). Note that getTick() * tickValue() can easily overflow on faster timers due to the 32-bit upper bound on arithmetic.

Implemented in Timer_LPTMR, Timer_PIT, and Timer_TPM.

PreciseTime getTime (  )

Gets the timer value in a nice form.

Note that in general, the timer may overflow, leading to saturated values obtained from getTime(). To maximize resolution, accuracy, performance, and range, it is recommended to use getTick() for most purposes. getTime() is mostly for convenience.

Returns:
the current tick converted into a PreciseTime representation.

Definition at line 132 of file HardwareTimer.cpp.

bool running (  )
Returns:
true if the timer is running.

Definition at line 39 of file HardwareTimer.cpp.

void start ( uint32_t  callback_tick_count,
bool  periodic,
uint32_t  num_callbacks 
)

Starts the timer.

If valid() or enabled() are false, then this method does nothing. Otherwise, the timer begins ticking. The user callback function specified in enableTimer() is called each time the timer rolls over.

Parameters:
callback_tick_countthe modulo tick value for when the timer calls the user callback function. Note that the timer counts up. Note that some timers may not support the full 32-bit range. Use getMaxCallbackTickCount() To check the maximum allowed value. If callback_tick_count is greater than that value, this method will have no effect.
periodicif true, the timer will call the user function every time the internal tick modulo callback_tick_count is reached. If false, the user callback function is only called the first num_callbacks times.
num_callbacksif periodic is set to false, this many callbacks will be made. Before the timer stops.

Definition at line 113 of file HardwareTimer.cpp.

float tickUnits (  )
Returns:
time in seconds corresponding to each tick

Definition at line 47 of file HardwareTimer.cpp.

float tickValue (  )
Returns:
the amount of time corresponding to each timer tick in units given by tickUnits().

Definition at line 43 of file HardwareTimer.cpp.

bool valid (  )
Returns:
true if this timer is valid. If false, the timer cannot be used.

Definition at line 31 of file HardwareTimer.cpp.