176 Task *
const taskToInsert,
177 bool (*compareByProperty)(
const Task *
const ,
194 if (compareByProperty(task, taskToInsert)) {
229 if (
NULL != linkedListElement) {
324 bool setCurrentTaskReady =
false;
347 setCurrentTaskReady =
true;
357 setCurrentTaskReady =
true;
360 if (setCurrentTaskReady) {
392 void (*
const jumpToManager[__LZ_SCHEDULING_POLICY_ENUM_END])(void) =
428 bool (*
const comparers[__LZ_SCHEDULING_POLICY_ENUM_END])
430 const Task *
const) = {
435 if (taskConfiguration->
schedulingPolicy >= __LZ_SCHEDULING_POLICY_ENUM_END) {
445 if (
NULL == newTask) {
505 const bool isIdleTask)
510 size_t desiredStackSize;
512 if (
NULL == taskConfiguration) {
514 &defaultConfiguration,
516 taskConfiguration = &defaultConfiguration;
527 if (
NULL == newTask) {
531 desiredStackSize = taskConfiguration->
stackSize 538 if (
NULL == taskStack) {
543 newTask->
name = taskConfiguration->
name;
597 const uint8_t maxIndex =
sizeof(pointer) - 1;
598 const uint8_t *
const oldPointerPointer = (
const uint8_t *
const)&pointer;
599 void (*newPointer)(void);
603 for (i = 0; i <= maxIndex; ++i) {
604 newPointerPointer[maxIndex - i] = oldPointerPointer[i];
627 sizeof(linkedListInit));
748 if (
NULL == taskConfiguration) {
761 return RegisterTask(taskEntryPoint, taskConfiguration,
false);
781 return currentTask->
name;
void Scheduler_Init(void)
Initialize the scheduler prior to running it.
#define INT_TOTAL
Total interrupt codes used.
Task * Scheduler_GetCurrentTask(void)
Get a pointer to the current running task.
static void ManagePriorityRealTimeTask(void)
Manage priority real-time tasks.
char const * name
A pointer to an allocated const string containing the name to give to the task.
Cyclic real-time scheduling.
bool Lz_RegisterTask(void(*const taskEntryPoint)(void), Lz_TaskConfiguration *taskConfiguration)
Register a new task.
size_t stackSize
The stack size of the task.
#define INT_LAST_ENTRY
Alias for the last code used.
#define WAIT_INTERRUPT
Set the task to wait for an interrupt.
void Lz_Task_Terminate(void)
Terminate the calling task.
#define ALLOW_ARITHM(X)
Allow arithmetic on a void pointer.
volatile FuncVoidVoid pc
Program counter for the task.
static void IdleTask(void)
The scheduler idle task.
static Lz_LinkedList readyTasks[__LZ_SCHEDULING_POLICY_ENUM_END]
The queues of ready tasks for each scheduling policy.
#define TERMINATE_TASK
Terminate the task.
void Scheduler_HandleClockTick(void *const sp)
This function is called when a clock tick occured, catch by the interrupt handler.
Lz_LinkedListElement stateQueue
The scheduling queue on which the task is stored.
void * stackPointer
The saved stack pointer of the task.
const bool LZ_CONFIG_IDLE_TASK_HAS_NAME
Configure if the idle task must have a name.
Kernel symbols definition.
#define CONTAINER_OF(P, M, T)
Get a pointer to the structure T containing the member M pointed by P.
static Lz_LinkedList terminatedTasks
The queue of terminated tasks.
lz_u_resolution_unit_t period
The period (T) of the task.
static const Lz_TaskConfiguration DefaultTaskConfiguration
Contains default values for Lz_TaskConfiguration.
void Arch_EnableInterrupts(void)
Enable all interrupts.
const char * name
The name of the task.
void List_Prepend(Lz_LinkedList *const linkedList, Lz_LinkedListElement *const item)
Insert an Lz_LinkedListElement as the first element of an existing Lz_LinkedList. ...
const bool LZ_CONFIG_MODULE_MUTEX_USED
Use module "mutex": Mutexes implementation.
void Scheduler_SleepUntilEndOfTimeSlice(void)
Put the current task to sleep until the end of its time slice.
static bool RegisterIdleTask(void)
Register the idle task.
void Lz_WaitTimer(lz_u_resolution_unit_t units)
Set the calling task to wait for the specified number of time resolution units (time slices)...
const char * Lz_Task_GetName(void)
Get the name of the calling task.
#define UNUSED(X)
Tell the compiler that the variable X is left unsed.
void(* entryPoint)(void)
Entry point of execution of the task.
void Arch_RestoreContextAndReturnFromInterrupt(void *stackPointer)
Restore the context of a previously saved task, and run it by returning from interrupt.
Include appropriate config file.
const bool LZ_CONFIG_MODULE_CLOCK_24_USED
Use module "clock_24": Implement a 24-Hour clock in the kernel.
lz_task_priority_t priority
The task priority.
lz_u_resolution_unit_t completion
The completion time (C) of the task (worst case execution time), expressed as an integer number of ti...
lz_u_resolution_unit_t timeUntilCompletion
The number of time units until the task will complete its execution.
lz_u_resolution_unit_t completion
The completion time (C) of the task (worst case execution time).
void Arch_CpuSleep(void)
Put the CPU to sleep according to the sleep settings.
#define WAIT_MUTEX
Wait for a mutex to be unlocked.
#define ELEMENTS_COUNT(X)
Get the number of elements in a statically initialized array.
static Task * currentTask
A pointer to the current running task.
The public API of the Lazuli kernel.
static void InsertTaskByPriority(Lz_LinkedList *const list, Task *const taskToInsert, bool(*compareByProperty)(const Task *const, const Task *const))
Insert a task in a list, keeping priorities ordered.
Lazuli scheduler interface.
const bool LZ_CONFIG_CHECK_INTERRUPT_CODE_OVER_LAST_ENTRY
When 1, check if the interrupt code sent by the ASM interrupt handler to the base scheduler interrupt...
Lz_LinkedListElement * List_Remove(Lz_LinkedList *const linkedList, Lz_LinkedListElement *const itemToRemove)
Remove an element from an Lz_LinkedList.
size_t stackSize
The size of the stack needed by the task.
volatile lz_task_to_scheduler_message_t taskToSchedulerMessage
The message the task has to pass to the scheduler for the next scheduling operation (i...
const size_t LZ_CONFIG_DEFAULT_TASK_STACK_SIZE
Default stack size in bytes for a new task.
Macro aliases on compiler facilities.
static void PrepareTaskContext(Task *const task)
Prepare the first context of the task so it will be ready when switching context for the first time (...
static Task * idleTask
The idle task.
uint16_t lz_u_resolution_unit_t
Represents the type used for the system clock resolution unit, as an unsigned integer.
#define WAIT_SOFTWARE_TIMER
Set the task to wait for the specified number of time resolution units, using the software timer...
void * KIncrementalMalloc(const size_t size)
Allocate memory for kernel objects using incremental method.
enum Lz_SchedulingPolicy schedulingPolicy
The scheduling policy of the task.
Lz_LinkedList waitingTasks
The list of tasks waiting for that mutex.
void Lz_Task_WaitActivation(void)
Set the calling task to wait for its next activation.
24-Hour clock kernel interface.
lz_u_resolution_unit_t timeUntilTimerExpiration
The number of time units until the software timer expires for the task.
void Scheduler_AbortTask(void *const sp)
Call the appropriate scheduler to abort the curent running task.
Doubly linked lists interface.
static Task * PickTaskToRun(void)
Pick the task ready to run with the highest priority.
void * stackOrigin
The bottom of the allocated stack for the task.
void List_Append(Lz_LinkedList *const linkedList, Lz_LinkedListElement *const item)
Insert an Lz_LinkedListElement as the last element of an existing Lz_LinkedList.
void Kernel_Panic(void)
Kernel panic.
static void UpdateCyclicRealTimeTasks(void)
Update all registered cyclic RT tasks.
void Arch_LoadFromProgmem(const void *source, void *destination, const size_t size)
Copy bytes from program memory to RAM.
static void Schedule(void)
Elect the new current task.
void Memory_Copy(const void *source, void *destination, const size_t size)
Copy bytes from one location to another in main memory.
Interrupt codes of ATmega328P.
uint8_t bool
Boolean type.
Represents the main container for doubly linked elements.
unsigned char uint8_t
Represents a unsigned integer type with width of exactly 8 bits.
Represents the configuration of a task.
static void ManageCyclicRealTimeTask(void)
Manage cyclic real-time tasks.
enum Lz_SchedulingPolicy schedulingPolicy
The scheduling policy.
#define NULL
NULL pointer.
static Lz_LinkedList waitingActivationTasks
The queue of tasks waiting activation.
static bool PeriodComparer(const Task *const task1, const Task *const task2)
Compare the "period" property of 2 tasks.
Priority time sliced real-time scheduling.
static Task * CallbackRegisterUserTask(const Lz_TaskConfiguration *const taskConfiguration)
Callback of SchedulerOperations.registerTask() for registering a user task.
#define WAIT_ACTIVATION
Set the task to wait for its next activation.
void Lz_Run(void)
Run the scheduler.
void Scheduler_HandleInterrupt(const uint8_t interruptCode)
This function is called by arch-specific interrupt handling routine.
volatile FuncVoidVoid terminationCallback
Callback to the scheduler to manage task termination.
void Arch_InitSystemTimer(void)
Initialize the system timer.
lz_u_resolution_unit_t timeUntilActivation
The number of time units until the task will be activated.
void List_InsertBefore(Lz_LinkedList *const linkedList, Lz_LinkedListElement *const listItem, Lz_LinkedListElement *const itemToInsert)
Insert an element before another in a Lz_LinkedList.
lz_task_priority_t priority
The priority of task.
Basic type definitions and useful macros.
Architecture Abstraction API.
static bool RegisterTask(void(*const taskEntryPoint)(void), Lz_TaskConfiguration *taskConfiguration, const bool isIdleTask)
Register a new task.
static void UpdateTasksWaitingSoftwareTimer(void)
Update all tasks waiting for the expiration of a software timer.
void Clock24_Increment(void)
Increment the 24-Hour clock, taking into the account the resolution of the system clock...
const bool LZ_CONFIG_ON_IDLE_SLEEP
When 1, put the CPU to sleep when it's idle.
#define NO_MESSAGE
No message has to be passed to the scheduler.
static Lz_LinkedList abortedTasks
The queue of aborted tasks.
Represents an element of a doubly linked list.
static Task * CallbackRegisterIdleTask(void)
Callback of SchedulerOperations.registerTask() for registering the scheduler idle task...
void Scheduler_WakeupTasksWaitingMutex(Lz_Mutex *const mutex)
Wake up all tasks waiting for a mutex.
const size_t LZ_CONFIG_IDLE_TASK_STACK_SIZE
The stack size in bytes of the scheduler idle task.
static Lz_LinkedList waitingInterruptsTasks[INT_TOTAL]
The table of waiting queues for interrupts.
void(*)(void) ReverseBytesOfFunctionPointer(void(*const pointer)(void))
Reverse the bytes of a function pointer.
void Lz_TaskConfiguration_Init(Lz_TaskConfiguration *const taskConfiguration)
Initialize an Lz_TaskConfiguration with default values for all parameters.
Lz_LinkedListElement * List_PickFirst(Lz_LinkedList *const linkedList)
Return the first element of an existing linked list.
void Arch_StartSystemTimer(void)
Start the system timer.
void * taskToSchedulerMessageParameter
A parameter that can accompany a taskToSchedulerMessage.
#define List_RemovableForEach(LINKEDLIST, TYPE, ITEM, MEMBER, ITERATOR)
Run through an Lz_LinkedList like a for loop, with the ability of removing elements from the list whi...
#define LINKED_LIST_INIT
Define the initialization value for the type Lz_LinkedList.
#define List_ForEach(LINKEDLIST, TYPE, ITEM, MEMBER)
Run through an Lz_LinkedList like a for loop.
const char *const LZ_CONFIG_IDLE_TASK_NAME
The name of the idle task.
void Lz_Task_WaitInterrupt(uint8_t interruptCode)
Wait for a specific interrupt to occur.
lz_u_resolution_unit_t period
The period (T) of the task, expressed as an integer number of time units.
void List_InitLinkedListElement(Lz_LinkedListElement *const item)
Initialize an Lz_LinkedListElement.
static bool PriorityComparer(const Task *const task1, const Task *const task2)
Compare the "priority" property of 2 tasks.
Represents the layout of the stack when saving the context of a task.
static Lz_LinkedList waitingTimerTasks
The queue of tasks waiting for their software timer to reach expiration.