Showing posts with label Interrupts. Show all posts
Showing posts with label Interrupts. Show all posts

Tuesday, July 1, 2008

OAL ISR or Installable ISR

Sometimes, when someone needs to handle the interrupt for their device driver in an ISR (because using an IST has too much latency or because the interrupt is shared) they will decide to use the OAL's ISR instead of creating an Installable ISR for their driver. In general, using the OAL ISR for your ISR is a bad idea, as it unnecessarily couples the OAL and your particular hardware platform.

The following are examples of Interrupts that normally will be handled in the OAL ISR:
  1. System Timer for the SYSINTR_RESCHED.
  2. Interrupt for on-chip RTC Driver (as it's driver resides in the OAL.)
  3. ISR for Profiler.

Other than the three(3) instances above, we should never really be putting ISR for device drivers in the OALs ISR routine. In fact, if you look at the 3 items above, they all are for components or modules that exist within the OAL itself, not at the Windows CE Kernel or User-Level driver level.

Note: There are likely more instances than the three(3) listed above, but the instances above should be the most common instances of drivers that should have their ISRs included in the OAL.

For drivers such as Ethernet MACs, Serial Ports and LCD Controllers, they should either be using an Installable ISR or simply just an IST. They should never be putting themselves in as an OAL ISR.

Pros of OAL ISR over Installable ISR:
  1. ISR gets called slightly faster than Installable ISR.
Cons of OAL ISR over Installable ISR:
  1. Driver becomes non-portable. OAL ISR needs to be modified for EVERY platform that the driver must run on.
  2. OAL becomes non-portable. OAL becomes tied to hardware platform making it desirable to have one OAL for each hardware platform, or forces the developer to use ifdef's to select hardware platform against OAL.
  3. Harder to upgrade driver without replacing entire OS.

Thursday, June 26, 2008

ISR and IST

An ISR (Interrupt Service Routine) and IST (Interrupt Service Thread) are two Interrupt Mechanisms that are used to handle interrupts in Windows CE that are also to referred to as Bottom Half and Top Half Interrupt Handlers.

In the majority of cases, a Windows CE driver will never have a real ISR, and will instead only have an IST. There are of course exceptions to this such as Interrupts that MUST be shared along with Interrupts that have a more time critical approach.

An ISR is not required in Windows CE as the OAL's Interrupt Handler should automatically cause an IST to unblock if no ISR is present for an actual Interrupt. Because of this, drivers that do not require the functionality that an actual ISR provides may simply create and use an IST instead.

Interrupt Service Thread
An interrupt service thread is basically a thread that has an infinite loop around a call to WaitForSingleObject that uses a special "Windows Event" to wait against. The call to WaitForSingleObject will unblock when the SYSINTR that this event is initialized against is returned from the OAL Interrupt Handler.

Interrupt Service Routine
This is commonly referred to as an "Installable Interrupt Service Routine" when dealing with Windows CE. This is created and loaded by the Driver to do some early processing on behalf of the driver.

Most commonly, these drivers are used to do memory copies from hardware to a software buffer, or to enable the use of Shared Interrupts.

See Also
MSDN: Installable ISRs and Device Drivers

Wednesday, June 25, 2008

Physical vs Logical Interrupts and SYSINTR

This article will hopefully clarify the differences between Physical Interrupts, Logical Interrupts and SYSINTR values.

Physical Interrupts
A Physical Interrupt, represents an actual Interrupt Line on the system. It' is important to note that a Physical Interrupt may have more than one actual source (for example Pio Channel A on the Atmel AT91 Processor has 32 possible sources for the Physical Interrupt due to it's 32 GPIO lines.)

Physical Interrupts may be Level-Based, Edge Based (Rising, Falling or Both) or even Level and Edge-Based depending on the platform. Generally, Phyiscal Interrupts cannot be both level and edge sensitive at the same time. Most platforms that support both must be configured for one or the other.

Logical Interrupts
A Logical Interrupt is used by a BSP to allow a driver to indivdually select an Interrupt Source even if it is shared with other devices.

Logical Interrupts allow for two interrupt sources that both share a Physical Interrupt line to be individually acccessed and separated at the Driver Level. This means that two Interrupt Sources may have Logical Interrupts 40 and 41 even though they are both actually Physical Interrupt 2.

It is the responsibilty of the person creating the BSP to create the actual Logical to Physical Interrupt mapping (part of the OAL Interrupt code.)

SYSINTR Values
SYSINTR Values are a mapping between values that drivers and system components use hook their ISTs up to actual Interrrupts. This mapping may be done dynamically or statically.

All SYSINTR values that are used by device drivers MUST use SYSINTR values that are are in the range of SYSINTR_FIRMWARE(16) to SYSINTR_MAXIMUM(72). If dynamic SYSINTRs are being used (highly recommended) then the driver will simply request a SYSINTR value from the OS for a Logical Interrupt that it already knows.

If a static SYSINTR value must be used, they may only exist between SYSINTR_FIRMWARE(16) + 16 and SYSINTR_MAXIMUM(72). Additionally, static SYSINTR values MUST be configured in the OAL of the BSP.