将Wince 6.0 Public下的Battdrvr驱动移植到BSP
By:zsz @ 2011/5/19
1、 将Public下的Battdrvr目录拷贝到BSPDir\SRC\Drivers目录下,并在此目录下的dir文件中增加battdrvr,记BSPDir\SRC\Driver\battdrvr目录为BSPBattdrvr
2、 更改BSPBattdrvr\PDD目录下的sources文件
原sources文件为:
TARGET=battdrvr_stubpdd
TARGETNAME=$(TARGET)
TARGETTYPE=LIBRARY
SOURCES = \
sbattif.c
改为:
RELEASETYPE=PLATFORM #加入这句标明lib放在BSP lib路径下
TARGET=battdrvr_stubpdd_ZGT #改名,为了和原来lib区别
TARGETNAME=$(TARGET)
TARGETTYPE=LIBRARY
WINCEOEM=1 #设置该值表示需要使用WinCE下的一些公用的库和头文件
SOURCES = \
sbattif.c
3、 更改BSPBattdrvr\MDD目录下的sources文件
原sources文件为
TARGET=battdrvr_mdd
TARGETNAME=$(TARGET)
TARGETTYPE=LIBRARY
TARGETDEFNAME=battdrvr
DEFFILE=$(TARGETDEFNAME).def
WINCETARGETFILE0=$(_COMMONOAKROOT)\lib\$(_CPUINDPATH)\$(TARGETDEFNAME).def
SOURCES = \
battdrvr.c \
battapi.c \
battzones.c
改为:
RELEASETYPE=PLATFORM
TARGET=battdrvr_mdd_ZGT
TARGETNAME=$(TARGET)
TARGETTYPE=LIBRARY
WINCEOEM=1
SOURCES = \
battdrvr.c \
battapi.c \
battzones.c
更改原因同2
4、 更改BSPBattdrvr\LIB目录下的sources文件
原sources文件为:
TARGET=battdrvr
TARGETNAME=$(TARGET)_lib
TARGETTYPE=LIBRARY
SYNCHRONIZE_DRAIN=1
SOURCELIBS=\
$(_COMMONOAKROOT)\lib\$(_CPUINDPATH)\battdrvr_mdd.lib \
$(_COMMONOAKROOT)\lib\$(_CPUINDPATH)\battdrvr_stubpdd.lib
WINCETARGETFILES=dummy
SOURCES =
改为:
RELEASETYPE=PLATFORM
TARGET=battdrvr
TARGETNAME=$(TARGET)_lib_ZGT
TARGETTYPE=LIBRARY
WINCEOEM=1
SYNCHRONIZE_DRAIN=1
SOURCELIBS=\
$(_TARGETPLATROOT)\lib\$(_CPUINDPATH)\battdrvr_mdd_ZGT.lib \
$(_TARGETPLATROOT)\lib\$(_CPUINDPATH)\battdrvr_stubpdd_ZGT.lib
#注意修改的路径
WINCETARGETFILES=dummy
SOURCES =
5、 在BSPBattdrvr目录下增加DLL目录(并在dir文件中加上此目录),将makefile和battdrvr.def拷贝到这个目录下
Battdrvr.def内容如下:
LIBRARY BATTDRVR
; DESCRIPTION Battery MDD/sample driver
EXPORTS Init
Deinit
Open
Close
Read
Write
Seek
PowerDown
PowerUp
IOControl
6、 在BSPBattdrvr\DLL目录下新建sources文件,内容如下:
TARGETNAME=battdrvr_ZGT
TARGETTYPE=DYNLINK
RELEASETYPE=PLATFORM
SYNCHRONIZE_DRAIN=1
WINCEOEM=1
DLLENTRY=DllMain
DEFFILE=battdrvr.def
SOURCELIBS=
TARGETLIBS=\
$(_TARGETPLATROOT)\lib\$(_CPUINDPATH)\battdrvr_lib_ZGT.lib \
$(_SYSGENOAKROOT)\lib\$(_CPUINDPATH)\ceddk.lib \
$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib
SOURCES=
将生成battdrvr_ZGT.dll文件
7、 在platform.bib中增加:
IF BSP_NOBATTERY !
battdrvr.dll $(_FLATRELEASEDIR)\battdrvr_ZGT.dll NK SHK
ENDIF BSP_NOBATTERY !
注意:是将battdrvr_ZGT.dll重命名为battdrvr.dll
8、 在platform.reg中增加:
IF BSP_NOBATTERY !
; HIVE BOOT SECTION
[HKEY_LOCAL_MACHINE\System\Events]
"SYSTEM/BatteryAPIsReady"="Battery Interface APIs"
; END HIVE BOOT SECTION
; These registry entries load the battery driver. The IClass value must match
; the BATTERY_DRIVER_CLASS definition in battery.h -- this is how the system
; knows which device is the battery driver. Note that we are using
; DEVFLAGS_NAKEDENTRIES with this driver. This tells the device manager
; to instantiate the device with the prefix named in the registry but to look
; for DLL entry points without the prefix. For example, it will look for Init
; instead of BAT_Init. This allows the prefix to be changed in the registry (if
; desired) without editing the driver code.
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Battery]
"Prefix"="BAT"
"Dll"="battdrvr.dll"
"Flags"=dword:8 ; DEVFLAGS_NAKEDENTRIES
"Order"=dword:0
"IClass"="{DD176277-CD34-4980-91EE-67DBEF3D8913}"
ENDIF BSP_NOBATTERY !
9、 在PB里选上Core OS->CEBASE->Core OS Services->Battery Driver
选上这个是为了方便增加battery驱动所需要的Dependencies,但是我们不会用到这个驱动,因为我们用的是battdrvr_ZGT.dll
10、sysgen即可