(1) 建立驱动程序目录
在 C:\WINCE500\PLATFORM\mini2440\Src\Drivers\下建立 WDTDriver目录,并在dirs文件中加入此目录,使系统编译 bsp 的时候可以编译这个文件
(2)为 WDT驱动创建 Makefile文件
可以参考其他驱动程序示例创建 Makefile文件。 在 WDTDriver目录中建立 makefile文件,内容如下:
# # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source # file to this component. This file merely indirects to the real make file # that is shared by all the components of Peg # !INCLUDE $(_MAKEENVROOT)\makefile.def
(3)为 WDT驱动创建 source 文件
可以参考其他驱动程序实例创建source 文件,内容如下:
!if 0 File: sources Copyright (c) 1995-2002 Microsoft Corporation. All rights reserved. !endif !if "$(BSP_NOWATCHDOG)" == "1" SKIPBUILD=1 !endif RELEASETYPE=PLATFORM TARGETNAME=WDTDriver TARGETTYPE=DYNLINK DLLENTRY=DllEntry TARGETLIBS= \ $(_COMMONSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib \ MSC_WARNING_LEVEL = $(MSC_WARNING_LEVEL) /W3 /WX SOURCES= wdt.cpp
(4)编写wdt.def导出 Dll 符号
可以参考其他驱动程序示例创建 wdt.def文件。
; ; Windows WDT Driver. Written by yubaolee(.cpp/anglecloudy) LIBRARY WDT EXPORTS WDT_Close WDT_Deinit WDT_Init WDT_IOControl WDT_Open WDT_PowerDown WDT_PowerUp WDT_Read WDT_Seek WDT_Write
(5)把驱动加入内核 在配置文件 platform.bib中加入以下内容:
IF BSP_NOWATCHDOG ! WDTDriver.dll $(_FLATRELEASEDIR)\WDTDriver.dll NK SH ENDIF BSP_NOWATCHDOG !
(6)把 LED 驱动加入注册表 在注册表文件 platform.reg中加入以下内容:
IF BSP_NOWATCHDOG ! [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\WDTDriver] "Prefix"="WDT" "Dll"="WDTDriver.dll" "Order"="200" ENDIF BSP_NOWATCHDOG !
(7)编写代码:
//wdt.h文件 #ifndef __WDT_H_ #define __WDT_H_ #ifdef __cplusplus extern "C" { #endif DWORD WDT_Init(DWORD dwContext); DWORD WDT_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode); DWORD WDT_Write(DWORD hOpenContext, LPCVOID pSourceBytes, DWORD NumberOfBytes); DWORD WDT_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count); DWORD WDT_Seek(DWORD hOpenContext, long Amount, DWORD Type); BOOL WDT_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut); BOOL WDT_Close(DWORD hOpenContext); BOOL WDT_Deinit(DWORD hDeviceContext); void WDT_PowerUp(DWORD hDeviceContext); void WDT_PowerDown(DWORD hDeviceContext); #ifdef __cplusplus } #endif #endif
//wdt.cpp源码 #include <windows.h> #include <nkintr.h> #include <pm.h> #include "pmplatform.h" #include "Pkfuncs.h" #include "s2440.h" #include "wdt.h" volatile WATCHreg *s2440WDT = 0; static BOOL FeedIt() { s2440WDT->rWTCON = 0x8021; // Init Value s2440WDT->rWTDAT = s2440WDT->rWTCNT = 0xFEA9; s2440WDT->rWTCON = ( 1 << 0) | (0x03 << 3 ) | (1 << 5) | (0x5A << 8); RETAILMSG(1,(TEXT("WDT: feed ok\r\n"))); return TRUE; } BOOL WINAPI DllEntry(HANDLE hinstDLL, DWORD dwReason, LPVOID Reserved/* lpvReserved */) { switch(dwReason) { case DLL_PROCESS_ATTACH: DEBUGREGISTER((HINSTANCE)hinstDLL); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; #ifdef UNDER_CE case DLL_PROCESS_EXITING: break; case DLL_SYSTEM_STARTED: break; #endif } return TRUE; } BOOL WDT_Deinit(DWORD hDeviceContext) { return TRUE; } BOOL WDT_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut) { return 0; } void WDT_PowerDown(DWORD hDeviceContext) { } void WDT_PowerUp(DWORD hDeviceContext) { } DWORD WDT_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count) { return 0; } DWORD WDT_Seek(DWORD hOpenContext, long Amount, DWORD Type) { return 0; } DWORD WDT_Init(DWORD dwContext) { do { s2440WDT = (volatile WATCHreg *) VirtualAlloc(0,sizeof(WATCHreg),MEM_RESERVE, PAGE_NOACCESS); if (s2440WDT == 0) { break; } if (!VirtualCopy((PVOID)s2440WDT,(PVOID)(WATCH_BASE),sizeof(WATCHreg),PAGE_READWRITE | PAGE_NOCACHE )) { break; } //ret = TRUE; RETAILMSG(1,(TEXT("WDT: VirtualAlloc ok\r\n"))); } while (0); RETAILMSG(1,(TEXT("WDT: Init\r\n"))); return TRUE; } BOOL WDT_Close(DWORD hOpenContext) { if (s2440WDT) { VirtualFree((void*)s2440WDT, sizeof(WATCHreg), MEM_RELEASE); s2440WDT = 0; RETAILMSG(1,(TEXT("WDT: VirtualFree ok\r\n"))); } RETAILMSG(1,(TEXT("WDT: Close\r\n"))); return TRUE; } // Beaf is here DWORD WDT_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode) { RETAILMSG(1,(TEXT("WDT: Open\r\n"))); return TRUE; } DWORD WDT_Write(DWORD hOpenContext, LPCVOID pSourceBytes, DWORD NumberOfBytes) { RETAILMSG(1,(TEXT("WDT: Write\r\n"))); FeedIt(); return TRUE; }
(8)这时打开PB 在FileView视图mini2440/src/Drivers/就可以看到WDT的工程了,右键Build Current Project,没有错误的话,就可以生成WDT.DLL文件了,再生成一下系统就行了。
-----------------------------------.CPP---------------------------------------------------------------
@written by .cpp