AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
Loading...
Searching...
No Matches

A simple cooperative task scheduler with prioritized tasks. More...

Collaboration diagram for Task Scheduler:

Modules

 Task Profiler
 A utility module that measures execution times of tasks.
 
 Status Codes
 Status Codes Definitions for the Task Scheduler.
 

Macros

#define SCHEDULER_MAX_TASKS   8U
 Maximum Number of tasks.
 

Typedefs

typedef uint8_t task_prio_t
 Definition of the task priority (and unique task ID).
 
typedef void * task_event_t
 Task event type definition.
 
typedef void(* task_function_t) (task_event_t e)
 Task functions definition.
 

Functions

scheduler_t * Scheduler_Init (void)
 Initializes the task scheduler.
 
void Scheduler_Run (scheduler_t *const me)
 Runs the task scheduler.
 
void Scheduler_SwitchContext (scheduler_t *const me)
 Suspends the current task and runs another task.
 
status_t Scheduler_AddTask (scheduler_t *const me, task_function_t task, task_prio_t priority, task_event_t eventQ, size_t eventQSize, const char *name)
 Adds an new task to the scheduler.
 
status_t Scheduler_PostEvent (scheduler_t *const me, task_prio_t priority, task_event_t event)
 Posts an event to the scheduler and executes it as soon as possible.
 
bool Scheduler_IsTaskPending (scheduler_t *const me, task_prio_t priority)
 Checks whether a specified task is pending for execution.
 

Detailed Description

A simple cooperative task scheduler with prioritized tasks.


A simple cooperative task scheduler with prioritized tasks.

Macro Definition Documentation

◆ 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.

Typedef Documentation

◆ task_event_t

typedef void* task_event_t

Task event type definition.


◆ task_function_t

typedef void(* task_function_t) (task_event_t e)

Task functions definition.


Parameters
eTask event pointer. An abstract pointer to an task intern data structure.

◆ task_prio_t

typedef uint8_t 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.

Function Documentation

◆ Scheduler_AddTask()

status_t Scheduler_AddTask ( scheduler_t *const  me,
task_function_t  task,
task_prio_t  priority,
task_event_t  eventQ,
size_t  eventQSize,
const char *  name 
)

Adds an new task to the scheduler.


Parameters
meThe instance handle of the task scheduler.
taskA pointer to the task function to be executed.
priorityThe priority level for the task. Every priority level can only have one task!
eventQA pointer to the task event queue.
eventQSizeThe size of the task event queue.
nameA 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
meThe instance handle of the task scheduler.
priorityThe priority of the task to be checked.
Returns
Returns true if the task is pending, false otherwise.

◆ Scheduler_PostEvent()

status_t Scheduler_PostEvent ( scheduler_t *const  me,
task_prio_t  priority,
task_event_t  event 
)

Posts an event to the scheduler and executes it as soon as possible.


Parameters
meThe instance handle of the task scheduler.
priorityThe priority of the task to be executed.
eventA 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
meThe 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
meThe instance handle of the task scheduler.