Picture
+-Kernel----------------------------------+
| |
| +-Process-+ +-Process-+ +-Process-+ |
| | | | | | | |
| | Thread | | Thread | | Thread | |
| | Thread | | | | | |
| | | | | | | |
| +---------+ +---------+ +---------+ |
| |
+-----------------------------------------+
PENDED <----> READY/EXEC. <-----> DELAYED
^ ^ |
| | |
v v v
PENDED & -----> SUSPENDED <------ DELAYED &
SUSPENDED SUSPENDED
PTASK pFunc[MAX_TASK]; // ptr to routine to run
UCHAR currentTask = -1; // initialize list of tasks to run
pFunc[0] = MyFirstTask;
pFunc[1] = My2ndTask;
pFunc[2] = ...
while(TRUE) { // forever loop
if (++currentTask >= MAX_TASK) {
currentTask = 0;
}
if (pFunc[currentTask] != NULL) { // call the next task
pFunc[currentTask]();
}
}
Background
PTASK pFunc[MAX_TASK]; // ptr to routine to run
while(TRUE) { // forever
if (++currentTask >= MAX_TASK) {
currentTask = 0;
}
if (pFunc[currentTask] != NULL) { // call the next task
pFunc[currentTask]();
}
}
Foreground
PISR IDT[MAX_ISR];
InterruptA() {
...
}
InterruptB() {
...
}
Background
struct { PFUNC pFunc; // function to run
PTASK pNext; // ptr to next task
} TASK, *PTASK;
PTASK pHead = NULL; // start list
PTASK pNext = NULL; // next task
while(TRUE) { // forever
if (pNext == NULL)
pNext = pHead; // call the next task
if (pNext != NULL) {
pNext->pFunc();
pNext = pNext->pNext
}
}
Foreground
PISR IDT[MAX_ISR];
InterruptA() {
...
AddTask(pMytask)
}
InterruptB() {
...
}
AddTask(PTASK pFunc) {
// walk list from head insert pFunc at position in list depending on priority
}