Comtrol eCos User Manual

Page 89

Advertising
background image

Interrupt Handling

Interrupts may currently be disabled globally, especially if the hardware does not support interrupt priorities.
Alternatively interrupts may be enabled such that higher priority interrupts are allowed through. The ISR may
be running on a separate interrupt stack, or on the stack of whichever thread was running at the time the
interrupt happened.

A typical ISR will do as little work as possible, just enough to meet the needs of the hardware and then
acknowledge the interrupt by calling

cyg_interrupt_acknowledge

. This ensures that interrupts will be

quickly reenabled, so higher priority devices can be serviced. For some applications there may be one device
which is especially important and whose ISR can take much longer than normal. However eCos device drivers
usually will not assume that they are especially important, so their ISRs will be as short as possible.

The return value of an ISR is normally one of

CYG_ISR_CALL_DSR

or

CYG_ISR_HANDLED

. The former indi-

cates that further processing is required at DSR level, and the interrupt handler’s DSR will be run as soon as
possible. The latter indicates that the interrupt has been fully handled and no further effort is required.

An ISR is allowed to make very few kernel calls. It can manipulate the interrupt mask, and on SMP systems
it can use spinlocks. However an ISR must not make higher-level kernel calls such as posting to a semaphore,
instead any such calls must be made from the DSR. This avoids having to disable interrupts throughout the
kernel and thus improves interrupt latency.

cyg_DSR_t

dsr

If an interrupt has occurred and the ISR has returned a value

CYG_ISR_CALL_DSR

, the system will call the

deferred service routine or DSR associated with this interrupt handler. If the scheduler is not currently locked
then the DSR will run immediately. However if the interrupted thread was in the middle of a kernel call and
had locked the scheduler, then the DSR will be deferred until the scheduler is again unlocked. This allows the
DSR to make certain kernel calls safely, for example posting to a semaphore or signalling a condition variable.
A DSR is a C function which takes the following form:

void

dsr_function(cyg_vector_t vector,

cyg_ucount32 count,

cyg_addrword_t data)

{

}

The first argument identifies the specific interrupt that has caused the DSR to run. The second argument
indicates the number of these interrupts that have occurred and for which the ISR requested a DSR. Usually
this will be

1

, unless the system is suffering from a very heavy load. The third argument is the

data

field

passed to

cyg_interrupt_create

.

cyg_handle_t*

handle

The kernel will return a handle to the newly created interrupt handler via this argument. Subsequent operations
on the interrupt handler such as attaching it to the interrupt source will use this handle.

cyg_interrupt*

intr

This provides the kernel with an area of memory for holding this interrupt handler and associated data.

89

Advertising