![]() |
Task scheduler library
1.0
Arduino library for simply executing tasks in parallel
|
#include "Tasks.h"
Go to the source code of this file.
Functions | |
void | Tasks_Init (void) |
Initialize timer and reset the tasks scheduler at first call. More... | |
void | Tasks_Clear (void) |
Reset the tasks schedulder. More... | |
bool | Tasks_Add (Task func, int16_t period, int16_t delay) |
Add a task to the task scheduler. More... | |
bool | Tasks_Remove (Task func) |
Remove a task from the task scheduler. More... | |
bool | Tasks_Delay (Task func, int16_t delay) |
Delay execution of a task. More... | |
bool | Tasks_SetState (Task func, bool state) |
Enable or disable the execution of a task. More... | |
void | Tasks_Start (void) |
Start the task scheduler. More... | |
void | Tasks_Pause (void) |
Pause the task scheduler. More... | |
Library providing a simple task scheduler for multitasking.
For more details please refer to Tasks.h
Definition in file Tasks.cpp.
bool Tasks_Add | ( | Task | func, |
int16_t | period, | ||
int16_t | delay = 0 |
||
) |
Add a task to the task scheduler.
A new task is added to the scheduler with a given execution period and delay until first execution.
If no delay is given the task is executed at once or after starting the task scheduler (see Tasks_Start())
If a period of 0ms is given, the task is executed only once and then removed automatically.
To avoid ambiguities, a function can only be added once to the scheduler. Trying to add it a second time will reset and overwrite the settings of the existing task.
For non-static member function use address from PTR_NON_STATIC_METHOD() macro.
Used HW blocks:
- Arduino ATMega: TIMER0_COMPA_vect
- Arduino SAM: TC3
[in] | func | Function to be executed. The function prototype should be similar to this: "void userFunction(void)" |
[in] | period | Execution period of the task in ms (0 to 32767) |
[in] | delay | Delay until first execution of task in ms (0 to 32767) |
MAX_TASK_CNT
in file Tasks.h
void Tasks_Clear | ( | void | ) |
bool Tasks_Delay | ( | Task | func, |
int16_t | delay | ||
) |
Delay execution of a task.
The task is delayed starting from the last 1ms timer tick which means the delay time is accurate to -1ms to 0ms.
This overwrites any previously set delay setting for this task and thus even allows earlier execution of a task. Delaying the task by <2ms forces it to be executed during the next 1ms timer tick. This means that the task might be called at any time anyway in case it was added multiple times to the task scheduler.
For non-static member function use address from PTR_NON_STATIC_METHOD() macro.
Used HW blocks:
- Arduino ATMega: TIMER0_COMPA_vect
- Arduino SAM: TC3
[in] | func | Function that should be delayed |
[in] | delay | Delay in ms (0 to 32767) |
void Tasks_Init | ( | void | ) |
void Tasks_Pause | ( | void | ) |
bool Tasks_Remove | ( | Task | func | ) |
Remove a task from the task scheduler.
Remove the specified task from the scheduler and free the slot again.
For non-static member function use address from PTR_NON_STATIC_METHOD() macro.
Used HW blocks:
- Arduino ATMega: TIMER0_COMPA_vect
- Arduino SAM: TC3
[in] | func | Function name that should be removed. |
bool Tasks_SetState | ( | Task | func, |
bool | state | ||
) |
Enable or disable the execution of a task.
Temporary pause or resume function for execution of single tasks by scheduler. This will not stop the task in case it is currently being executed but just prevents the task from being executed again in case its state is set to 'false' (inactive).
For non-static member function use address from PTR_NON_STATIC_METHOD() macro.
Used HW blocks:
- Arduino ATMega: TIMER0_COMPA_vect
- Arduino SAM: TC3
[in] | func | Function to be paused/resumed. The function prototype should be similar to this: "void userFunction(void)" |
[in] | state | New function state (false=pause, true=resume) |