145
Chapter 2 Applications Programming
_mtsr(9,tmr);
if(tick++ > 100)
{
tick=0;
sig_sig=0x80000000 | timer_sig;
}
/* write to TMR register */
}
The
second stage
of the UART interrupt handler, the signal handler, is shown
below. Note, the
sig_uart()
routine calls the
printf()
library routine. This is not per-
mitted with the High C 29K library routines as the
printf()
routine is not reentrant.
However, the use of
printf()
helps illustrate the operating principle. Normally a sig-
nal handler must use the
_sigret()
signal return service, at least with a HIF conform-
ing operating system. However, when a signal handler is called from the dispatcher,
the signal return service should not be used. It is possible to determine if the dispatch-
er is in use by testing the variable
dispatcher_running
; it becomes non zero when
the dispatcher is in use. However, testing the
dispatcher_running
flag may be insuf-
ficient in some circumstances. It is possible that the Signal Dispatcher is running and
initiating signal handler execution. At the same time a signal handler may be re-
quested directly by, say, an interrupt. The Dispatcher is running but the directly re-
quested signal handler must use the signal return service.
Signals need not always be queued for processing. If a very high priority (im-
mediate) interrupt occurs and further signal processing is necessary,
sig_sig
should
be simply set to the signal number. In this case it is important that the signal handler
use the
_sigret()
service.
_Interrupt sig_uart(sig_number)
int
sig_number;
{
printf(”in signal handler number=%d\n”, sig_number);
printf(”received string=%s\n”, recv_data);
if(!dispatcher_running)_sigret(); /* no _sigret() service call *
}
/* signal handler for UART */
The Signal Dispatcher is implemented as a signal handler. The dispatcher re-
moves signals from a stack and calls the appropriate signal handler. When a signal
handler is requested by a Freeze mode handler, and the Signal Dispatcher is not cur-
rently executing, the requested signal (
sig_sig
value) is not immediately started. In its
place the dispatcher signal handler is initiated.
Shown on Figure 2-4 is an example of the Signal Dispatcher in operation. The
first interrupt is from the UART. It is dealt with entirely in Freeze mode; the
sig_sig
variable is not set such as to request a second stage signal handler. The UART gener-
ates the second interrupt. This time the
sig_sig
variable is set to request the
sig_uart()
signal handler be started by the Signal Dispatcher. While the second stage handler is
running, a timer interrupt occurs. The Freeze mode timer handler requests a second
stage handler be started by the Signal Dispatcher. When the dispatcher completes the
currently executing second stage handler (the UART’s), it initiates the timer’s second