Initializing an Interrupt
Windows CE initializes an interrupt either in OEMInit or as part of device driver initialization. Part of the interrupt initialization can also include the creation of an interrupt service thread (IST).
The kernel begins the interrupt initialization process by calling OEMInit. Use OEMInit to register an interrupt service routine (ISR) by calling the HookInterrupt function. HookInterrupt associates an ISR with a hardware interrupt request (IRQ). Further, you must use OEMInit to register the interrupts for the system timer because subsequent code, such as the scheduler, relies on a system timer.
Some device drivers may require handling that cannot be completed in an ISR. When Windows CE calls the initialization function for these types of device drivers, you can use InterruptInitialize to register an event handle with the interrupt identifier returned by the ISR of the target device. The initialization function of the device driver can then set up an IST for the interrupt by calling the CreateThread function. The main loop of the thread should wait on the event by using the WaitForSingleObject function. Do not use WaitForMultipleObjects. The main loop should also process the interrupt.
If you create a thread in the driver initialization routine, you should set the appropriate priority level of the thread with the CeSetThreadPriority function. This provides the appropriate scheduling times. When the IST has a higher priority than the interrupted thread, Windows CE interrupts the thread and runs the IST immediately. The thread priorities can range from 0 through 255, with 0 as the highest priority. The choice of the IST priority level is dependent upon the environment in which the IST needs to run. These environmental factors include the number of threads, relative priority of threads, and the amount of interrupt handling.
The following code example shows the functions that a device driver initialization routine typically calls to create an event and a thread associated with an ISR.
// Create an event and a thread, and then associate them.
hEvent = CreateEvent(...)
// Get the event handle, register the interrupt, and then
// associate it with the event.
InterruptInitialize(SYSINTR_SERIAL, hEvent, ...)
// Create the thread for the IST, passing it the event handle.
// The IST code calls WaitOnSingleObject, so give it the event handle.
hThd = CreateThread(..., MyISTRoutine, hEvent, ...)
CeSetThreadPriority(hThd, 152);
See Also
How to Develop an OEM Adaptation Layer | Implementing an ISR
Last updated on Wednesday, April 13, 2005
© 2005 Microsoft Corporation. All rights reserved.