28#ifndef FREERTOS_TIMER_HPP
29#define FREERTOS_TIMER_HPP
42void callTimerFunction(TimerHandle_t timer);
64 static void*
operator new(size_t) =
delete;
65 static void*
operator new[](size_t) =
delete;
67 static void*
operator new(size_t,
void* ptr) {
71 static void*
operator new[](size_t,
void* ptr) {
99 return (handle != NULL);
127 return (xTimerIsTimerActive(handle) != pdFALSE);
169 inline bool start(
const TickType_t blockTime = 0)
const {
170 return (xTimerStart(handle, blockTime) == pdPASS);
207 BaseType_t taskWoken = pdFALSE;
208 const bool result = (xTimerStartFromISR(handle, &taskWoken) == pdPASS);
209 if (taskWoken == pdTRUE) {
210 higherPriorityTaskWoken =
true;
226 return (xTimerStartFromISR(handle, NULL) == pdPASS);
259 inline bool stop(
const TickType_t blockTime = 0)
const {
260 return (xTimerStop(handle, blockTime) == pdPASS);
296 BaseType_t taskWoken = pdFALSE;
297 const bool result = (xTimerStopFromISR(handle, &taskWoken) == pdPASS);
298 if (taskWoken == pdTRUE) {
299 higherPriorityTaskWoken =
true;
315 return (xTimerStopFromISR(handle, NULL) == pdPASS);
356 const TickType_t blockTime = 0)
const {
357 return (xTimerChangePeriod(handle, newPeriod, blockTime) == pdPASS);
403 const TickType_t newPeriod)
const {
404 BaseType_t taskWoken = pdFALSE;
406 (xTimerChangePeriodFromISR(handle, newPeriod, &taskWoken) == pdPASS);
407 if (taskWoken == pdTRUE) {
408 higherPriorityTaskWoken =
true;
426 return (xTimerChangePeriodFromISR(handle, newPeriod, NULL) == pdPASS);
462 if (xTimerDelete(handle, blockTime) == pdPASS) {
510 inline bool reset(
const TickType_t blockTime = 0)
const {
511 return (xTimerReset(handle, blockTime) == pdPASS);
548 BaseType_t taskWoken = pdFALSE;
549 const bool result = (xTimerResetFromISR(handle, &taskWoken) == pdPASS);
550 if (taskWoken == pdTRUE) {
551 higherPriorityTaskWoken =
true;
567 return (xTimerResetFromISR(handle, NULL) == pdPASS);
591 vTimerSetReloadMode(handle, (autoReload ? pdTRUE : pdFALSE));
613 return pcTimerGetName(handle);
636 return xTimerGetPeriod(handle);
665 return xTimerGetExpiryTime(handle);
686 return (uxTimerGetReloadMode(handle) == pdTRUE);
698 this->deleteBlockTime = deleteBlockTime;
710 return deleteBlockTime;
734 explicit TimerBase(
const TickType_t deleteBlockTime = 0)
735 : deleteBlockTime(deleteBlockTime) {}
756 TimerHandle_t handle = NULL;
757 TickType_t deleteBlockTime;
760#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
832 explicit Timer(
const TickType_t period,
const bool autoReload =
false,
833 const char* name =
"",
const TickType_t deleteBlockTime = 0)
835 this->handle = xTimerCreate(name, period, (autoReload ? pdTRUE : pdFALSE),
836 this, callTimerFunction);
846#if (configSUPPORT_STATIC_ALLOCATION == 1)
919 explicit StaticTimer(
const TickType_t period,
const bool autoReload =
false,
920 const char* name =
"",
921 const TickType_t deleteBlockTime = 0)
924 xTimerCreateStatic(name, period, (autoReload ? pdTRUE : pdFALSE),
this,
925 callTimerFunction, &staticTimer);
933 StaticTimer_t staticTimer;
940inline void callTimerFunction(TimerHandle_t timer) {
Class that encapsulates the functionality of a FreeRTOS timer.
Definition Timer.hpp:868
StaticTimer(const TickType_t period, const bool autoReload=false, const char *name="", const TickType_t deleteBlockTime=0)
Construct a new StaticTimer object by calling TimerHandle_t xTimerCreateStatic( const char * const pc...
Definition Timer.hpp:919
Base class that provides the standard task interface to FreeRTOS::Timer and FreeRTOS::StaticTimer.
Definition Timer.hpp:56
TimerBase(const TickType_t deleteBlockTime=0)
Construct a new TimerBase object. This default constructor is deliberately private as this class is n...
Definition Timer.hpp:734
bool deleteTimer(const TickType_t blockTime=0)
Function that calls BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xBlockTime )
Definition Timer.hpp:461
void setReloadMode(const bool autoReload) const
Function that calls void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t xAutoReload )
Definition Timer.hpp:590
virtual void timerFunction()=0
Abstraction function that acts as the entry point of the timer callback for the user.
bool changePeriodFromISR(const TickType_t newPeriod) const
Function that calls BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer, TickType_t xNewPeriod...
Definition Timer.hpp:425
bool startFromISR() const
Function that calls BaseType_t xTimerStartFromISR( TimerHandle_t xTimer, BaseType_t *pxHigherPriority...
Definition Timer.hpp:225
bool stop(const TickType_t blockTime=0) const
Function that calls BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xBlockTime )
Definition Timer.hpp:259
bool startFromISR(bool &higherPriorityTaskWoken) const
Function that calls BaseType_t xTimerStartFromISR( TimerHandle_t xTimer, BaseType_t *pxHigherPriority...
Definition Timer.hpp:206
bool resetFromISR() const
Function that calls BaseType_t xTimerResetFromISR( TimerHandle_t xTimer, BaseType_t *pxHigherPriority...
Definition Timer.hpp:566
TickType_t getPeriod() const
Function that calls TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
Definition Timer.hpp:635
bool changePeriod(const TickType_t newPeriod, const TickType_t blockTime=0) const
Function that calls BaseType_t xTimerChangePeriod( TimerHandle_t xTimer, TickType_t xNewPeriod,...
Definition Timer.hpp:355
bool stopFromISR() const
Function that calls BaseType_t xTimerStopFromISR( TimerHandle_t xTimer, BaseType_t *pxHigherPriorityT...
Definition Timer.hpp:314
bool getReloadMode() const
Function that calls UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer )
Definition Timer.hpp:685
bool isActive() const
Function that calls BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
Definition Timer.hpp:126
bool resetFromISR(bool &higherPriorityTaskWoken) const
Function that calls BaseType_t xTimerResetFromISR( TimerHandle_t xTimer, BaseType_t *pxHigherPriority...
Definition Timer.hpp:547
bool start(const TickType_t blockTime=0) const
Function that calls BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xBlockTime )
Definition Timer.hpp:169
bool isValid() const
Function that checks the value of the timer handle. This function should be called to ensure the time...
Definition Timer.hpp:98
void setDeleteBlockTime(const TickType_t deleteBlockTime=0)
Set the delete block time. This value is used when the destructor calls deleteTimer().
Definition Timer.hpp:697
~TimerBase()
Destroy the TimerBase object.
Definition Timer.hpp:747
bool reset(const TickType_t blockTime=0) const
Function that calls BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xBlockTime )
Definition Timer.hpp:510
bool stopFromISR(bool &higherPriorityTaskWoken) const
Function that calls BaseType_t xTimerStopFromISR( TimerHandle_t xTimer, BaseType_t *pxHigherPriorityT...
Definition Timer.hpp:295
TickType_t getDeleteBlockTime() const
Set the delete block time. This value is used when the destructor calls deleteTimer().
Definition Timer.hpp:709
virtual void timerEntry() final
Function that acts as the entry point of the timer instance.
Definition Timer.hpp:84
TickType_t getExpiryTime() const
Function that calls TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
Definition Timer.hpp:664
const char * getName() const
Function that calls const char * pcTimerGetName( TimerHandle_t xTimer )
Definition Timer.hpp:612
bool changePeriodFromISR(bool &higherPriorityTaskWoken, const TickType_t newPeriod) const
Function that calls BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer, TickType_t xNewPeriod...
Definition Timer.hpp:402
Class that encapsulates the functionality of a FreeRTOS timer.
Definition Timer.hpp:778
Timer(const TickType_t period, const bool autoReload=false, const char *name="", const TickType_t deleteBlockTime=0)
Construct a new Timer object by calling TimerHandle_t xTimerCreate( const char * const pcTimerName,...
Definition Timer.hpp:832