首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

关于动态加载中断流驱动,该如何解决

2012-03-09 
关于动态加载中断流驱动1:如果加载驱动不成功 首先注意你的XXX_Open() 那3个XXX是否大写2:对于WINCE4.2以

关于动态加载中断流驱动
1:如果加载驱动不成功 首先注意你的XXX_Open() 那3个XXX是否大写
2:对于WINCE4.2以上的版本,动态加载中断流是不成功的啊

但是我的版本是WINCE5.0,而且我大小写都注意了,我就是用CE驱动调试助手激活我的中断驱动就是不成功啊

希望大侠们指点
放出我的程序
[code=C/C++][/code]



/*******************************************************************
** 函数: DLL程序入口
** 功能: 驱动形式是DLL的
********************************************************************/
BOOL WINAPI DllEntry(HANDLE hinstDLL,
DWORD dwReason,
LPVOID /* lpvReserved */)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
DEBUGREGISTER((HINSTANCE)hinstDLL);
return TRUE;
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 KEY_Deinit(DWORD hDeviceContext)
{
BOOL ret=true;

RETAILMSG(1,(TEXT("WZQ_KEY:KEY_Deinit......\r\n")));

//屏蔽系统逻辑按键中断
InterruptDisable(SYSINTR_USER_KEY);

CloseHandle(g_hEINTIntrThread);

for(int i=0; i<4; i++)
{
CloseHandle(g_ahKeyEvent[i]);
}
//释放虚拟内存空间
VirtualFree((void*)s2440IOP, sizeof(IOPreg), MEM_RELEASE);
VirtualFree((void*)s2440INT, sizeof(INTreg), MEM_RELEASE);

return TRUE;
}

BOOL KeyGpioInit()
{
RETAILMSG(1,(TEXT("Key_Gpio_Setting----\r\n")));
s2440IOP->rGPGCON = (s2440IOP->rGPGCON & ~(0x3 << 0x0)) | (0x2 << 0x0);// GPG0 == EINT8
s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 0)) | (0x3 << 0);// Falling-edge triggered.

s2440IOP->rGPGCON = (s2440IOP->rGPGCON & ~(0x3 << 0x6)) | (0x2 << 0x6);// GPG3 == EINT11
s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 12)) | (0x3 << 12);// Falling-edge triggered.

s2440IOP->rGPGCON = (s2440IOP->rGPGCON & ~(0x3 << 0x10)) | (0x2 << 0x10);// GPG5 == EINT13
s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 20)) | (0x3 << 20);// Falling-edge triggered.

s2440IOP->rGPGCON = (s2440IOP->rGPGCON & ~(0x3 << 0x12)) | (0x2 << 0x12);// GPG6 == EINT14
s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 24)) | (0x3 << 24);// Falling-edge triggered.

s2440IOP->rGPGCON = (s2440IOP->rGPGCON & ~(0x3 << 0x14)) | (0x2 << 0x14);// GPG7 == EINT15
s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 28)) | (0x3 << 28);// Falling-edge triggered.

s2440IOP->rGPGCON = (s2440IOP->rGPGCON & ~(0x3 << 0x22)) | (0x2 << 0x22);// GPG11 == EINT19
s2440IOP->rEXTINT2 = (s2440IOP->rEXTINT2 & ~(0x7<< 12)) | (0x3 << 12);// Falling-edge triggered.
return TRUE;
}

BOOL InitInterruptThread(void)
{
DWORD threadID;
DWORD ret; 

g_hKeyEvent=CreateEvent(NULL, FALSE, FALSE, NULL);

if(!g_hKeyEvent)
{
RETAILMSG(1,(TEXT("Fail to g_hKeyEvent=CreateEvent(NULL, FALSE, FALSE, NULL);\r\n")));
return FALSE;
}

ret=InterruptInitialize(SYSINTR_USER_KEY, g_hKeyEvent, NULL, 0);

if(!ret)
{
RETAILMSG(1,(TEXT("Fail to ret=InterruptInitialize(SYSINTR_USER_KEY, g_hKeyEvent, NULL, 0);\r\n")));
return FALSE;
}

g_hEINTIntrThread=CreateThread(
NULL,
0,
(LPTHREAD_START_ROUTINE)EintThread,
0,
0,
&threadID
);
if(NULL == g_hEINTIntrThread)
{
RETAILMSG(1,(TEXT("Fail to g_hEINTIntrThread\r\n")));
return FALSE;
}

RETAILMSG(1,(_T("UserKey.DLL::InterruptThread Initialized.\r\n")));


return TRUE;
}

DWORD KEY_Init(DWORD dwContext)
{

RETAILMSG(1,(TEXT("KEY_Init----\r\n")));

// 1. Virtual Alloc
EINT_InitAddress();

KeyGpioInit();

for(int i=0; i<4; i++)
{
g_ahKeyEvent[i]=CreateEvent(NULL,FALSE,FALSE,NULL);
}

if (!InitInterruptThread())
{
  RETAILMSG(1,(TEXT("Fail to initialize userkey interrupt event\r\n")));
  return FALSE;
  }  


//mInitialized = TRUE;
return TRUE;
}

