Synchronization levels – Comtrol eCos User Manual

Page 391

Advertising
background image

Chapter 18. Device Driver Interface to the Kernel

The second model is to defer device processing to the DSR. The ISR simply prevents further delivery of
interrupts by either programming the device, or by calling

cyg_drv_interrupt_mask()

. It must then call

cyg_drv_interrupt_acknowledge()

to allow other interrupts to be delivered and then request that its DSR be

called. When the DSR runs it does the majority of the device handling, optionally signals a condition variable to
wake a thread, and finishes by calling

cyg_drv_interrupt_unmask()

to re-allow device interrupts. Thread

level code uses

cyg_drv_dsr_lock()

to prevent DSRs running while it manipulates shared memory. The eCos

serial device drivers use this approach.

The third model is to defer device processing even further to a thread. The ISR behaves exactly as in the previous
model and simply blocks and acknowledges the interrupt before request that the DSR run. The DSR itself only calls

cyg_drv_cond_signal()

to wake the thread. When the thread awakens it performs all device processing, and has

full access to all kernel facilities while it does so. It should finish by calling

cyg_drv_interrupt_unmask()

to

re-allow device interrupts. The eCos ethernet device drivers are written to this model.

The first model is good for devices that need immediate processing and interact infrequently with thread level. The
second model trades a little latency in dealing with the device for a less intrusive synchronization mechanism. The
last model allows device processing to be scheduled with other threads and permits more complex device handling.

Synchronization Levels

Since it would be dangerous for an ISR or DSR to make a call that might reschedule the current thread (by trying
to lock a mutex for example) all functions in this API have an associated synchronization level. These levels are:

Thread

This function may only be called from within threads. This is usually the client code that makes calls into the

device driver. In a non-kernel configuration, this will be code running at the default non-interrupt level.

DSR

This function may be called by either DSR or thread code.

ISR

This function may be called from ISR, DSR or thread code.

The following table shows, for each API function, the levels at which is may be called:

Callable from:

Function

ISR

DSR

Thread

-------------------------------------------------------------------------

cyg_drv_isr_lock

X

X

X

cyg_drv_isr_unlock

X

X

X

cyg_drv_spinlock_init

X

cyg_drv_spinlock_destroy

X

cyg_drv_spinlock_spin

X

X

X

cyg_drv_spinlock_clear

X

X

X

cyg_drv_spinlock_try

X

X

X

cyg_drv_spinlock_test

X

X

X

cyg_drv_spinlock_spin_intsave

X

X

X

cyg_drv_spinlock_clear_intsave

X

X

X

287

Advertising