Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows CE Driver Architecture Jay Loney Program Manager Windows CE Drivers Microsoft.com.

Similar presentations


Presentation on theme: "Windows CE Driver Architecture Jay Loney Program Manager Windows CE Drivers Microsoft.com."— Presentation transcript:

1 Windows CE Driver Architecture Jay Loney Program Manager Windows CE Drivers JayLoney @ Microsoft.com

2 2 Agenda Driver Architecture Driver Architecture Device, Regenum, Loading Model, Power management Device, Regenum, Loading Model, Power management Windows CE versus WDM Windows CE versus WDM Memory and CEDDK Memory and CEDDK Basic Interrupt Architecture Basic Interrupt Architecture Windows CE.NET’s Installable ISRs (IISR) Windows CE.NET’s Installable ISRs (IISR) Bus Drivers Bus Drivers

3 3 Windows CE Architecture OEM Hardware Embedded Shell Applications WIN32 APIs COREDLL, WINSOCK, OLE, COMMCTRL, COMMDLG, WININET, TAPI Windows CE Shell Services Remote Connectivity KernelLibrary IrDA GWES Device Manager FileManager TCP/IP OALBootloader Drivers Device drivers File drivers MicrosoftOEMISV Networkdrivers

4 4 What Is A Driver In Windows CE Simply a DLL with a well defined set of entry points Simply a DLL with a well defined set of entry points Hosted by a Device Manager process space (sometimes GWES) Hosted by a Device Manager process space (sometimes GWES) Interface to apps via CreateFile (Streams – optional) Interface to apps via CreateFile (Streams – optional) Typically handle interrupts via dedicated thread (IST) Typically handle interrupts via dedicated thread (IST) Synchronization between apps and ISTs via criticalsections and mutexes Synchronization between apps and ISTs via criticalsections and mutexes Driver can have multiple simultaneous threads active Driver can have multiple simultaneous threads active

5 5 Driver Architecture

6 6 Types Of Drivers

7 7 Native Versus Stream Loading Mechanism Generally Native device drivers are loaded in the GWES process space by registry keys Generally Native device drivers are loaded in the GWES process space by registry keys Bus drivers loaded by Device.exe using registry Bus drivers loaded by Device.exe using registry Installable, Stream, and Hybrid drivers in Device.exe by either bus driver or Registry Enumerator Installable, Stream, and Hybrid drivers in Device.exe by either bus driver or Registry Enumerator

8 8 Device Manager User-level process that runs continously User-level process that runs continously Separate application that interacts with the kernel, the registry and stream interface driver DLLs Separate application that interacts with the kernel, the registry and stream interface driver DLLs Provides ActivateDevice and DeactivateDevice APIs Provides ActivateDevice and DeactivateDevice APIs

9 9 Device Manager Contains the IO Resource Manager Contains the IO Resource Manager Loads the registry enumerator (RegEnum.dll) which in turn loads the drivers based on the registry Loads the registry enumerator (RegEnum.dll) which in turn loads the drivers based on the registry Provides power notification callbacks Provides power notification callbacks Tracks all loaded devices and issues device interface notifications for insertion and removal Tracks all loaded devices and issues device interface notifications for insertion and removal

10 10 Device Manager Device Driver Loading Process Device Driver Loading Process DEVICE.EXE Kernel I/O Resource Manager (part of Device.exe) REGENUM.DLL PCIBUS.DLL loads loads loads DEVICE.EXE I/O Resource Manager (part of Device.exe) REGENUM.DLL PCIBUS.DLL

11 11 Registry Enumerator Registry Enumerator is RegEnum.dll Registry Enumerator is RegEnum.dll Device.exe loads the Registry Enumerator from HKEY_LOCAL_MACHINE\Drivers\RootKey Device.exe loads the Registry Enumerator from HKEY_LOCAL_MACHINE\Drivers\RootKey Registry Enumerator scans the registry for more drivers to load Registry Enumerator scans the registry for more drivers to load Registry Enumerator is re-entrant and supports hierarchical usage Registry Enumerator is re-entrant and supports hierarchical usage When it gets unloaded, it also unloads anything it directly loaded When it gets unloaded, it also unloads anything it directly loaded Registry Enumerator examines the first level of keys just below the key passed to it, according to Order Registry Enumerator examines the first level of keys just below the key passed to it, according to Order Registry Enumerator invokes ActivateDeviceEx on each subkey it finds Registry Enumerator invokes ActivateDeviceEx on each subkey it finds

