FreeRTOS C++ Wrappers  1.6.0
C++ interface to FreeRTOS
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Private Member Functions | Private Attributes | List of all members
cpp_freertos::Timer Class Referenceabstract

#include <timer.hpp>

Public Member Functions

 Timer (const char *const TimerName, TickType_t PeriodInTicks, bool Periodic=true)
 
 Timer (TickType_t PeriodInTicks, bool Periodic=true)
 
virtual ~Timer ()
 
bool IsActive ()
 
bool Start (TickType_t CmdTimeout=portMAX_DELAY)
 
bool StartFromISR (BaseType_t *pxHigherPriorityTaskWoken)
 
bool Stop (TickType_t CmdTimeout=portMAX_DELAY)
 
bool StopFromISR (BaseType_t *pxHigherPriorityTaskWoken)
 
bool Reset (TickType_t CmdTimeout=portMAX_DELAY)
 
bool ResetFromISR (BaseType_t *pxHigherPriorityTaskWoken)
 
bool SetPeriod (TickType_t NewPeriod, TickType_t CmdTimeout=portMAX_DELAY)
 
bool SetPeriodFromISR (TickType_t NewPeriod, BaseType_t *pxHigherPriorityTaskWoken)
 

Static Public Member Functions

static TaskHandle_t GetTimerDaemonHandle ()
 

Protected Member Functions

virtual void Run ()=0
 

Static Private Member Functions

static void TimerCallbackFunctionAdapter (TimerHandle_t xTimer)
 

Private Attributes

TimerHandle_t handle
 

Detailed Description

Wrapper class around FreeRTOS's implementation of a timer.

This is an abstract base class. To use this, you need to subclass it. All of your timers should be derived from the Timer class. Then implement the virtual Run function. This is a similar design to Java threading.

Definition at line 107 of file timer.hpp.

Constructor & Destructor Documentation

◆ Timer() [1/2]

Timer::Timer ( const char *const  TimerName,
TickType_t  PeriodInTicks,
bool  Periodic = true 
)

Construct a named timer. Timers are not active after they are created, you need to activate them via Start, Reset, etc.

Exceptions
TimerCreateException
Parameters
TimerNameName of the timer for debug.
PeriodInTicksWhen does the timer expire and run your Run() method.
Periodictrue if the timer expires every PeriodInTicks. false if this is a one shot timer.

Definition at line 46 of file ctimer.cpp.

◆ Timer() [2/2]

Timer::Timer ( TickType_t  PeriodInTicks,
bool  Periodic = true 
)

Construct an unnamed timer. Timers are not active after they are created, you need to activate them via Start, Reset, etc.

Exceptions
TimerCreateException
Parameters
PeriodInTicksWhen does the timer expire and run your Run() method.
Periodictrue if the timer expires every PeriodInTicks. false if this is a one shot timer.

Definition at line 67 of file ctimer.cpp.

◆ ~Timer()

Timer::~Timer ( )
virtual

Destructor

Definition at line 87 of file ctimer.cpp.

Member Function Documentation

◆ GetTimerDaemonHandle()

TaskHandle_t Timer::GetTimerDaemonHandle ( )
static

If you need it, obtain the task handle of the FreeRTOS task that is running the timers.

Returns
Task handle of the FreeRTOS timer task.

Definition at line 157 of file ctimer.cpp.

◆ IsActive()

bool Timer::IsActive ( )

Is the timer currently active?

Returns
true if the timer is active, false otherwise.

Definition at line 93 of file ctimer.cpp.

◆ Reset()

bool Timer::Reset ( TickType_t  CmdTimeout = portMAX_DELAY)

Reset a timer. This changes the state to active.

Parameters
CmdTimeoutHow long to wait to send this command to the timer code.
Returns
true if this command will be sent to the timer code, false if it will not (i.e. timeout).

Definition at line 125 of file ctimer.cpp.

◆ ResetFromISR()

bool Timer::ResetFromISR ( BaseType_t *  pxHigherPriorityTaskWoken)

Reset a timer from ISR context. This changes the state to active.

Parameters
pxHigherPriorityTaskWokenDid this operation result in a rescheduling event.
Returns
true if this command will be sent to the timer code, false if it will not (i.e. timeout).

Definition at line 131 of file ctimer.cpp.

◆ Run()

virtual void cpp_freertos::Timer::Run ( )
protectedpure virtual

Implementation of your actual timer code. You must override this function.

◆ SetPeriod()

bool Timer::SetPeriod ( TickType_t  NewPeriod,
TickType_t  CmdTimeout = portMAX_DELAY 
)

Change a timer's period.

Parameters
NewPeriodThe period in ticks.
CmdTimeoutHow long to wait to send this command to the timer code.
Returns
true if this command will be sent to the timer code, false if it will not (i.e. timeout).

Definition at line 138 of file ctimer.cpp.

◆ SetPeriodFromISR()

bool Timer::SetPeriodFromISR ( TickType_t  NewPeriod,
BaseType_t *  pxHigherPriorityTaskWoken 
)

Change a timer's period from ISR context.

Parameters
NewPeriodThe period in ticks.
pxHigherPriorityTaskWokenDid this operation result in a rescheduling event.
Returns
true if this command will be sent to the timer code, false if it will not (i.e. timeout).

Definition at line 146 of file ctimer.cpp.

◆ Start()

bool Timer::Start ( TickType_t  CmdTimeout = portMAX_DELAY)

Start a timer. This changes the state to active.

Parameters
CmdTimeoutHow long to wait to send this command to the timer code.
Returns
true if this command will be sent to the timer code, false if it will not (i.e. timeout).

Definition at line 99 of file ctimer.cpp.

◆ StartFromISR()

bool Timer::StartFromISR ( BaseType_t *  pxHigherPriorityTaskWoken)

Start a timer from ISR context. This changes the state to active.

Parameters
pxHigherPriorityTaskWokenDid this operation result in a rescheduling event.
Returns
true if this command will be sent to the timer code, false if it will not (i.e. timeout).

Definition at line 105 of file ctimer.cpp.

◆ Stop()

bool Timer::Stop ( TickType_t  CmdTimeout = portMAX_DELAY)

Stop a timer. This changes the state to inactive.

Parameters
CmdTimeoutHow long to wait to send this command to the timer code.
Returns
true if this command will be sent to the timer code, false if it will not (i.e. timeout).

Definition at line 112 of file ctimer.cpp.

◆ StopFromISR()

bool Timer::StopFromISR ( BaseType_t *  pxHigherPriorityTaskWoken)

Stop a timer from ISR context. This changes the state to inactive.

Parameters
pxHigherPriorityTaskWokenDid this operation result in a rescheduling event.
Returns
true if this command will be sent to the timer code, false if it will not (i.e. timeout).

Definition at line 118 of file ctimer.cpp.

◆ TimerCallbackFunctionAdapter()

void Timer::TimerCallbackFunctionAdapter ( TimerHandle_t  xTimer)
staticprivate

Adapter function that allows you to write a class specific Run() function that interfaces with FreeRTOS. Look at the implementation of the constructors and this code to see how the interface between C and C++ is performed.

Definition at line 165 of file ctimer.cpp.

Member Data Documentation

◆ handle

TimerHandle_t cpp_freertos::Timer::handle
private

Reference to the underlying timer handle.

Definition at line 279 of file timer.hpp.


The documentation for this class was generated from the following files: