为了完成CE作业又来看CE下的驱动程序设计了,后悔上那堂课时没认真听...... 还是先把知识复习一下:
1 在UNIX & Windows 9x系列中驱动程序和操作系统是绑定在一起的,在核心态里运行。但在CE里,大部分的驱动程序只是一个DLL文件,在用户态下运行。
2 大部分的驱动程序都是用来控制硬件的,但某些硬件是不需要驱动的,如:CPU,Memory......也有一些虚拟设备的驱动 ,如:文件系统驱动,RAM disk
3 CE提供逻辑中断SYSINTRs,中断仅被当作用户态下的一个线程(IST)
4 硬件的OEMs并不提供该硬件在CE上的驱动,而只是一个硬件规约(Hardware Specification)
驱动的分类: 1 Native 2 Bus 3 Stream interface
一,Native驱动 也叫做Built-in驱动,是硬件所必须的,由OEM设计硬件时所完成的。如:键盘,触摸屏...... 也许不支持一般设备驱动接口 。当OS的新版本出来时,一般Native驱动只需做很少的改动。
二,Bus驱动 管理系统总线,如PCI总线;PCMICA和CompactFlash也被当作总线。负责询问总线上的硬件来决定什么硬件被安装和正在分配资源。也会要求设备管理器(Device Manager)来为线上硬件装载合适的驱动。
三,Stream interface驱动 一会在下面会详细介绍这个
驱动的种类:
-
-
-
-
lBluetooth HCI Transport Driver
-
lDirect3D Device Driver Interface
-
lDirectDraw Display Drivers
-
-
-
-
-
lNotification LED Drivers
-
-
-
-
-
-
lStream Interface Drivers
-
-
驱动的装载过程: 1 大部分的驱动都是由系统启动时的设备管理进程(Device.exe)来完成装载的。
2 而一些Buit-in驱动由GWES.exe来装载。这些驱动包括显示驱动(DDI.dll),键盘驱动和触摸屏(鼠标)驱动
3 Device.exe会查看注册表里的[HKEY_LOCAL_MACHINE]\Drivers中一个被称为RootKey的字符串,通常是Builtin。这个RootKey里的驱动列表就是设备管理器必须初始化的。 [帖图1] 4 装载驱动的DLL, 为它创建一个ActiveKey(在[HKEY_LOCAL_MACHINE\Drivers\Active 下),并将这个DLL作为设备驱动注册到系统中。
3. [帖图2]
5 也可以由应用程序来手工装载驱动,如ActiveDeviceEx函数;另一个老的装载驱动的方法是用:RegisterDevice和 DeregisterDevice。
Stream Interface
一个流式接口驱动是指一个驱动把流式接口函数暴露出来,而不考虑驱动所控制的设备类型。典型的流式接口驱动:文件系统驱动(iostream,fstream),COM,LPT。。。。。
直接使用win32文件系统API: hSer = CreateFile(TEXT(“COM1:”), GENERIC_READ, 0, NULL, OPEN_EXSITING, 0, NULL); rc = ReadFile(hSer, &ch, 1, &cBytes, NULL); TransmitCommChar(hSer, ‘a’); CloseHandle(hSer);
创建一个流式驱动的过程: 1 写一个DLL,把流式接口的函数都expose出来 2 创建设备驱动 3 配置注册表
Closes the device context identified by hOpenContext.
Called by the Device Manager to de-initialize a device.
Called by the Device Manager to initialize a device.
Sends a command to a device.
Opens a device for reading, writing, or both. An application indirectly invokes this function when it calls CreateFile to open special device file names.
Ends power to the device. It is useful only with devices that can be shut off under software control.
Restores power to a device.
Reads data from the device identified by the open context.
Moves the data pointer in the device.
XXX_Write Writes data to the device.
注册表配置:
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Sample]
"Dll" = "mydriver.Dll"
"Prefix" = "DEM"
"Index" = dword:1
"Order" = dword:0
"FriendlyName" = "Demo Driver"
"Ioctl" = dword:0
CE下的服务 在CE4.0之前是没有服务可用的,4.0之后服务管理被加入进来了。
一个CE服务也是一个DLL,结构和一个流式驱动程序的差不多:有3字符前缀,有10个进入口函数
未完待续........
最后一次更新:2005年1月1日19:29:47

|