12 12 Driver Registry Keys Registry Enumerator examines the SubKeys as defined below Registry Enumerator examines the SubKeys as defined below Order – Smallest value gets loaded first Order – Smallest value gets loaded first dll – Which DLL to load dll – Which DLL to load Prefix – Three letter stream interface name, used only with drivers that expose a stream interface Prefix – Three letter stream interface name, used only with drivers that expose a stream interface Index – Identifier when multiple instances are present, between 0 and 9, inclusively Index – Identifier when multiple instances are present, between 0 and 9, inclusively Flags – Modifies the default behavior of the enumerator Flags – Modifies the default behavior of the enumerator

13 13 ActivateDeviceEx Exposed by Device.exe Exposed by Device.exe Bus Drivers call ActivateDeviceEx when they load device drivers Bus Drivers call ActivateDeviceEx when they load device drivers ActivateDeviceEx also locks the stream interface driver into working RAM ActivateDeviceEx also locks the stream interface driver into working RAM This prevents code pages from being discarded This prevents code pages from being discarded Registry Enumerator calls ActivateDeviceEx on each built-in subkey it finds Registry Enumerator calls ActivateDeviceEx on each built-in subkey it finds ActivateDeviceEx loads driver and updates registry ActivateDeviceEx loads driver and updates registry

14 14 Driver Loading Registry Enumerator is key to loading drivers Registry Enumerator is key to loading drivers Device Manager loads Registry Enumerator Device Manager loads Registry Enumerator Scans registry and loads drivers Scans registry and loads drivers public\common\oak\drivers\regenum public\common\oak\drivers\regenum Driver loading process Driver loading process RegEnum scans registry, loads bus drivers RegEnum scans registry, loads bus drivers Bus driver scans the bus and locates devices Bus driver scans the bus and locates devices Searches the registry for device information Searches the registry for device information Finds a match and loads appropriate driver Finds a match and loads appropriate driver Action for not finding a match differs with each bus Action for not finding a match differs with each bus Sends notification that interface is available Sends notification that interface is available

15 15 Registry Key Example [HKEY_LOCAL_MACHINE\Drivers] "RootKey"="Drivers\\BuiltIn” "RootKey"="Drivers\\BuiltIn”[HKEY_LOCAL_MACHINE\Drivers\BuiltIn] "Dll"="RegEnum.dll“ "Dll"="RegEnum.dll“[HKEY_LOCAL_MACHINE\Drivers\CSP\Serial] "Dll"="Com16550.Dll" "Dll"="Com16550.Dll" "Order"=dword:0 "Order"=dword:0 "Irq"=dword:3 "Irq"=dword:3 "MemBase"=dword:FFBFC000 "MemBase"=dword:FFBFC000 "MemLen"=dword:8 "MemLen"=dword:8 "SysIntr"=dword:13 "SysIntr"=dword:13 "Prefix"="COM" "Prefix"="COM" "DeviceArrayIndex"=dword:0 "DeviceArrayIndex"=dword:0 "Priority"=dword:0 "Priority"=dword:0

16 16 Interface Classes Drivers are characterized by their interface Drivers are characterized by their interface Each IClass has a GUID and a Name Each IClass has a GUID and a Name GUID describes the generic device interface GUID describes the generic device interface Name identifies the instance of an interface Name identifies the instance of an interface COM1:, DSK1: and so on COM1:, DSK1: and so on Exposing a driver’s interface Exposing a driver’s interface IClass subkey in the registry IClass subkey in the registry Drivers publish interface – AdvertiseInterface Drivers publish interface – AdvertiseInterface Apps query interface – RequestDeviceNotifications Apps query interface – RequestDeviceNotifications Pre-defined GUIDs for existing interfaces Pre-defined GUIDs for existing interfaces A32942B7-920C-486b-B0E6-92A702A99B35 A32942B7-920C-486b-B0E6-92A702A99B35