//-----------------------------------------
//-----------------------------------------
BOOL KEY_IOControl(DWORD hOpenContext, 
DWORD dwCode, 
PBYTE pBufIn, 
DWORD dwLenIn, 
PBYTE pBufOut, 
DWORD dwLenOut, 
PDWORD pdwActualOut)
{
   
RETAILMSG(1,(TEXT("KEY:Ioctl code = 0x%x\r\n"), dwCode));
return TRUE;


//-----------------------------------------
//-----------------------------------------
DWORD KEY_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
RETAILMSG(1,(TEXT("USERKEY: KEY_Open\r\n")));
  RETAILMSG(1,(TEXT("USERKEY: KEY_Open---------\r\n")));
RETAILMSG(1,(TEXT("USERKEY: KEY_Open----------\r\n")));
RETAILMSG(1,(TEXT("USERKEY: KEY_Open-----------\r\n")));

return TRUE;


//-----------------------------------------
//-----------------------------------------
BOOL KEY_Close(DWORD hOpenContext)
{
RETAILMSG(1,(TEXT("USERKEY: KEY_Close\r\n")));
return TRUE;


//-----------------------------------------
//-----------------------------------------
void KEY_PowerDown(DWORD hDeviceContext)
{
RETAILMSG(1,(TEXT("USERKEY: KEY_PowerDown\r\n")));



//-----------------------------------------
//-----------------------------------------
void KEY_PowerUp(DWORD hDeviceContext)
{
RETAILMSG(1,(TEXT("USERKEY: KEY_PowerUp\r\n")));


//-----------------------------------------
//-----------------------------------------
DWORD KEY_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
DWORD dwRet;
uchar *pReadBuf;

RETAILMSG(1,(TEXT("USERKEY: KEY_Read\r\n")));

if(pBuffer==NULL || Count==0)
{
return FALSE;
}

pReadBuf=(uchar *)MapPtrToProcess(pBuffer,GetCallerProcess());
*pReadBuf=0;

//挂起当前线程直到有按键按下为止
dwRet=WaitForMultipleObjects(4,g_ahKeyEvent,FALSE,INFINITE);

if(dwRet==WAIT_OBJECT_0)
{
ResetEvent(g_ahKeyEvent[KEY1_EVENT]);
*pReadBuf=KEY1_DOWN;
}
else if(dwRet==WAIT_OBJECT_0+1)
{
ResetEvent(g_ahKeyEvent[KEY2_EVENT]);
*pReadBuf=KEY2_DOWN;
}
else if(dwRet==WAIT_OBJECT_0+2)
{
ResetEvent(g_ahKeyEvent[KEY3_EVENT]);
*pReadBuf=KEY3_DOWN;
}
else if(dwRet==WAIT_OBJECT_0+3)
{
ResetEvent(g_ahKeyEvent[KEY4_EVENT]);
*pReadBuf=KEY4_DOWN;
}
return (TRUE);


//-----------------------------------------
//-----------------------------------------
DWORD KEY_Seek(DWORD hOpenContext, long Amount, DWORD Type)


{
RETAILMSG(1,(TEXT("USERKEY: KEY_Seek\r\n")));
return 0;


//-----------------------------------------
//-----------------------------------------
DWORD KEY_Write(DWORD hOpenContext, LPCVOID pSourceBytes, DWORD NumberOfBytes)
{
RETAILMSG(1,(TEXT("USERKEY: KEY_Write\r\n")));
return 0;
}

[解决办法]
加载到哪一步不成功,请看打印信息,你打包这个驱动能用吗?

注意在XXX_DeInit函数必须把系统中断释放,否则卸载驱动再次加载会造成一个物理中断对应多个系统中断,这样是不会响应中断的。
[解决办法]
怎么个不成功法?

基本上,只要注册表没错,加载应该是没问题的。
[解决办法]
驱动加载不成功和你的KEY_init函数有很大关系。
如果跟不了代码,建议在KEY_init()中插入日志打印语句,看到底是哪步有问题,定位了这个再说。


例如:

DWORD KEY_Init(DWORD dwContext) 


RETAILMSG(1,(TEXT("KEY_Init----\r\n"))); 

// 1. Virtual Alloc 
EINT_InitAddress(); 
RETAILMSG(1,(TEXT("EINT_InitAddress done...\r\n")));
KeyGpioInit(); 
RETAILMSG(1,(TEXT("KeyGpioInit done...\r\n")));

for(int i=0; i <4; i++) 

g_ahKeyEvent[i]=CreateEvent(NULL,FALSE,FALSE,NULL); 

RETAILMSG(1,(TEXT("Create 4 Events done...\r\n")));

if (!InitInterruptThread()) 

RETAILMSG(1,(TEXT("Fail to initialize userkey interrupt event\r\n")));
return FALSE; 
}

//mInitialized = TRUE; 
return TRUE; 
}

热点排行