39/317
2 - How does a typical microcontroller work?
2.6 AN APPLICATION USING INTERRUPTS: A MULTITASKING KERNEL
The conclusion in the previous paragraph states that interrupts are well-suited for a certain
class of events to be processed. However, there are other cases outside this category. Some
of them are better addressed by the concept of multitasking.
In many applications, several processings are required that do not match the specificity of the
interrupt-driven processes. For example:
Two or more processes are continuously active, that each take long processing times.
These processes are not (or not directly) started by external events.
They do not require a quick reaction time.
In such cases, the interrupt concept is obviously inappropriate. Actually, these processes
seem to require each a core of their own. However, considerations of cost may not allow for
multiple microcontrollers on the same board. The concept of multitasking is the answer to this
requirement. It is a software solution that does not require extra components, and makes the
system believe the various tasks run on different cores, although it is simply the same core
that is shared between all the tasks at the expense of the computing power that is shared be-
tween this tasks, plus a certain waste produced by the specific mechanisms that provide for
the multitasking. This waste limits the frequency at which the tasks can be switched; if they are
switched too often, the proportion of the time taken to switch tasks becomes too large, and the
corresponding part of the microcontroller computing power is lost. The designer must check
whether the power remaining for each task is sufficient or not; if not, the type of microcontroller
is probably unsuitable for the project.
There are two kinds of multitasking, namely pre-emptive multitasking and non pre-emptive
multitasking. The second kind is also called cooperative multitasking.
2.6.1 Pre-emptive multitasking
Pre-emptive means that the computing power that is allocated to a task is withdrawn from it
without notice, that is, that particular task is stopped at an unexpected place by brute force.
Then, the power is allocated to another task, until it is stopped in turn, and so on for all the
tasks; then, the first task that is currently sleeping regains control and continues for some time.
The task switching is done under control of an interrupt triggered by a timer. This allows the
core time to be partitioned at will between the various tasks. The time for which each task is al-
lowed to run may be the same for all tasks; or it may be decided to allow more time for some
more important (or time-consuming) tasks, and less for others. In a word, the multitasking
kernel may fine-tune the resource sharing between the tasks.
The main drawback of this system is that since the tasks are interrupted at any place in the
code, many precautions must be taken to ensure the coherence of the data, just as explained
above about interrupts. In fact, if a task starts to write a piece of data and is put asleep in the
Содержание 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 ...