17 17 I/O Resource Manager IORM is an intrinsic part of Device Manager IORM is an intrinsic part of Device Manager Tracks available I/O resources (IRQ and I/O base address) Tracks available I/O resources (IRQ and I/O base address) OEM pre-allocates resources for built-in devices OEM pre-allocates resources for built-in devices Bus drivers request resources when loading a client driver on their bus Bus drivers request resources when loading a client driver on their bus ResourceRequest ResourceRequest ResourceRelease ResourceRelease ResourceCreateList ResourceCreateList IORM fails ResourceRequest when there is a conflict IORM fails ResourceRequest when there is a conflict

18 18 Registry Helper Routines Reads resource configuration from the registry Reads resource configuration from the registry OpenDeviceKey OpenDeviceKey DDKReg_GetIsrInfo DDKReg_GetIsrInfo DDKReg_GetWindowInfo DDKReg_GetWindowInfo DDKReg_GetPciInfo DDKReg_GetPciInfo APIs in COREDLL APIs in COREDLL Prototyped in and Prototyped in and Samples in public\common\oak\drivers Samples in public\common\oak\drivers wavedev\pdd\es1371\wavepdd.cpp -> GetRegistryConfig wavedev\pdd\es1371\wavepdd.cpp -> GetRegistryConfig

19 19 Contrast: Windows XP WDM Loading Model Drivers are loaded in the kernel address space as a.sys file Drivers are loaded in the kernel address space as a.sys file In Windows XP, everything is PNP In Windows XP, everything is PNP Boot time: BIOS tells you ACPI table which tells you which drivers to load, including busses Boot time: BIOS tells you ACPI table which tells you which drivers to load, including busses Windows CE walks through the registry Windows CE walks through the registry Run time: PNP manager is informed of added devices by the bus drivers. PNP manager asks bus driver who it is, PNP Man. loads the driver based on inf database. CE’s bus drivers detect PNP devices, scan registry for driver and request driver loading from Device Manager Run time: PNP manager is informed of added devices by the bus drivers. PNP manager asks bus driver who it is, PNP Man. loads the driver based on inf database. CE’s bus drivers detect PNP devices, scan registry for driver and request driver loading from Device Manager Driver entry is called DriverEntry Driver entry is called DriverEntry In CE it’s xxx_Init In CE it’s xxx_Init Then the other driver entry points are specified for read/write/IOCTL/power Then the other driver entry points are specified for read/write/IOCTL/power In CE it’s the rest of the streams interface In CE it’s the rest of the streams interface Drivers are re-entrant Drivers are re-entrant PDO device objects (handle), provided by bus driver, to handle multiple instances PDO device objects (handle), provided by bus driver, to handle multiple instances

20 20 Power Management Power Manager Power Manager Flexible infrastructure for system-level and peripheral-level power management Flexible infrastructure for system-level and peripheral-level power management Lets devices intelligently manage their own power Lets devices intelligently manage their own power Acts as a mediator between the devices and system/applications Acts as a mediator between the devices and system/applications Enables OEMs to modify the code surrounding calls to PowerOffSystem() Enables OEMs to modify the code surrounding calls to PowerOffSystem()

21 21 Power Management System-level power states System-level power states Device (peripheral) level power states Device (peripheral) level power states On System Idle User Idle Suspend D0 Fully Powered D3 Sleep D1 Low Performance D4 Off D2 Standby

22 22 Power Manager Architecture Drivers Power Manager (pm.dll) PM APIs Application Notification Message Queue DriverAPIs ApplicationAPIs

