35/317
2 - How does a typical microcontroller work?
Thus it is up to the programmer to save it, by pushing it to the stack at the beginning of the
service routine, and popping it before executing the IRET statement.
2.5.2.2 Managing the stack
This is just a reminder, since it applies anywhere in the program. The service routine must
track the usage it makes of the stack, so as to pop at the end as many bytes as it had pushed
at the beginning. This may look trivial, but if some pushes occur in some conditions and not
others (i.e. the service routine has conditional statements somewhere), the popping must
occur in exactly the reverse way, taking into account the same conditions as those that pro-
duced the pushing. This may not be very obvious to code.
2.5.2.3 Resetting the hardware interrupt request flags
In some peripherals, the hardware flag that produced the interrupt request is automatically
cleared on servicing the interrupt. In this case, no special care need be taken.
On the contrary, in some other peripherals (such as the timer), the interrupt request flag keeps
its state after the interrupt is granted. This flag must be cleared anywhere in the interrupt
service routine, but necessarily before the I bit of the Condition Code Register is cleared (on
execution of the IRET instruction). Otherwise, the interrupt service routine would be called
again immediately after executing the IRET instruction, and the core would loop indefinitely
through this interrupt service routine, thus blocking the main program.
How to reset the interrupt request flag is described as part of the description of each periph-
eral.
2.5.2.4 Making an interrupt service routine interruptible
On interrupt granting, the I bit of the Condition Code Register is set, to prevent the service rou-
tine being interrupted by incoming interrupt requests. Further interrupt requests will then suffer
from a delay before they are serviced. This delay is called «interrupt latency». Actually this
term includes the reaction time of the core itself, to which the time for the servicing in progress
must be added.
However, there are cases where it is necessary to allow an interrupt service routine to be itself
interrupted. This is the case if a service routine performs processing that takes a certain
amount of time, and another interrupt source requires that its request be processed immedi-
ately, i.e. the permitted latency is short.
The solution is then to allow the slow service routine to be interrupted. This may be done by re-
setting the I bit of the Condition Code Register. This must be done after the hardware interrupt
request flag that triggered the interrupt currently in progress is cleared, for the same reason as
explained above. Please note, however, that this must only be done when necessary, since
the size of the stack is often limited in small microcontrollers.
Содержание 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 ...