R_RTOS  0.1
DistributedRealTimeOperatingSystemfortheARMCortexMArchitecture

Functions for creating, maintaining and handling tasks. More...

Data Structures

struct  tskMailBox
 Task mailbox for messaging services. More...
 
struct  advTskPrio_struc
 Contains the TskPrio visible to the system and the real TskPrio. More...
 
struct  tskTCB
 Task Control Block. More...
 

Macros

#define MAX_TASKS   NR_OF_TSKS
 Maximum number of tasks in the system. More...
 
#define TSK_ID_IDLE   ((TskID)0x0u)
 Reserved TskID for the IDLE Task. More...
 
#define TSK_ID_NO_TSK   TSK_ID_IDLE
 Reserved ID for no task. More...
 
#define TSK_GETSTATE(pTsk)   (TskState)(pTsk->tskState)
 Given a pointer to a TskTCB, retrieve the current state of the task.
 
#define TSK_STATE_IS_ERROR(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_ERROR)
 Evaluate if the task is in an error state.
 
#define TSK_STATE_IS_ACTIVE(pTsk)   (TskState)(TSK_GETSTATE(pTsk) & TSK_STATE_ACTIVE)
 Evaluate if the task is in an active state.
 
#define TSK_STATE_IS_ACTIVE_RUNNING(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_ACTIVE_RUNNING )
 Evalutate if the task is currently in the ACTIVE_RUNNING state.
 
#define TSK_STATE_IS_ACTIVE_SUSPENDED(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_ACTIVE_SUSPENDED )
 Evalutate if the task is currently in the ACTIVE_SUSPENDED state.
 
#define TSK_STATE_IS_ACTIVE_READY(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_ACTIVE_READY )
 Evalutate if the task is currently in the ACTIVE_READY state.
 
#define TSK_STATE_IS_ACTIVE_CRITSEC(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_ACTIVE_CRITSEC )
 Evalutate if the task is currently in the ACTIVE_CRITSEC state. More...
 
#define TSK_STATE_IS_WAITING(pTsk)   (TskState)(TSK_GETSTATE(pTsk) & TSK_STATE_WAITING)
 Evalutate if the task is in a waiting state.
 
#define TSK_STATE_IS_WAITING_TMR(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_WAITING_TMR)
 Evalutate if the task is in a waiting state, waiting for a software timer to expire.
 
#define TSK_STATE_IS_WAITING_MSGRCV(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_WAITING_MSGRCV)
 Evalutate if the task is in a waiting state, waiting for a message to be received.
 
#define TSK_STATE_IS_WAITING_MSGSND(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_WAITING_MSGSND)
 Evalutate if the task is in a waiting state, waiting for a message to be send.
 
#define TSK_STATE_IS_WAITING_EVT(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_WAITING_EVT)
 Evalutate if the task is in a waiting state, waiting for an event or a group of events.
 
#define TSK_STATE_IS_WAITING_SEM(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_WAITING_SEM)
 Evalutate if the task is in a waiting state, waiting for an occupied semaphore.
 
#define TSK_STATE_IS_WAITING_MNTR(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_WAITING_MNTR)
 Evalutate if the task is in a waiting state, waiting for a currently blocked monitor.
 
#define TSK_STATE_IS_UNINIT(pTsk)   (TskState)(TSK_GETSTATE(pTsk) & TSK_STATE_UNINIT)
 Evalutate if the task is in an uninitialized state. More...
 
#define TSK_STATE_IS_UNINIT_UNINIT(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_UNINIT_UNINIT)
 Evalutate if the task has not yet been initialized correctly.
 
#define TSK_STATE_IS_UNINIT_FAILED(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_UNINIT_FAILED)
 Evalutate if the task is in an uninitialized state due to a system failure.
 
#define TSK_STATE_IS_UNINIT_ENDED(pTsk)   (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_UNINIT_ENDED)
 Evalutate if the task is in an uninitialized state because it finished its execution.
 
#define NR_OF_TSKS   ((uint8_t)0x4u)
 Number of tasks in the system. More...
 
#define TSK_PRIO_LEVELS_NR   ((uint8_t)0xFu)
 Number of available priority levels in the system. More...
 

Typedefs

typedef uint8_t TskID
 Task identification number (ID).
 
typedef uint8_t TskPrioLvl
 Used to set the size of the task priorities.
 
typedef uint8_t tskStateT
 Used to set the size of the task states.
 
typedef FktCall TskStartAddr
 function pointer to a task's function with no arguments and no return.
 
typedef FktCall TskEndAddr
 function pointer to a function which shall be called if a task finishes its execution.
 
typedef enum tskPrio TskPrio
 Task priority level.
 