23 23 Contrast: WDM Power Management Similar structure, different implementation Similar structure, different implementation Power manager lives in the Kernel (in Windows CE it’s in DeviceMan) Power manager lives in the Kernel (in Windows CE it’s in DeviceMan) S0-S5 system states (CE has OEMIdle and OEMPowerDown) S0-S5 system states (CE has OEMIdle and OEMPowerDown) WDM Power manager negotiates with all active drivers whether a system state can be entered WDM Power manager negotiates with all active drivers whether a system state can be entered WDM Power Manager walks the device tree, tells the drivers that the system is in a certain state. The driver then makes its own decision as to what Device state (D-state) the device should be in WDM Power Manager walks the device tree, tells the drivers that the system is in a certain state. The driver then makes its own decision as to what Device state (D-state) the device should be in (CE has D0-D5, but is extensible) (CE has D0-D5, but is extensible) Driver can veto a System state because it is working Driver can veto a System state because it is working Battery Critical off has the highest precedent and will override any driver working Battery Critical off has the highest precedent and will override any driver working

24 24 Physical Memory 64 MB RAM 32 MB Flash Dbg Serial Port 2 GB User 512 MB Uncached 512 MB Cached 64 MB RAM 32 MB Flash 64 MB RAM 32 MB Flash Physical Memory Kernel Virtual Address Reserved 04000000 82000000 80000000 80000000 A0000000 C0000000 0

25 25 Not Used Slot 0 Slot 32 64 KB 32 MB 64 MB 2 GB 3 GB 4 GB Memory mapped files Above 2G-3G Mapped to physical memory Virtual address space Slot 1 Slot 32 NULL pointers Virtual Address Space 512M Cached 512M Non-Cached 0x80000000 0xA0000000 Accessable via MmMapiIoSpace

26 26 Memory Management Functions Device drivers are user-mode modules Device drivers are user-mode modules Necessary to map physical memory to virtual memory Necessary to map physical memory to virtual memory VirtualAlloc, VirtualFree: reserve, free virtual memory VirtualAlloc, VirtualFree: reserve, free virtual memory MEM_RESERVE MEM_RESERVE VirtualCopy: Maps a physical memory range to a virtual memory range VirtualCopy: Maps a physical memory range to a virtual memory range PAGE_NOCACHE PAGE_NOCACHE PAGE_PHYSICAL PAGE_PHYSICAL

27 27 Driver Memory Access – Mapped Pointers MapPtrToProcess MapPtrToProcess Allows you to map a pointer from one address space to another Allows you to map a pointer from one address space to another GetCurrentProcess GetCurrentProcess Retrieves a process identifier to be used with the MapPtrToProcess function Retrieves a process identifier to be used with the MapPtrToProcess function SetProcPermissions SetProcPermissions Gives the current process access to other processes’ address spaces Gives the current process access to other processes’ address spaces

28 28 Driver Memory Access – Mapped Pointers App Calls DeviceIOControl DM mapped into Slot 0 App is mapped into Slot 0 DM Calls xxx_IoControl DM Sets permissions to App space APP DM Slot 0 APP APP Mapped pointer Driver Calls MapPtrToProcess Driver returns from xxx_IoControl DM Re-Sets permissions to App space App is mapped into Slot 0 APP DM APP Original pointer DM APP

29 29 Contrast: WDM Basic Memory Management Windows XP drivers are in kernel address space Windows XP drivers are in kernel address space XP Drivers can access all kernel address space XP Drivers can access all kernel address space Can access the User space of the context from which they’re called Can access the User space of the context from which they’re called In Windows CE, drivers have to map through virtual memory to get to their physical port/memory In Windows CE, drivers have to map through virtual memory to get to their physical port/memory Driver’s communicate in 2 ways Driver’s communicate in 2 ways Buffered IO Buffered IO Direct IO (suggested only if packet is bigger then 1 page) Direct IO (suggested only if packet is bigger then 1 page) MMMapIOSpace maps physical devices into kernel address space MMMapIOSpace maps physical devices into kernel address space Windows CE does this with OEMAddressTable in the OAL Windows CE does this with OEMAddressTable in the OAL

