A simple cooperative task scheduler with prioritized tasks.
More...
|
| Task Profiler |
| A utility module that measures execution times of tasks.
|
|
| Status Codes |
| Status Codes Definitions for the Task Scheduler.
|
|
A simple cooperative task scheduler with prioritized tasks.
A simple cooperative task scheduler with prioritized tasks.
◆ SCHEDULER_MAX_TASKS
#define SCHEDULER_MAX_TASKS 8U |
Maximum Number of tasks.
- Warning
- Maximum number is 32 due to internal data structures of size uint32. If larger number of tasks are desired, the internal data structures need to be adjusted.
◆ task_event_t
Task event type definition.
◆ task_function_t
Task functions definition.
- Parameters
-
e | Task event pointer. An abstract pointer to an task intern data structure. |
◆ task_prio_t
Definition of the task priority (and unique task ID).
Higher values mean higher urgency. Priority 0 can be used for IDLE task.
◆ Scheduler_AddTask()
Adds an new task to the scheduler.
- Parameters
-
me | The instance handle of the task scheduler. |
task | A pointer to the task function to be executed. |
priority | The priority level for the task. Every priority level can only have one task! |
eventQ | A pointer to the task event queue. |
eventQSize | The size of the task event queue. |
name | A descriptive name of the task. |
- Returns
- Returns the status (STATUS_OK on success).
◆ Scheduler_Init()
scheduler_t * Scheduler_Init |
( |
void |
| ) |
|
Initializes the task scheduler.
Resets internal data structures to a known state.
- Returns
- Returns the abstract pointer to the scheduler handle object.
◆ Scheduler_IsTaskPending()
bool Scheduler_IsTaskPending |
( |
scheduler_t *const |
me, |
|
|
task_prio_t |
priority |
|
) |
| |
Checks whether a specified task is pending for execution.
- Parameters
-
me | The instance handle of the task scheduler. |
priority | The priority of the task to be checked. |
- Returns
- Returns true if the task is pending, false otherwise.
◆ Scheduler_PostEvent()
Posts an event to the scheduler and executes it as soon as possible.
- Parameters
-
me | The instance handle of the task scheduler. |
priority | The priority of the task to be executed. |
event | A void* pointer to and task event parameter. |
- Returns
- Returns the status (STATUS_OK on success).
◆ Scheduler_Run()
void Scheduler_Run |
( |
scheduler_t *const |
me | ) |
|
Runs the task scheduler.
This is the main routine for the scheduler module. It schedules all the pending tasks in order of priority in an endless loop. If an error occurs within an task, the error is logged, but not handled!
- Parameters
-
me | The instance handle of the task scheduler. |
◆ Scheduler_SwitchContext()
void Scheduler_SwitchContext |
( |
scheduler_t *const |
me | ) |
|
Suspends the current task and runs another task.
The function can be called from within a task in order to suspend the current task and run other task (to completion). The function return when the other task is finished. The function runs exactly one other task, even if more are pending. The function can be called another time to run another task. If no tasks are pending, the function does nothing.
- Note
- This function never returns!
- Parameters
-
me | The instance handle of the task scheduler. |