typedef enum tskState TskState
 Possible states of tasks. More...
 
typedef enum tskSettings TskSettings
 Settings of a task...
 
typedef struct tskMailBox TskMB
 Task mailbox for messaging services. More...
 
typedef struct advTskPrio_struc AdvTskPrio
 Contains the TskPrio visible to the system and the real TskPrio. More...
 
typedef struct tskTCB TskTCB
 Task Control Block. More...
 

Enumerations

Functions

void os_SCHEDULE (void)
 Schedules the next ready task according to its priority. More...
 
RetCode tsk_tskInit (const TskID tskID, const TskStartAddr const strtAddr, const TskEndAddr const endAddr, const StackSize stkSze)
 Creates a task according to the provided input parameters. More...
 
RetCode os_IDLETskInit (const TskStartAddr const strtAddr)
 Creates the IDLE Task. More...
 
RetCode tsk_tskDestroy (TskTCB *const tsk)
 Destroy the given task. More...
 
RetCode tsk_ClrEvt (PTskTCB const tsk, PSyncEle const syncEle)
 Clear the event that currently blocks the task. More...
 
RetCode tsk_SetEvt (PTskTCB const tsk, PSyncEle const syncEle)
 Set the event described by syncEle for the specified task. More...
 
RetCode tsk_SetInactive (PTskTCB const tsk, TskState tskInactvState)
 Set the specified task inactive, remove from active wait queue and set the specified new task state. More...
 
RetCode tsk_ChngePrio (PTskTCB const tsk, const TskPrio newTskPrio)
 

Variables

BitsOSFlags gOS_FLAGS
 Flags used for maintaining the OS. More...
 
TskTCBp_cur_tsk_tcb
 Pointer to currently running task's tskTCB. More...
 
PTskTCB const pIDLETsk = &( tsk_AR[0] )
 Constant pointer to the IDLE Task's tskTCB. More...
 
PTskTCB pIDLETsk
 Constant pointer to the IDLE Task's tskTCB. More...
 

Detailed Description

Functions for creating, maintaining and handling tasks.

Macro Definition Documentation

#define MAX_TASKS   NR_OF_TSKS

Maximum number of tasks in the system.

The Maximum number of tasks in the system is influenced by the amount of heap available.

#define NR_OF_TSKS   ((uint8_t)0x4u)

Number of tasks in the system.

Note
User Defined
#define TSK_ID_IDLE   ((TskID)0x0u)

Reserved TskID for the IDLE Task.

TskID 0 is reserved for the IDLE Task to ensure it always has the same ID

Warning
NO TASK EXCEPT THE IDLE TASK SHALL HAVE THIS ID!
#define TSK_ID_NO_TSK   TSK_ID_IDLE

Reserved ID for no task.

TSK_ID_NO_TSK is a specially reserved TskID to indicate that there is no task.

Warning
NO TASK SHALL HAVE THIS ID!
#define TSK_PRIO_LEVELS_NR   ((uint8_t)0xFu)

Number of available priority levels in the system.

Note
User defined.
Maximum 256, minimum 2
#define TSK_STATE_IS_ACTIVE_CRITSEC (   pTsk)    (TskState)(TSK_GETSTATE(pTsk) == TSK_STATE_ACTIVE_CRITSEC )

Evalutate if the task is currently in the ACTIVE_CRITSEC state.

The task is currently running and also within a critical section.

#define TSK_STATE_IS_UNINIT (   pTsk)    (TskState)(TSK_GETSTATE(pTsk) & TSK_STATE_UNINIT)

Evalutate if the task is in an uninitialized state.

Warning
IF THE TASK IS UNINITIALIZED, DO NOT ATTEMPT TO FORCEFULLY RUN A TASK.

Typedef Documentation

typedef struct advTskPrio_struc AdvTskPrio

Contains the TskPrio visible to the system and the real TskPrio.

Each task has a visible TskPrio which represents the priority the task currently has as seen by the system. Additionally each task saves its actual TskPrio for further retrieval.

typedef struct tskMailBox TskMB

Task mailbox for messaging services.

Mailbox to keep track of received messages and their sources. Mailbox are arranged in a single linked list. Hence a task can have multiple mailboxes of the same or different sources.

typedef enum tskState TskState

Possible states of tasks.

