208/317
7 - Debugger and PROM Programmer Tutorial for ST72251
7.6.3.2 The
Yield
routine
A call to this routine must be inserted in the code of each task, at least once within the main
loop. As many calls to
Yield
as you wish may be inserted in each task. W hen this function is
executed, the current task is suspended and control is passed to the next task in the order
they have been declared. This task will in turn call
Yield
some time later, and the following
task will be activated; and so on, until all other tasks have been executed once for a segment
of code included between two calls to
Yield
. Then, the first task will continue.
The mechanism is the following: calling
Yield
has automatically pushed, on the stack that be-
longs to the current task, the address of the instruction that follows the call to
Yield
. The value
of the stack pointer is then stored in the element of the
ImStack
table that corresponds to the
current task, whose number is kept in
Permut
. Now, all the information on the state of the task
we leave is saved.
Permut
is incremented, or, if at the number of the last task, it is cleared. The
contents of the element of the
ImStack
table that corresponds to the new value of
Permut
are
then copied to the stack pointer. The stack pointer now points to the next task's own stack, and
to the return address from
Yield
that was pushed when this task called
Yield
the last time it
was active. The
Yield
routine then executes its final
ret
instruction; but instead of returning
to the place where it was just called, it returns to the most recent active task.
This process seems confusing; you must mentally follow what is going on in each of the tasks.
Let us put things another way:
From each task's point of view, the
Yield
function is a function that does nothing but insert an
unpredictable delay in the execution. Each task sees
Yield
the same way, and all of them
think they are the only one executing on the microcontroller.
Содержание 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 ...