42/317
2 - How does a typical microcontroller work?
2.6.3 Multitasking kernels
2.6.3.1 Advantages of programming with a multitasking kernel
The multitasking kernel is the piece of code that controls the multitasking. The way it does it,
and the flexibility it offers may vary greatly from one kernel to the other. It is generally supplied
ready made, and the programmer has to give his program the appropriate architecture to get
the benefits of it.
Writing an application with multitasking in mind is easy and leads to a clear, organized struc-
ture. The work to do is divided in tasks, and these tasks are written separately as procedures.
They exchange data using either communication mechanisms built-in to the kernel, or
common data in memory, taking care to avoid collisions. The main difficulty is to identify what
a task actually is. For example, two processings that are always performed one after the other,
and always in the same order, constitute a single task. On the contrary, two processings that
either may or must be performed at the same time are two separate tasks.
The features of a kernel vary from product to product. One must first know which kernel is
being used, the type of multitasking (pre-emptive or cooperative), and the services provided
by the kernel. Some of these are discussed below.
2.6.3.2 The task declaration and allocation
The kernel must be aware of the existence of the tasks, their number and their start ad-
dresses. Some kernels expect this to be stated at compile time; in this case, the number of
tasks is known from the beginning of program execution and cannot change afterwards.
Some others allow tasks to be added (or created) while the program is running. This allows
tasks to be created when the need shows up, for example to process an incoming event and
then terminate. In this case, it is convenient to also have the ability to remove or kill the task.
Again, there are two options: a task may terminate when it decides to do so (kill itself or “sui-
cide”); or it may be killed by any task, including itself.
2.6.3.3 Task sleeping and waking-up
A task may be alive but have nothing to do; in this case, to save computing power, it is wise to
completely stop allocating core time to it. The task is then asleep. This can be done by calling
a function often called Sleep, passing to it the identification of the task to be put asleep. A task
can put itself asleep if it is waiting for some event.
Obviously, it is necessary to have a means of waking-up a sleeping task. This cannot of
course be done by the sleeping task itself, and can only be done either by other tasks or by an
interrupt service routine. For example, let us consider a task that processes the keystrokes
generated by a keypad. The hardware of the keypad may generate an interrupt when a key is
pressed. This interrupt may wake-up the keypad task that reads the keycode and takes the
appropriate action. When this is done, the task may go asleep again. One might ask why it is
Содержание ST7 Series
Страница 1: ...ST7 8 BIT MCU FAMILY USER GUIDE JANUARY 1999 1 ...
Страница 238: ...238 317 8 C Language and the C Compiler 08 Burn bmp Then use the EPROMer programmer software as described in Chapter 7 ...
Страница 289: ...289 317 10 Second Application a Sailing Computer 10 befor Bs Rw Vw VMG AlphaR AlphaV Before the wind ...