R_RTOS  0.1
DistributedRealTimeOperatingSystemfortheARMCortexMArchitecture
Stacked Software Timer

Functions for creating, initializing, maintaining and handling a task timers. More...

Data Structures

struct  sysTimerStruc
 Struct for system timer maintenance. More...
 
struct  tskTimerStruc
 Struct for task timer maintenance. More...
 
struct  timerStruc
 Struct for timer maintenance. More...
 

Macros

#define TMR_INVALID_TIME   (LifeTime)0xFFFFFFFFu
 Value for an invalid LifeTime.
 
#define TMR_PIT_DELAY   (uint32_t)0x3u
 Delay compensation between PIT and TPM timers. More...
 
#define MEM_OBJECTS_TMR   ((uint8_t)0x4u)
 Number of SyncEle that will be allocated by the Timer mechanism in its memory pool. More...
 

Typedefs

typedef uint16_t WaitTime
 Time to wait for a Timer.
 
typedef uint32_t SysTime
 Used to describe a systemtime.
 
typedef uint8_t SysTicks
 Amount of SysTicks.
 
typedef uint16_t TmrTime
 Used to describe the time of a software timer.
 
typedef uint32_t LifeTime
 Used to describe time in the system as a timestamp.
 
typedef enum timerTypeEn TimerType
 Enumeration of all the different types of software timers.
 
typedef struct sysTimerStruc SysTimer
 Struct for system timer maintenance.
 
typedef struct tskTimerStruc TskTimer
 Struct for task timer maintenance.
 
typedef struct timerStruc Timer
 Struct for timer maintenance.
 

Enumerations

Functions

void os_SCHEDULE (void)
 Schedules the next ready task according to its priority. More...
 
static RetCode tmr_InsertSysTmrQ (TmrFktCall *sysFktTmr, LifeTime expires)
 Insert the given TmrFktCall object into the system timer queue according to its expiration time. More...
 
static RetCode tmr_InsertTskTmrQ (PTskTCB tsk, LifeTime expires)
 Insert the given TskTCB object into the task timer queue according to its expiration time. More...
 
RetCode tmr_INIT (void)
 Calibrate the PIT Timer periodically. More...
 
RetCode tmr_setSysTimer (SysFktID fktID, TmrTime msToWait, uint8_t periodicity)
 Sets up a Timer to call a SysFkt corresponding to the given SysFktID as soon as the timer expires. More...
 
RetCode tmr_setTskTimer (PTskTCB tsk, TmrTime msToWait)
 Sets up a Timer for a task and queues it into the Timer queue according to its WaitTime relative to the current PIT value. More...
 
void tmr_SysTimerElapsed (void)
 Function to be called as soon as a system Timer expires. More...
 
void tmr_TskTimerElapsed (void)
 Function to be called as soon as a task Timer expires. More...
 
RetCode tmr_GiveUpOnTMR (PTskTCB const tsk)
 Forces the deletion of a task's Timer from the Timer queue and adjusts the queue accordingly. More...
 

Variables

SysFkt sys_SysFkt []
 System function array to hold various kinds of system functions. System functions can be referenced by their index in this array.
 
static MemPoolID memPoolID_TMR
 Memory Pool ID for the timer's memory pool. More...
 
static Timer tskTMR
 The start node for the task Timer queue. More...
 
static Timer sysTMR
 The start node for the system Timer queue. More...
 

Detailed Description

Functions for creating, initializing, maintaining and handling a task timers.

Macro Definition Documentation

#define MEM_OBJECTS_TMR   ((uint8_t)0x4u)

Number of SyncEle that will be allocated by the Timer mechanism in its memory pool.

Note
User Defined
#define TMR_PIT_DELAY   (uint32_t)0x3u

Delay compensation between PIT and TPM timers.

Returns
Delay value

Since the PIT and TPM timers are driven by different clock sources (BusClock for PIT; OSCERCLK for TPM) they might suffer from a desynchronization. In order to overcome this issue, a small delay is allowed.

