KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
scheduler.h File Reference

Simple task scheduler for tasks. More...

#include <stdbool.h>
#include <util/macro.h>

Go to the source code of this file.

Macros

#define TASK_ID_NONE   -1
 
#define E_SCHD_INVTASKID   ( E_SCHD + 0x01 )
 Invalid task ID.
 
#define E_SCHD_INVTASKID_DESCR   "Invalid task ID"
 

Typedefs

typedef void(* SchdTaskF )()
 Task function typedef. More...
 

Functions

bool schdRegister (SchdTaskF task, bool priority, int *taskId)
 Register a task with the scheduler. More...
 
void schdRunPeriodic (int taskId, int interval)
 Schedule a task to run periodically. More...
 
void schdStop (int taskId)
 Stop a scheduled task. More...
 
void schdRunDelay (int taskId, int interval)
 Schedule a task to run after a delay. More...
 
void schdRun (int taskId)
 Run a task 'now'. More...
 
void schdRunIRQ (int taskId)
 Schedule a task from an IRQ. More...
 
void schdSetEnable (int taskId, bool enabled)
 Enable of disable a task. More...
 
bool schdTasksPending ()
 Checks if there are any tasks pending. More...
 
bool schdAddIdleTask (SchdTaskF idleTask)
 Adds an idle task, the task which is executed when there is nothing else to do. More...
 
void schdRunForever ()
 Invoked in the main, starts the scheduler.
 

Detailed Description

Simple task scheduler for tasks.

Tasks are functions with no argument and no return value which will be invoked by the scheduler. Its a form of cooperative multitasking, so if a function does not return it will stall the entire system.

At the end the scheduler will be run by calling schdRunForever(). This is than the main-loop.

More information can be found in the tutorial Adding timed processes to the scheduler.

Definition in file scheduler.h.

Typedef Documentation

typedef void(* SchdTaskF)()

Task function typedef.

Just a simple function with no arguments and no return value.

Definition at line 47 of file scheduler.h.

Function Documentation

bool schdAddIdleTask ( SchdTaskF  idleTask)

Adds an idle task, the task which is executed when there is nothing else to do.

Note that idle tasks can not be removed.

Parameters
idleTaskThe idle task.
Return values
trueIdle task configured
falseIdle task not configured

Definition at line 135 of file scheduler.c.

bool schdRegister ( SchdTaskF  task,
bool  priority,
int *  taskId 
)

Register a task with the scheduler.

Parameters
taskThe function to invoke (e.g. void myFunc())
priorityWhether or not this is a high-priority function.
taskIdWill be filled in with the task identifier.
Return values
trueAll OK
falseNo can do, check errGet(). Most likely there is no more space left.

Definition at line 95 of file scheduler.c.

void schdRun ( int  taskId)

Run a task 'now'.

Well, not really now, but as soon as possible.

Note
Do not call this function form within an IRQ.
Parameters
taskIdThe task to run

Definition at line 233 of file scheduler.c.

void schdRunDelay ( int  taskId,
int  interval 
)

Schedule a task to run after a delay.

Parameters
taskIdThe task ID to run.
intervalThe delay in milliseconds.

Definition at line 201 of file scheduler.c.

void schdRunIRQ ( int  taskId)

Schedule a task from an IRQ.

Parameters
taskId

Definition at line 242 of file scheduler.c.

void schdRunPeriodic ( int  taskId,
int  interval 
)

Schedule a task to run periodically.

Parameters
taskIdThe task ID to run.
intervalThe interval in milliseconds.

Definition at line 212 of file scheduler.c.

void schdSetEnable ( int  taskId,
bool  enabled 
)

Enable of disable a task.

If a task is disabled, it won't run. Not periodically, not when schdRun is invoked.

Parameters
taskIdThe task to run
booltrue - Enable the task, false - disable the task.

Definition at line 248 of file scheduler.c.

void schdStop ( int  taskId)

Stop a scheduled task.

Parameters
taskIdThe task ID to run.

Definition at line 223 of file scheduler.c.

bool schdTasksPending ( )

Checks if there are any tasks pending.

Could be used if you wish to run for as long as there are no other tasks. Though this is not advised.

Return values
trueTasks are pending
falseTasks are not pending

Definition at line 260 of file scheduler.c.