30 30 CEDDK CE v2.1x and later supports a platform independent I/O scheme CE v2.1x and later supports a platform independent I/O scheme Left up to the OEM and driver writer to actually use them Left up to the OEM and driver writer to actually use them CEDDK.DLL CEDDK.DLL BUS Management BUS Management Memory Management Memory Management I/O Management I/O Management CEDDK APIs taken from NTDDK CEDDK APIs taken from NTDDK Not documented until V2.12 Not documented until V2.12 But most available in V2.00 But most available in V2.00

31 31 CEDDK Abstraction Device drivers use CEDDK Device drivers use CEDDK Properly written drivers are binary compatible across platforms Properly written drivers are binary compatible across platforms Source code compatible across CPUs Source code compatible across CPUs Device Manager Device Driver CEDDK.DLL Hardware

32 32 CEDDK Internals Coverage Function Examples BusManagementHalGetBusDataByOffset()HalGetBusData()HalSetBusDataByOffset()HalSetBusData()HalTranslateBusAddress()HalTranslateSystemAddress() Memory Management MmMapIOSpace – MmUnmapIOSpace HalAllocateCommonBuffer I/O Access XXXX => XXXX => UCHAR/USHORT/ULONG UCHAR/USHORT/ULONGREAD_REGISTER_XXXXWRITE_REGISTER_XXXXREAD_PORT_XXXXWRITE_PORT_XXXX

33 33 Contrast: WDM Advanced Memory Management The CEDDK-like functions aren’t used anymore in WDM The CEDDK-like functions aren’t used anymore in WDM Bus drivers are now controlling the DMA for their own busses Bus drivers are now controlling the DMA for their own busses PNP Manager asks the bus driver what resources the driver needs and arbitrates the resources including DMA channel requests PNP Manager asks the bus driver what resources the driver needs and arbitrates the resources including DMA channel requests PNP Manager can arbitrate conflicts (“resource rebalancing”) PNP Manager can arbitrate conflicts (“resource rebalancing”) Ex. Device1 can use irq 10 or 11 and gets 10, device2 comes later and can only use 10, PNP Manager will shuffle device1 to 11 and restart him Ex. Device1 can use irq 10 or 11 and gets 10, device2 comes later and can only use 10, PNP Manager will shuffle device1 to 11 and restart him In CE, always use shared interrupts to help avoid this problem. In the example above, you’re stuck In CE, always use shared interrupts to help avoid this problem. In the example above, you’re stuck

34 34 Interrupt Architecture Interrupt is just a particular exception Interrupt is just a particular exception Caught by kernel code Caught by kernel code Dealt with prior to resuming user code Dealt with prior to resuming user code But hardware is independent of OS But hardware is independent of OS CE uses two stage Interrupt Service model CE uses two stage Interrupt Service model Lightweight code to quiet interrupt Lightweight code to quiet interrupt Scheduled code to service hardware Scheduled code to service hardware OS provides API for enabling IRQ signals, prioritization, etc. OS provides API for enabling IRQ signals, prioritization, etc. Hardware specific operations done in OAL and device driver code Hardware specific operations done in OAL and device driver code

35 35KernelOAL User Mode HW All CE 3.0 Interrupt Handling None Device Driver IST Processing Set Event EOI Except. Handler ISREnable App Higher Priority PSR SYSINTR_ID IRQ Masked All IRQ Enabled WFSO WFSO on Event Application Resumes

36 36 Notes On ISRs And ISTs ISTs are plain old user mode code ISTs are plain old user mode code Full CE.NET API and CRT library available Full CE.NET API and CRT library available CE.NET scheduler controls IST execution based on thread priority CE.NET scheduler controls IST execution based on thread priority Run-time binding to SYSINTR Run-time binding to SYSINTR ISRs are called from Exception Handler ISRs are called from Exception Handler No OS services available No OS services available Stack space is limited Stack space is limited May be reentrant (OAL choice) May be reentrant (OAL choice) Assembly language on MIPS, SHx Assembly language on MIPS, SHx