Enumeration Type Documentation

Enumeration of all the different types of software timers.

Enumerator
SysTimerType 

System software timer.

TskTimerType 

Task software timer.

SysTickTimerType 

System Tick software timer.

Function Documentation

void os_SCHEDULE ( void  )

Schedules the next ready task according to its priority.

The task queue is scanned until a task ready to run is found. The queue is sorted according to the tasks' priority beforehand.

Postcondition
p_nxt_tsk_tcb A pointer to the chosen task's tskTCB is stored to this global variable.
If the next task does not equal the current task a context switch is initiated by setting PendSV to pending
RetCode tmr_GiveUpOnTMR ( PTskTCB const  tsk)

Forces the deletion of a task's Timer from the Timer queue and adjusts the queue accordingly.

Parameters
[in]tskPointer to the task's TskTcb
Returns
RetCode Return the success of the operation

If a task is destroyed, which still has a Timer, this Timer needs to be deleted from the queue and the timer might need to be adjusted accordingly.

Triggers the scheduler!

RetCode tmr_INIT ( void  )

Calibrate the PIT Timer periodically.

Since the PIT timer is clocked by the Bus clock whereas the TPM module has various clock sources the two timers drift away from each other. To compensate this behavior the PIT timer is calibrated in intervals according to a TPM timer.

static RetCode tmr_InsertSysTmrQ ( TmrFktCall sysFktTmr,
LifeTime  expires 
)
static

Insert the given TmrFktCall object into the system timer queue according to its expiration time.

Parameters
[in]sysFktTmrPointer to the TmrFktCall object to insert
[in]expiresExpiration time
Returns
RetCode
RET_OK
RET_NOK
Note
Entries are sorted according to their ascending timer expiration.
static RetCode tmr_InsertTskTmrQ ( PTskTCB  tsk,
LifeTime  expires 
)
static

Insert the given TskTCB object into the task timer queue according to its expiration time.

Parameters
[in]tskPointer to the TskTCB object to insert
[in]expiresExpiration time
Returns
RetCode
RET_OK
RET_NOK
Note
Entries are sorted according to their ascending timer expiration.
RetCode tmr_setSysTimer ( SysFktID  fktID,
TmrTime  msToWait,
uint8_t  periodicity 
)

Sets up a Timer to call a SysFkt corresponding to the given SysFktID as soon as the timer expires.

Parameters
[in]fktIDSysFktID of the function to call upon expiration
[in]msToWaitPeriod of time to wait in ms
[in]periodicityPeriodicity of the timer (if set to 1 the timer will reset itself)
Returns
RetCode
RET_OK
RET_NOK
RetCode tmr_setTskTimer ( PTskTCB  tsk,
TmrTime  msToWait 
)

Sets up a Timer for a task and queues it into the Timer queue according to its WaitTime relative to the current PIT value.

Parameters
[in]tskPointer to the task's TskTcb
[in]msToWaitPeriod of time to wait in ms.
Returns
RetCode Return the success of the operation

Sets up a Timer for the given task and queues the Timer into the Timer queue. The Timer, which expires the earliest is always the start of the list. Might adjust the startTMRNode.

void tmr_SysTimerElapsed ( void  )

Function to be called as soon as a system Timer expires.

Calls the system function and re-sets it according to its periodicty settings.

void tmr_TskTimerElapsed ( void  )

Function to be called as soon as a task Timer expires.

Adjusts the TskEvtFlags and sets the task ready (if it is not waiting on any other event). Also maintains the Timer queue and automatically scans for more Timers to be expired. Resets the timer which triggers the next Timer.

Triggers the scheduler!

Variable Documentation

MemPoolID memPoolID_TMR
static

Memory Pool ID for the timer's memory pool.

Allocation requests for SyncEle for the Timer will be served from the memory pool corresponding to this MemPoolID.

Timer sysTMR
static

The start node for the system Timer queue.

Initialized to NULL.

Timer tskTMR
static

The start node for the task Timer queue.

Initialized to NULL.