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... | |
TskTCB * | p_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... | |
Functions for creating, maintaining and handling tasks.
#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.
#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
#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.
#define TSK_PRIO_LEVELS_NR ((uint8_t)0xFu) |
Number of available priority levels in the system.
#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.
typedef struct advTskPrio_struc AdvTskPrio |
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.
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 |
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.
enum tskPrio |
Task priority level.
enum tskSettings |
Settings of a task...
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 |
RetCode os_IDLETskInit | ( | const TskStartAddr const | strtAddr | ) |
Creates the IDLE Task.
[in] | strtAddr | Address of the IDLE Task's function |
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.
Clear the event that currently blocks the task.
[in] | tsk | Pointer to the TskTCB to clear the event for |
[in] | syncEle | Pointer to the SyncEle set up for the event |
Set the event described by syncEle for the specified task.
[in] | tsk | Pointer to the TskTCB to set the event for |
[in] | syncEle | Pointer to the SyncEle set up for the event |
Set the specified task inactive, remove from active wait queue and set the specified new task state.
[in] | tsk | Pointer to the TskTCB to set inactive |
[in] | tskInactvState | State to set the task to |
Destroy the given task.
[in] | tsk | Pointer to the TskTCB of the task to be destroyed |
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.
[in] | tskID | TskID of the task to be created |
[in] | strtAddr | Address of the task's function |
[in] | endAddr | Optional address of a function to which the task shall return to after its execution (provide NULL for default behavior) |
[in] | stkSze | desired size of the task's stack |
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.
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.