#include <mn_timer.hpp>

Public Member Functions

 basic_timer (const char *strName, unsigned int uiPeriod, bool bIsOneShot=true)
 
virtual ~basic_timer ()
 
virtual int create ()
 
virtual int destroy (unsigned int timeout=(unsigned int) 0xffffffffUL)
 
virtual int active (unsigned int timeout=(unsigned int) 0xffffffffUL)
 
virtual int inactive (unsigned int timeout=(unsigned int) 0xffffffffUL)
 
virtual int reset (unsigned int timeout=(unsigned int) 0xffffffffUL)
 
virtual bool set_period (unsigned int uiNewPeriod, unsigned int timeout=(unsigned int) 0xffffffffUL)
 
virtual unsigned int get_period ()
 
const char * get_name ()
 
bool is_oneshot ()
 
virtual void * get_handle ()
 
int get_id ()
 
virtual void set_id (int nId)
 
virtual bool is_running ()
 
 operator bool ()
 

Protected Member Functions

virtual void on_timer ()=0
 
virtual void on_enter ()
 
virtual void on_exit ()
 

Static Protected Member Functions

static void runtimerstub (void *xTimer)
 

Private Attributes

bool m_bIsOneShot
 
unsigned int m_uiPeriod
 
const char * m_strName
 
void * m_pHandle
 
int m_iTimerID
 

Detailed Description

Wrapper class around FreeRTOS's implementation of a timer.

Constructor & Destructor Documentation

◆ basic_timer()

mn::basic_timer::basic_timer ( const char *  strName,
unsigned int  uiPeriod,
bool  bIsOneShot = true 
)

Construct a timer.

Parameters
strNameName of the timer.
uiPeriodWhen does the timer expire and run your Run() method.
bIsOneShottrue if this is a one shot timer. false if the timer expires every PeriodInTicks.

◆ ~basic_timer()

virtual mn::basic_timer::~basic_timer ( )
inlinevirtual

Member Function Documentation

◆ active()

int mn::basic_timer::active ( unsigned int  timeout = (unsigned int) 0xffffffffUL)
virtual

Start the timer.

Parameters
timeoutHow long to wait
Returns
ERR_TIMER_OK All okay, no error ERR_TIMER_NOTCREATED the timer are not created, plaese call create() first ERR_TIMER_AKTIVATE if it will not (i.e. timeout).

◆ create()

int mn::basic_timer::create ( )
virtual

Create the timer

Note
Timers are not active after they are created, you need to activate them via active, reset, etc.
Returns
ERR_TIMER_OK No error, ERR_TIMER_ALREADYINIT The timer are allready created and ERR_TIMER_CANTCREATE on error on create the FreeRTOS Timer

◆ destroy()

int mn::basic_timer::destroy ( unsigned int  timeout = (unsigned int) 0xffffffffUL)
virtual

destroy the timer

Parameters
timeoutHow long to wait
Returns
ERR_TIMER_OK No error, ERR_TIMER_NOTCREATED the timer are not created, plaese call create() first

◆ get_handle()

virtual void* mn::basic_timer::get_handle ( )
inlinevirtual

Get the FreeRTOS handle

Returns
the FreeRTOS handle

◆ get_id()

int mn::basic_timer::get_id ( )
inline

Returns the ID assigned to the timer.

Returns
The ID assigned to the timer being queried.

◆ get_name()

const char* mn::basic_timer::get_name ( )
inline

Get the timer's name

Returns
The timer's name

◆ get_period()

virtual unsigned int mn::basic_timer::get_period ( )
inlinevirtual

Get the timer's period

Returns
The timer's period

◆ inactive()

int mn::basic_timer::inactive ( unsigned int  timeout = (unsigned int) 0xffffffffUL)
virtual

Stop the timer

Parameters
timeoutHow long to wait
Returns
ERR_TIMER_OK All okay, no error ERR_TIMER_NOTCREATED the timer are not created, plaese call create() first ERR_TIMER_INAKTIVATE if it will not (i.e. timeout).

◆ is_oneshot()

bool mn::basic_timer::is_oneshot ( )
inline

Is the timer is one shotted?

Returns
true The timer is one shotted and false when not

◆ is_running()

bool mn::basic_timer::is_running ( )
virtual

Queries a timer to see if it is active or dormant.

Returns
false will be returned if the timer is dormant. And true will be returned if the timer is active.

◆ on_enter()

virtual void mn::basic_timer::on_enter ( )
inlineprotectedvirtual

You can override this functions, call befor on_timer

◆ on_exit()

virtual void mn::basic_timer::on_exit ( )
inlineprotectedvirtual

You can override this functions, call after on_timer

◆ on_timer()

virtual void mn::basic_timer::on_timer ( )
protectedpure virtual

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

◆ operator bool()

mn::basic_timer::operator bool ( )
inline

◆ reset()

int mn::basic_timer::reset ( unsigned int  timeout = (unsigned int) 0xffffffffUL)
virtual

Reset the timer

Parameters
timeoutHow long to wait
Returns
ERR_TIMER_OK All okay, no error ERR_TIMER_NOTCREATED the timer are not created, plaese call create() first ERR_TIMER_RESET if it will not (i.e. timeout).

◆ runtimerstub()

void mn::basic_timer::runtimerstub ( void *  xTimer)
staticprotected

Adapter function that allows you to write a class specific on_timer() function that interfaces with FreeRTOS.

◆ set_id()

void mn::basic_timer::set_id ( int  nId)
virtual

Sets the ID assigned to the timer.

If the same callback function is assigned to multiple timers then the timer ID can be used as time specific (timer local) storage.

Parameters
nIdThe ID to assign to the timer.

◆ set_period()

bool mn::basic_timer::set_period ( unsigned int  uiNewPeriod,
unsigned int  timeout = (unsigned int) 0xffffffffUL 
)
virtual

Change a timer's period.

Parameters
uiNewPeriodThe new period in ticks.
timeoutHow long to wait
Returns
true no error, false if it will not (i.e. timeout).

Member Data Documentation

◆ m_bIsOneShot

bool mn::basic_timer::m_bIsOneShot
private

A saved / cached copy of what the timers's mode is.

◆ m_iTimerID

int mn::basic_timer::m_iTimerID
private

A saved / cached copy of what the timers's ID is.

◆ m_pHandle

void* mn::basic_timer::m_pHandle
private

Reference to the underlying timer handle.

◆ m_strName

const char* mn::basic_timer::m_strName
private

A saved / cached copy of what the timers's name is.

◆ m_uiPeriod

unsigned int mn::basic_timer::m_uiPeriod
private

A saved / cached copy of what the timers's period is.


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