State Mask (bits)
TSK_STATE_ERROR 0000 0000
TSK_STATE_ACTIVE 0001 0000
TSK_STATE_ACTIVE_RUNNING 0001 0001
TSK_STATE_ACTIVE_SUSPENDED 0001 0010
TSK_STATE_ACTIVE_READY 0001 0100
TSK_STATE_ACTIVE_CRITSEC 0001 1000
TSK_STATE_WAITING 0110 0000
TSK_STATE_WAITING_MSGNG 0010 0000
TSK_STATE_WAITING_MSGRCV 0010 0001
TSK_STATE_WAITING_MSGSND 0010 0010
TSK_STATE_WAITING_SYNC 0100 0000
TSK_STATE_WAITING_TMR 0100 0001
TSK_STATE_WAITING_EVT 0100 0010
TSK_STATE_WAITING_SEM 0100 0100
TSK_STATE_WAITING_MNTR 0100 1000
TSK_STATE_UNINIT 1000 0000
TSK_STATE_UNINIT_UNINIT 1000 0001
TSK_STATE_UNINIT_FAILED 1000 0010
TSK_STATE_UNINIT_ENDED 1000 1000
typedef struct tskTCB TskTCB

Task Control Block.

The Task Control block contains information about the task and its state. In addition the TCB contains a XORed pointer to the next and previous task queue entry.

Enumeration Type Documentation

enum tskPrio

Task priority level.

Enumerator
TSK_PRIO_ERROR 

Pseudo priority level indicating an error.

TSK_PRIO_LOWEST 

TSK_PRIO_LOWEST.

TSK_PRIO_LOWER 

TSK_PRIO_LOWER.

TSK_PRIO_LOW 

TSK_PRIO_LOW.

TSK_PRIO_MED 

TSK_PRIO_MED.

TSK_PRIO_ABOVMED 

TSK_PRIO_ABOVMED.

TSK_PRIO_HIG 

TSK_PRIO_HIG.

TSK_PRIO_HIGHER 

TSK_PRIO_HIGHER.

TSK_PRIO_HIGHEST 

TSK_PRIO_HIGHEST.

TSK_PRIO_ULT 

TSK_PRIO_ULT.

TSK_PRIO_IDLE 

Utmost highest priority is unique to the IDLE Task to ensure that it is always the start of the list regardless of the other task's priority levels.

Settings of a task...

Enumerator
TskSet_NONE 

NO SETTINGS.

TskSet_Periodic 

keep task context

TskSet_OneShot 

delete after execution

TskSet_DUMMY_0 

TskSet_DUMMY_0.

TskSet_DUMMY_1 

TskSet_DUMMY_1.

TskSet_DUMMY_2 

TskSet_DUMMY_2.

TskSet_DUMMY_3 

TskSet_DUMMY_3.

TskSet_DUMMY_4 

TskSet_DUMMY_4.

TskSet_DUMMY_5 

TskSet_DUMMY_5.

enum tskState

Possible states of tasks.

State Mask (bits)
TSK_STATE_ERROR 0000 0000
TSK_STATE_ACTIVE 0001 0000
TSK_STATE_ACTIVE_RUNNING 0001 0001
TSK_STATE_ACTIVE_SUSPENDED 0001 0010
TSK_STATE_ACTIVE_READY 0001 0100
TSK_STATE_ACTIVE_CRITSEC 0001 1000
TSK_STATE_WAITING 0110 0000
TSK_STATE_WAITING_MSGNG 0010 0000
TSK_STATE_WAITING_MSGRCV 0010 0001
TSK_STATE_WAITING_MSGSND 0010 0010
TSK_STATE_WAITING_SYNC 0100 0000
TSK_STATE_WAITING_TMR 0100 0001
TSK_STATE_WAITING_EVT 0100 0010
TSK_STATE_WAITING_SEM 0100 0100
TSK_STATE_WAITING_MNTR 0100 1000
TSK_STATE_UNINIT 1000 0000
TSK_STATE_UNINIT_UNINIT 1000 0001
TSK_STATE_UNINIT_FAILED 1000 0010
TSK_STATE_UNINIT_ENDED 1000 1000
Enumerator
TSK_STATE_ERROR 

Error state.

TSK_STATE_ACTIVE 

Active task states.

TSK_STATE_ACTIVE_RUNNING 

Task is currently running.

TSK_STATE_ACTIVE_SUSPENDED 

Task was preempted, hence it is suspended.

TSK_STATE_ACTIVE_READY 

Task is ready to be run.

TSK_STATE_ACTIVE_CRITSEC 

Task is running in a critical section.

TSK_STATE_WAITING_MSGNG 

Task messaging waiting states.

TSK_STATE_WAITING_MSGRCV 

Task is waiting for a message to be published.

TSK_STATE_WAITING_MSGSND 

Task is waiting for its message to be received.

TSK_STATE_WAITING_SYNC 

Task synchronization waiting states.

TSK_STATE_WAITING_TMR 

Task is waiting for a timer.

