我写了个极简单的驱动程序,就是在2410上挂了一个ram,然后想对这个ram进行读写操作,现在不知道如何对这个驱动写测试代码
我的驱动代码如下
哪位高手愿意帮我看看阿
# include
# include
# include
# include
# include
# include "test_drv.h"
static BYTE g_Tmp=0;
static DWORD g_OpenCount=0;
//static DWORD Dll_PROCESS_ATTACH,DLL_PROCESS_DETACH;
bool WINAPI DllEntry(HANDLE hInstDll,DWORD dwReason,LPVOID lpvReserved)
{
switch( dwReason)
{
case DLL_PROCESS_ATTACH:
RETAILMSG(1,(TEXT("SPL: DLL_PROCESS_ATTACH.\r\n")));
DisableThreadLibraryCalls((HMODULE)hInstDll);
break;
case DLL_PROCESS_DETACH:
RETAILMSG(1,(TEXT("SPL: DLL_PROCESS_DETACH.\r\n")));
break;
}
return(true);
}
DWORD SPL_Init(DWORD dwContext)
{
RETAILMSG(1,(TEXT("::: SPL_Init.\r\n")));
g_Tmp=0;
g_OpenCount=0;
return 1;
}
BOOL SPL_Deinit(DWORD dwContext)
{
RETAILMSG(1,(TEXT("::: SPL_Deinit.\r\n")));
g_Tmp=0;
g_OpenCount=0;
return TRUE;
}
DWORD SPL_Open(DWORD hDeviceContext,DWORD AccessCode,DWORD ShareMode)
{
RETAILMSG(1,(TEXT("::: SPL_Open.\r\n")));
//不允许多个应用程序打开本驱动
if(g_OpenCount!=0)
{
RETAILMSG(1,(TEXT("SPL Open failed.\r\n")));
return 0;
}
g_OpenCount ++;
return g_OpenCount;
}
BOOL SOL_Close(DWORD hOpenContext)
{
RETAILMSG(1,(TEXT("::: SPL_Close.\r\n")));
if(g_OpenCount!=0)
g_OpenCount--;
return true;
}
bool SPL_IOControl(DWORD hOpenContext,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut)
{
RETAILMSG(1,(TEXT("::: SPL_IOControl. \r\n")));
return true;
}
void SPL_PowerUp(void)
{
RETAILMSG(1,(TEXT("::: SPL_PowerUp.\r\n")));
}
void SPL_PowerDown(void)
{
RETAILMSG(1,(TEXT("::: SPL_PowerDown.\r\n")));
}
DWORD SPL_Read(DWORD hOpenContext,LPVOID pBuffer,DWORD Count)
{
uchar * pReadBuffer;
RETAILMSG(1,(TEXT(":::SPL_Read.\r\n")));
if((pBuffer==NULL)||(Count<=0))
{
RETAILMSG(1,(TEXT("::: SPL_Read()parameter is error.\r\n")));
return 0;
}
//映射空间地址
pReadBuffer=(uchar *)MapPtrToProcess(pBuffer,GetCallerProcess());
*pReadBuffer=g_Tmp;
return 1;
}
DWORD SPL_Write(DWORD hOpenContext,LPCVOID pBuffer,DWORD Count)
{
uchar *pWriteBuffer;
RETAILMSG(1,(TEXT("::: SPL_Write.\r\n")));
if((pBuffer==NULL)||(Count<=0))
{
RETAILMSG(1,(TEXT("::: SPL_Write()parameter is error.\r\n")));
return 0;
}
//映射空间地址
pWriteBuffer=(uchar *)MapPtrToProcess((LPVOID)pBuffer,GetCallerProcess());
g_Tmp=*pWriteBuffer;
return 1;
}
DWORD SPL_Seek(DWORD hOpenContext,long Amount,DWORD Type)
{
RETAILMSG(1,(TEXT("::: SPL_Seek.\r\n")));
return 0;
}