37 37 ISR Observations IRQ priorities CPU architecture dependent IRQ priorities CPU architecture dependent PIC hardware handles this on x86 PIC hardware handles this on x86 OAL arrays IntrPriority, IntrMask on MIPS OAL arrays IntrPriority, IntrMask on MIPS OAL could add real-time feature allowing IST processing to preempt ISR service OAL could add real-time feature allowing IST processing to preempt ISR service Under CE 3.0, all ISR code part of OAL Under CE 3.0, all ISR code part of OAL Not particularly expandable Not particularly expandable IRQs bound to event IDs in OEMInit IRQs bound to event IDs in OEMInit No Support for PNP, IRQ sharing (PCI bus) No Support for PNP, IRQ sharing (PCI bus) CE.NET addresses these limitations with Installable ISR (IISR) chain CE.NET addresses these limitations with Installable ISR (IISR) chain

38 38 CE.NET Installable ISRs Preferable Extension to CE 3.0 ISR architecture Preferable Extension to CE 3.0 ISR architecture DLL code, bound at run time DLL code, bound at run time Source code can be CPU independent Source code can be CPU independent Typically coded in “C” Typically coded in “C” Some restrictions apply Some restrictions apply No calls to CRT, Windows API, or other DLLs No calls to CRT, Windows API, or other DLLs Run-to-completion ISR, or IST dispatch Run-to-completion ISR, or IST dispatch Support for hardware IRQ sharing Support for hardware IRQ sharing Distinct SYSINTR ID from same IRQ Distinct SYSINTR ID from same IRQ

39 39 IISR CE.NET Interrupt Handling Kernel OAL Driver HW Set Event None Except. Handler ISR Higher Priority IRQs Enabled PSR SYSINTR_ID IRQ Masked SYSINTR_xxSYSINTR_NOP IST IISR 1 NKCallIntChain(IRQ) IISR n SYSINTR_CHAIN IISR 2

40 40 IISR Control Flow Driver registers IISR DLL with the Kernel with the call to LoadIntChainHandler() Driver registers IISR DLL with the Kernel with the call to LoadIntChainHandler() Data passed to IISR via KernelLibIoControl() Data passed to IISR via KernelLibIoControl() OAL ISR decodes IRQ from hardware, calls kernel NkCallIntChain(dwIRQ) to query IISRs OAL ISR decodes IRQ from hardware, calls kernel NkCallIntChain(dwIRQ) to query IISRs IISRs called in binding order IISRs called in binding order IISR return value indicates status IISR return value indicates status SYSINTR_CHAIN indicates IRQ not recognized SYSINTR_CHAIN indicates IRQ not recognized OAL ISR translates IRQ to SYSINTR as before OAL ISR translates IRQ to SYSINTR as before SYSINTR_NOP indicates IISR run-to-completion SYSINTR_NOP indicates IISR run-to-completion IISR must make IRQ go away! IISR must make IRQ go away! Other values indicate IISR owns interrupt Other values indicate IISR owns interrupt OAL ISR code must set PIC IRQ mask OAL ISR code must set PIC IRQ mask OAL ISR handles PIC EOI, returns ID OAL ISR handles PIC EOI, returns ID

41 41 Interrupt Service Thread Is user-mode thread of device drivers for built-in devices Is user-mode thread of device drivers for built-in devices Does the actual processing of the interrupt Does the actual processing of the interrupt Creates an event object associated with the logical interrupt by calling CreateEvent function Creates an event object associated with the logical interrupt by calling CreateEvent function IST remains idle most of the time, awakened when the kernel signals the event object IST remains idle most of the time, awakened when the kernel signals the event object IST usually runs at above-normal priority, boost priority with CeSetThreadPriority function IST usually runs at above-normal priority, boost priority with CeSetThreadPriority function

42 42 Interrupt Service Thread InterruptInitialize InterruptInitialize Call InterruptInitialize to link the Event with the Interrupt ID of the ISR Call InterruptInitialize to link the Event with the Interrupt ID of the ISR WaitForSingleObject WaitForSingleObject Can be used to wait for an event to be signaled Can be used to wait for an event to be signaled This call is usually inside a loop so that when interrupt is processed, the IST gets back to this call waiting for the next interrupt to be handled This call is usually inside a loop so that when interrupt is processed, the IST gets back to this call waiting for the next interrupt to be handled InterruptDone InterruptDone After the interrupt data is processed, the IST must call the InterruptDone function to instruct the kernel to enable the hardware interrupt related to this thread After the interrupt data is processed, the IST must call the InterruptDone function to instruct the kernel to enable the hardware interrupt related to this thread