TSK_STATE_WAITING_EVT 

Task is waiting for an event.

TSK_STATE_WAITING_SEM_BIN 

Task is waiting for a binary semaphore.

TSK_STATE_WAITING_SEM_CNT 

Task is waiting for a coutning semaphore.

TSK_STATE_WAITING_MTX 

Task is waiting for a mutex.

TSK_STATE_WAITING_MNTR 

Task is waiting for a monitor.

TSK_STATE_WAITING 

Common task waiting states.

TSK_STATE_UNINIT 

Task is uninitialized.

TSK_STATE_UNINIT_UNINIT 

Task has not yet been initialized.

TSK_STATE_UNINIT_FAILED 

Task is uninitialized due to a system failure.

TSK_STATE_UNINIT_ENDED 

Task is uninitialized, because it finished its execution.

Function Documentation

RetCode os_IDLETskInit ( const TskStartAddr const  strtAddr)

Creates the IDLE Task.

Parameters
[in]strtAddrAddress of the IDLE Task's function
Returns
RetCode Return the success of the operation

Create the IDLE Task and provide its tskTCB with information.

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 tsk_ChngePrio ( PTskTCB const  tsk,
const TskPrio  newTskPrio 
)
Parameters
[in]tskPointer to the TskTCB of the task to change the priority of
[in]newTskPrioTskPrio to set the task to
Returns
RetCode
RET_OK
RET_NOK
RetCode tsk_ClrEvt ( PTskTCB const  tsk,
PSyncEle const  syncEle 
)

Clear the event that currently blocks the task.

Parameters
[in]tskPointer to the TskTCB to clear the event for
[in]syncElePointer to the SyncEle set up for the event
Returns
RetCode
RET_OK
RET_NOK
Precondition
Task must be inactive and blocked by the event specified by syncEle.
Postcondition
Task is put into the active task list.
RetCode tsk_SetEvt ( PTskTCB const  tsk,
PSyncEle const  syncEle 
)

Set the event described by syncEle for the specified task.

Parameters
[in]tskPointer to the TskTCB to set the event for
[in]syncElePointer to the SyncEle set up for the event
Returns
RetCode
RET_OK
RET_NOK
Precondition
Task must be active and in the active task list.
Postcondition
Task is set inactive and taken out of the active task list.
RetCode tsk_SetInactive ( PTskTCB const  tsk,
TskState  tskInactvState 
)

Set the specified task inactive, remove from active wait queue and set the specified new task state.

Parameters
[in]tskPointer to the TskTCB to set inactive
[in]tskInactvStateState to set the task to
Returns
RetCode
RET_OK
RET_NOK
RetCode tsk_tskDestroy ( TskTCB *const  tsk)

Destroy the given task.

Parameters
[in]tskPointer to the TskTCB of the task to be destroyed
Returns
RetCode Return the success of the operation

Release all resources used by the task and delete it from the queue.

This does not trigger the scheduler!

RetCode tsk_tskInit ( const TskID  tskID,
const TskStartAddr const  strtAddr,
const TskEndAddr const  endAddr,
const StackSize  stkSze 
)

Creates a task according to the provided input parameters.

Parameters
[in]tskIDTskID of the task to be created
[in]strtAddrAddress of the task's function
[in]endAddrOptional address of a function to which the task shall return to after its execution (provide NULL for default behavior)
[in]stkSzedesired size of the task's stack
Returns
RetCode Return the success of the operation

Creates a task by allocating space for its tskTCB and filling it with the provided and computed informations. Also allocates the stack for the task.

Note
Task is not activated yet!

Variable Documentation

BitsOSFlags gOS_FLAGS

Flags used for maintaining the OS.

Contains various flags for the operation of the OS.

might be obsolete

TskTCB* p_cur_tsk_tcb

Pointer to currently running task's tskTCB.

To keep track of the currently running task this pointer stores it. Is set to NULL when the currently running task is ended/killed, which is then acknowledged by the context switch (No saving of the current task's context).

Initialized to NULL

pIDLETsk

Constant pointer to the IDLE Task's tskTCB.

Since the IDLE Task is not allocated dynamically its location in the memory will not change during runtime. This Pointer is used to always reference the IDLE Task and thus the start of the list containing all tasks in the System.

Initialized to the address of the IDLE Task's tskTCB.

PTskTCB const pIDLETsk = &( tsk_AR[0] )

Constant pointer to the IDLE Task's tskTCB.

Since the IDLE Task is not allocated dynamically its location in the memory will not change during runtime. This Pointer is used to always reference the IDLE Task and thus the start of the list containing all tasks in the System.

Initialized to the address of the IDLE Task's tskTCB.