| |||||
Technical Support On-Line Manuals RTX51 Tiny User's Guide | Round-Robin Task SwitchingRTX51 Tiny may be configured to use Round-Robin Multitasking (or task switching). Round-Robin allows quasi-parallel execution of several tasks. Tasks are not really executed concurrently but are time-sliced (the available CPU time is divided into time slices and RTX51 Tiny assigns a time slice to each task). Since the time slice is short (only a few milliseconds) it appears as though tasks execute simultaneously. Tasks execute for the duration of their time-slice (unless the task's time slice is given up). Then, RTX51 Tiny switches to the next task that is ready to run. The duration of a time slice may be defined by the RTX51 Tiny Configuration. The following example shows a simple RTX51 Tiny program that uses Round-Robin Multitasking. The two tasks in this program are counter loops. RTX51 Tiny starts executing task 0 which is the function named job0. This function creates another task called job1. After job0 executes for its time slice, RTX51 Tiny switches to job1. After job1 executes for its time slice, RTX51 Tiny switches back to job0. This process is repeated indefinitely.
#include <rtx51tny.h>
int counter0;
int counter1;
void job0 (void) _task_ 0 {
os_create (1); /* mark task 1 as ready */
while (1) { /* loop forever */
counter0++; /* update the counter */
}
}
void job1 (void) _task_ 1 {
while (1) { /* loop forever */
counter1++; /* update the counter */
}
}
Note
| ||||
| |||||