43 43 Typical IST Start struct ISTData // Declare the Strucure to pass to the IST { HANDLE hThread; // IST Handle HANDLE hThread; // IST Handle DWORD sysIntr; // Logical ID DWORD sysIntr; // Logical ID HANDLE hEvent; // handle to the event to wait for interrupt HANDLE hEvent; // handle to the event to wait for interrupt volatile BOOL abort; // flag to test to exit the IST volatile BOOL abort; // flag to test to exit the IST}; ISTData g_KeypadISTData; // Create event to link to IST g_KeypadISTData.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // Translate IRQ to an logical ID (x86 CEPC) g_KeypadISTData.sysIntr =Mapirq2Sysintr(5); // start the thread g_KeypadISTData.hThread = CreateThread(NULL,0,&KeypadIST, &g_KeypadISTData, 0, NULL); &g_KeypadISTData, 0, NULL);

44 44 Typical IST Start //Change the threads priority CeSetThreadPriority(g_KeypadISTData.hThread,0); //disconnect any previous event from logical ID InterruptDisable(g_KeypadISTData.sysIntr); // Connect Logical ID with Event InterruptInitialize(g_KeypadISTData.sysIntr, g_KeypadISTData. hEvent,NULL,0); Set the IST Thread Priority Set the IST Thread Priority Disconnect any previous events from the associated ISR Disconnect any previous events from the associated ISR Connect to the associated ISR Connect to the associated ISR

