Data Structures | |
struct | TaskEntry_t |
Defines | |
#define | TASK(name) void name (void) |
#define | TASK_LIST TaskEntry_t Scheduler_TaskList[] = |
#define | TASK_MAX_DELAY (MAX_DELAYCTR_COUNT - 1) |
#define | TASK_RUN true |
#define | TASK_STOP false |
Typedefs | |
typedef void(* | TaskPtr_t )(void) |
typedef uint16_t | SchedulerDelayCounter_t |
Functions | |
void | Scheduler_Start (void) |
void | Scheduler_Init (void) |
static void | Scheduler_ResetDelay (SchedulerDelayCounter_t *const DelayCounter) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE |
bool | Scheduler_HasDelayElapsed (const uint16_t Delay, SchedulerDelayCounter_t *const DelayCounter) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(2) |
void | Scheduler_SetTaskMode (const TaskPtr_t Task, const bool TaskStatus) |
void | Scheduler_SetGroupTaskMode (const uint8_t GroupID, const bool TaskStatus) |
Variables | |
TaskEntry_t | Scheduler_TaskList [] |
volatile uint8_t | Scheduler_TotalTasks |
volatile SchedulerDelayCounter_t | Scheduler_TickCounter |
For a task to yield it must return, thus each task should have persistent data marked with the static attribute.
Usage Example:
#include <LUFA/Scheduler/Scheduler.h> TASK(MyTask1); TASK(MyTask2); TASK_LIST { { .Task = MyTask1, .TaskStatus = TASK_RUN, .GroupID = 1 }, { .Task = MyTask2, .TaskStatus = TASK_RUN, .GroupID = 1 }, } int main(void) { Scheduler_Start(); } TASK(MyTask1) { // Implementation Here } TASK(MyTask2) { // Implementation Here }
#define TASK | ( | name | ) | void name (void) |
#define TASK_LIST TaskEntry_t Scheduler_TaskList[] = |
Defines a task list array, containing one or more task entries of the type TaskEntry_t. Each task list should be encased in curly braces and ended with a comma.
Usage Example:
#define TASK_MAX_DELAY (MAX_DELAYCTR_COUNT - 1) |
Constant, giving the maximum delay in scheduler ticks which can be stored in a variable of type SchedulerDelayCounter_t.
#define TASK_RUN true |
Task status mode constant, for passing to Scheduler_SetTaskMode() or Scheduler_SetGroupTaskMode().
#define TASK_STOP false |
Task status mode constant, for passing to Scheduler_SetTaskMode() or Scheduler_SetGroupTaskMode().
typedef uint16_t SchedulerDelayCounter_t |
Type define for a variable which can hold a tick delay value for the scheduler up to the maximum delay possible.
typedef void(* TaskPtr_t)(void) |
Type define for a pointer to a scheduler task.
bool Scheduler_HasDelayElapsed | ( | const uint16_t | Delay, | |
SchedulerDelayCounter_t *const | DelayCounter | |||
) |
Determines if the given tick delay has elapsed, based on the given .
[in] | Delay | The delay to test for, measured in ticks |
[in] | DelayCounter | The counter which is storing the starting tick value for the delay |
static SchedulerDelayCounter_t DelayCounter = 10000; // Force immediate run on start-up // Task runs every 10000 ticks, 10 seconds for this demo if (Scheduler_HasDelayElapsed(10000, &DelayCounter)) { // Code to execute after delay interval elapsed here }
void Scheduler_Init | ( | void | ) |
Initializes the scheduler so that the scheduler functions can be called before the scheduler itself is started. This must be executed before any scheduler function calls other than Scheduler_Start(), and can be omitted if no such functions could be called before the scheduler is started.
static void Scheduler_ResetDelay | ( | SchedulerDelayCounter_t *const | DelayCounter | ) | [inline, static] |
Resets the delay counter value to the current tick count. This should be called to reset the period for a delay in a task which is dependant on the current tick value.
[out] | DelayCounter | Counter which is storing the starting tick count for a given delay. |
void Scheduler_SetGroupTaskMode | ( | const uint8_t | GroupID, | |
const bool | TaskStatus | |||
) |
Sets the task mode for a given task group ID, allowing for an entire group of tasks to have their statuses changed at once.
[in] | GroupID | Value of the task group ID whose status is to be changed |
[in] | TaskStatus | New task status for tasks in the specified group (TASK_RUN or TASK_STOP) |
void Scheduler_SetTaskMode | ( | const TaskPtr_t | Task, | |
const bool | TaskStatus | |||
) |
Sets the task mode for a given task.
[in] | Task | Name of the task whose status is to be changed |
[in] | TaskStatus | New task status for the task (TASK_RUN or TASK_STOP) |
void Scheduler_Start | ( | void | ) |
Starts the scheduler in its infinite loop, executing running tasks. This should be placed at the end of the user application's main() function, as it can never return to the calling function.
Task entry list, containing the scheduler tasks, task statuses and group IDs. Each entry is of type TaskEntry_t and can be manipulated as desired, although it is preferential that the proper Scheduler functions should be used instead of direct manipulation.
Contains the current scheduler tick count, for use with the delay functions. If the delay functions are used in the user code, this should be incremented each tick period so that the delays can be calculated.
volatile uint8_t Scheduler_TotalTasks |
Contains the total number of tasks in the task list, irrespective of if the task's status is set to TASK_RUN or TASK_STOP.