circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

December 1998, Issue 101

A Minimalist Multitasking Executive


by Richard Man & Christina Willrich
Start Task Function Scheduling and Timeslice Task Context Task Control Block Global Variables Memory Management API Assembly Functions Give it a Try Enhancements References, Sources & PDF

TASK CONTROL BLOCK

The data structure TaskControlBlock (see Listing 3) describes a task. µexec keeps all tasks in a circular linked list and a global variable keeps track of the current task.

To choose the next task to run, µexec follows the next pointer field of the current task and sets the current-task variable accordingly. To ensure that there is always at least one task to run, the system creates a null task. It calls UEXC_Defer in an infinite loop, enabling other tasks to run. If no other task is there, the system runs this null task indefinitely.

A task is identified by its task ID, which is kept in the tid field. ticks is the number of ticks that the task should execute before scheduling occurs (i.e., its timeslice value). current_ ticks is the number of ticks left in the execution of this task.

func is the pointer to the C function for the task. The stack start and end values are for debugging purposes, such as detecting stack overrun. sp is the current value of the stack pointer. It must be within the range of the start and end stack values.