45 45 Typical IST Start DWORD KeypadIST(void *dat) { ISTData* pData= (ISTData*)dat; ISTData* pData= (ISTData*)dat; // loop until told to stop // loop until told to stop While(!pData->abort) While(!pData->abort) { // wait for the interrupt event... { // wait for the interrupt event... WaitForSingleObject(pData->hEvent, INFINITE) WaitForSingleObject(pData->hEvent, INFINITE) if(pData->abort) if(pData->abort) break; break; // Handle the interrupt... // Handle the interrupt... // Let OS know the interrupt processing is done // Let OS know the interrupt processing is done InterruptDone(pData->sysIntr); InterruptDone(pData->sysIntr); } Return 0; Return 0;}

46 46 Typical IST Stop // set abort flag to true to let thread know // that it should exit g_KeypadISTData.abort =TRUE; //disconnect event from logical ID //this internally sets g_KeypadISTData.sysIntr which in turn //sets g_KeypadISTData.hEvent through the kernel InterruptDisable(g_KeypadISTData.sysIntr); //wait for thread to exit WaitForSingleObject(g_KeypadISTData.hEvent,INFINITE);CloseHandle(g_KeypadISTData.hEvent);CloseHandle(g_KeypadISTData.hThread); Set a flag that will cancel the IST loop Set a flag that will cancel the IST loop Call InterruptDisable to disconnect the triggering event from the logical ID Call InterruptDisable to disconnect the triggering event from the logical ID Close the Thread Add Reference for the code Close the Thread Add Reference for the code

47 47 Contrast: WDM Interrupts Driver is assigned interrupt by the PNP manager Driver is assigned interrupt by the PNP manager Driver registers with kernel it’s ISR Driver registers with kernel it’s ISR When IRQ fires, IDT table links the IRQ to the ISR When IRQ fires, IDT table links the IRQ to the ISR ISR routines run in arbitrary thread context because all applications share the kernel space ISR routines run in arbitrary thread context because all applications share the kernel space ISR runs immediately ISR runs immediately Priority by hardware first, then IRQL (levels) 0-31, 3-28 are hardware devices Priority by hardware first, then IRQL (levels) 0-31, 3-28 are hardware devices Queue Deferred Procedure Calls to do extended read/write work when IRQL drops to 2, this queue is drained in FIFO order Queue Deferred Procedure Calls to do extended read/write work when IRQL drops to 2, this queue is drained in FIFO order Threads (spell-checker) run when IRQL hits 0 Threads (spell-checker) run when IRQL hits 0 DPCs are similar to CE ISTs, however CE ISTs are prioritized DPCs are similar to CE ISTs, however CE ISTs are prioritized

48 48 Bus Drivers Overview PCMCIA PCMCIA I82365 (ISA) I82365 (ISA) TI-1250 (PCI) TI-1250 (PCI) USB Host USB Host Multiple Host Controllers Multiple Host Controllers OHCI and UHCI (PCI) OHCI and UHCI (PCI)

49 49 PCMCIA Host PCMCIA bus driver has three main threads PCMCIA bus driver has three main threads Status change thread (card insertion/removal) Status change thread (card insertion/removal) Interrupt thread (handles card functional interrupt requests) Interrupt thread (handles card functional interrupt requests) Callback thread (notifies card clients of events) Callback thread (notifies card clients of events) Bus driver supports a subset of Card Serv. messages, delivered as callbacks from the callback thread Bus driver supports a subset of Card Serv. messages, delivered as callbacks from the callback thread Interrupts are delivered to client drivers as callbacks Interrupts are delivered to client drivers as callbacks Newly inserted cards are scanned for identifying PnP tuples and compared with entries in the registry Newly inserted cards are scanned for identifying PnP tuples and compared with entries in the registry If no match is found, candidate drivers can run “detect” routines to card-specific mechanisms to ID the card If no match is found, candidate drivers can run “detect” routines to card-specific mechanisms to ID the card May display a dialog box asking for the name of the DLL May display a dialog box asking for the name of the DLL

50 50 USB Host USB Version 1.1 compliant USB Version 1.1 compliant OHCI and UHCI fully supported OHCI and UHCI fully supported Support for all transfer types Support for all transfer types Isoch, bulk, interrupt, control Isoch, bulk, interrupt, control USBD supports multiplexing between multiple HC USBD supports multiplexing between multiple HC Client drivers are typically loaded using LoadDriver and use USBD operations to communicate with the HC Client drivers are typically loaded using LoadDriver and use USBD operations to communicate with the HC Client drivers can optionally call ActivateDeviceEx() on themselves to expose a stream interface to apps Client drivers can optionally call ActivateDeviceEx() on themselves to expose a stream interface to apps Detects and identifies newly attached devices Detects and identifies newly attached devices Loads drivers as described in the registry Loads drivers as described in the registry May display a dialog box asking for the name of the DLL May display a dialog box asking for the name of the DLL

51

52 52 Community Resources http://msdn.microsoft.com/embedded/ Community Sites http://www.microsoft.com/communities/default.mspx http://www.microsoft.com/communities/default.mspx http://www.microsoft.com/communities/default.mspx List of Newsgroups List of Newsgroups http://communities2.microsoft.com/communities/newsgroups/en- us/default.aspx http://communities2.microsoft.com/communities/newsgroups/en- us/default.aspx http://communities2.microsoft.com/communities/newsgroups/en- us/default.aspx http://communities2.microsoft.com/communities/newsgroups/en- us/default.aspx Attend a free chat or webcast Attend a free chat or webcast http://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/seminar/events/webcasts/default.mspx http://www.microsoft.com/seminar/events/webcasts/default.mspx http://www.microsoft.com/seminar/events/webcasts/default.mspx Locate a local user group(s) Locate a local user group(s) http://www.microsoft.com/communities/usergroups/default.mspx http://www.microsoft.com/communities/usergroups/default.mspx http://www.microsoft.com/communities/usergroups/default.mspx Non-Microsoft Community Sites Non-Microsoft Community Sites http://www.microsoft.com/communities/related/default.mspx http://www.microsoft.com/communities/related/default.mspx http://www.microsoft.com/communities/related/default.mspx

53


Download ppt "Windows CE Driver Architecture Jay Loney Program Manager Windows CE Drivers Microsoft.com."

Similar presentations


Ads by Google