Template class to implement a polled timer. More...
#include <PolledTimer.h>
Public Types | |
using | TickType = typename Clock::TickType |
using | Margin = NanoTime::TimeConst< Clock, NanoTime::Microseconds, POLLED_TIMER_MARGIN_US > |
![]() | |
using | Clock = Clock |
using | TimeType = TimeType |
using | TicksPerUnit = typename Clock::template TicksPerUnit< unit_ > |
using | TimeConst = TimeConst< Clock, unit_, time > |
using | TicksConst = TicksConst< Clock, ticks > |
using | MaxClockTime = typename Clock::template MaxTime< unit_ > |
Get the time corresponding to the maximum clock tick value. More... | |
![]() | |
using | TickType = TickType_ |
template<uint64_t ticks> | |
using | TicksConst = TicksConst< Clock, ticks > |
template<Unit unit, uint64_t time> | |
using | TimeConst = TimeConst< Clock, unit, time > |
template<Unit unit> | |
using | TicksPerUnit = std::ratio_divide< std::ratio< frequency_ >, UnitTickRatio< unit > > |
template<Unit unit, typename TimeType > | |
using | TimeSource = TimeSource< Clock, unit, TimeType > |
template<typename T > | |
using | Ticks = Ticks< Clock, T > |
using | MaxTicks = TicksConst< maxTicks_ > |
template<Unit unit> | |
using | MaxTime = typename MaxTicks::template TimeConst< unit > |
Public Member Functions | |
Timer (const TimeType &timeInterval=0) | |
Create a Timer with optional expiry time. More... | |
void | start () |
Start the timer. More... | |
template<uint64_t timeInterval> | |
void | reset () |
Start the timer with a new expiry interval. More... | |
template<uint64_t timeInterval> | |
constexpr uint32_t | checkTime () |
Check the given time interval is valid and return the corresponding tick count. More... | |
bool | reset (const TimeType &timeInterval) |
Start the timer with a new expiry interval. More... | |
bool | resetTicks (const TimeType &interval) |
Start the timer with a new expiry interval. More... | |
void | cancel () |
Cancelling a timer means it will never expire. More... | |
TickType | elapsedTicks () const |
Get elapsed ticks since start() was last called. More... | |
NanoTime::Time< TimeType > | elapsedTime () const |
Get elapsed time since start() was last called. More... | |
TickType | remainingTicks () const |
Get ticks remaining until expiry. More... | |
NanoTime::Time< TimeType > | remainingTime () const |
Get time remaining until expiry. More... | |
bool | canExpire () const |
bool | canWait () const |
bool | expired () |
Determine if timer has expired. More... | |
Static Public Member Functions | |
static constexpr NanoTime::Unit | unit () |
static constexpr TickType | maxInterval () |
static constexpr Margin | margin () |
![]() | |
static constexpr Unit | unit () |
static constexpr BasicRatio32 | ticksPerUnit () |
Number of clock ticks per unit of time. More... | |
static constexpr MaxClockTime | maxClockTime () |
static constexpr TimeConst< time > | timeConst () |
Obtain a TimeConst type representing the given time quantity. More... | |
static constexpr TicksConst< ticks > | ticksConst () |
Class template defining a fixed tick quantity. More... | |
static constexpr Time< TimeType > | maxCalcTime () |
The maximum time value supported by timeToTicks without overflowing. More... | |
static constexpr Ticks< Clock, TimeType > | maxCalcTicks () |
The maximum tick value supported by ticksToTime without overflowing. More... | |
static Ticks< Clock, TimeType > | timeToTicks (TimeType time) |
Get the number of ticks for a given time. More... | |
static constexpr uint64_t | timeToTicks () |
Get the number of ticks for a given time. More... | |
static constexpr uint64_t | ticksToTime () |
Get the time for a given number of clock ticks. More... | |
static Time< TimeType > | ticksToTime (TimeType ticks) |
Get the time for a given number of clock ticks. More... | |
static String | toString () |
![]() | |
static constexpr const char * | typeName () |
static constexpr uint32_t | frequency () |
static constexpr MaxTicks | maxTicks () |
template<Unit unit> | |
static constexpr MaxTime< unit > | maxTime () |
static Ratio32 | ticksPerUnit (Unit unit) |
Get ticks per unit as a Ratio object. More... | |
template<Unit unit, uint64_t time> | |
static constexpr TimeConst< unit, time > | timeConst () |
Class template defining a fixed time quantity. More... | |
template<uint64_t ticks> | |
static constexpr TicksConst< ticks > | ticksConst () |
Class template defining a fixed tick quantity. More... | |
template<Unit unit, typename TimeType > | |
static constexpr TimeSource< unit, TimeType > | timeSource () |
Create a Time Source for this Clock. More... | |
template<Unit unit, typename TimeType > | |
static Ticks< TimeType > | timeToTicks (TimeType time) |
Get the number of ticks for a given time. More... | |
template<Unit unit, typename TimeType > | |
static Time< TimeType > | ticksToTime (TimeType ticks) |
Get the time for a given number of clock ticks. More... | |
static String | toString () |
Detailed Description
template<class Clock, NanoTime::Unit unit_, bool IsPeriodic, typename TimeType>
class PolledTimer::Timer< Clock, unit_, IsPeriodic, TimeType >
Template class to implement a polled timer.
- Template Parameters
-
Clock Clock source unit Time unit for tick/time conversions IsPeriodic TimeType Variable type to use (uint32_t or uint64_t)
- Note
- Intervals and expiry use 'tick' values which are very efficient, whereas 'time' values must be computed so are very slow (~100+ cycles for uint32_t, considerably more for uint64_t). The class keeps a note of a 'start' time (in ticks) used to determine the
elapsed()
return value. An 'interval' value may be given is specified, then theexpired()
method returns true.
If the interval is set to 0, the timer will expire immediately, and remain so: canWait()
will return false. Call cancel()
to prevent the timer from ever expiring: canExpire()
will return false. Call start()
to set the timer going with the previously set interval. Call reset()
to set the timer with a new interval.
A periodic timer will automatically restart when expired. A one-shot timer will remain expired until reset.
Member Typedef Documentation
◆ Margin
using PolledTimer::Timer< Clock, unit_, IsPeriodic, TimeType >::Margin = NanoTime::TimeConst<Clock, NanoTime::Microseconds, POLLED_TIMER_MARGIN_US> |
◆ TickType
using PolledTimer::Timer< Clock, unit_, IsPeriodic, TimeType >::TickType = typename Clock::TickType |
Constructor & Destructor Documentation
◆ Timer()
|
inline |
Create a Timer with optional expiry time.
- Parameters
-
timeInterval Relative time until expiry
Member Function Documentation
◆ cancel()
|
inline |
Cancelling a timer means it will never expire.
◆ canExpire()
|
inline |
◆ canWait()
|
inline |
◆ checkTime()
|
inlineconstexpr |
Check the given time interval is valid and return the corresponding tick count.
- Template Parameters
-
timeInterval
- Return values
-
uint32_t
- Note
- If time interval is invalid fails compilation
◆ elapsedTicks()
|
inline |
Get elapsed ticks since start() was last called.
◆ elapsedTime()
|
inline |
Get elapsed time since start() was last called.
◆ expired()
|
inline |
Determine if timer has expired.
- Return values
-
bool
◆ margin()
|
inlinestaticconstexpr |
◆ maxInterval()
|
inlinestaticconstexpr |
◆ remainingTicks()
|
inline |
Get ticks remaining until expiry.
◆ remainingTime()
|
inline |
Get time remaining until expiry.
◆ reset() [1/2]
|
inline |
Start the timer with a new expiry interval.
- Template Parameters
-
timeInterval Time to expire after last call to start()
◆ reset() [2/2]
|
inline |
Start the timer with a new expiry interval.
- Parameters
-
timeInterval Time to expire after last call to start()
- Return values
-
bool true on success, false on failure
- See also
- See
resetTicks()
◆ resetTicks()
|
inline |
Start the timer with a new expiry interval.
- Parameters
-
interval Clock ticks to expire after last call to start()
- Return values
-
bool true on success, false if interval is out of range
- Note
- If time interval is 0, timer will expire immediately, and if it exceeds the maximum interval the timer will never expire.
◆ start()
|
inline |
Start the timer.
◆ unit()
|
inlinestaticconstexpr |
The documentation for this class was generated from the following file: