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

[wince5.0]关于interruptinitialize的使用有关问题,请问

2012-03-21 
[wince5.0]关于interruptinitialize的使用问题,请教!我目前是在一个wince5.0平台上写个小驱动,需要在init

[wince5.0]关于interruptinitialize的使用问题,请教!
我目前是在一个wince5.0平台上写个小驱动,需要在init里启用一个中断,于是就想到了interruptinitialize()这个函数。现在的问题是如果在原BSP里的某个驱动里使用这个函数调用就没有问题,并且能完成任务;但是我自己写的驱动,编译完成后就总是出现调用错误,出错信息如下:
MyDriver - DLL_PROCESS_ATTACH
MyDriver - DEM_Init 
+OALIntrEnableIrqs(1, 0x8c9902c8)
+BSPIntrEnableIrq(-1)
MyDriver - ~ DEM_Init
---------------------------------------------
下面附上我在powerbutton驱动里init函数中的代码,在这里加载就可以。

HANDLE WINAPI PWR_Init(ULONG Identifier)
{
HMODULE hmCore;

// get pointers to APIs for shutting down the system -- this is only necessary if
// we are concerned that somebody might sysgen a version of the OS that doesn't
// contain the appropriate APIs.
gpfnSetSystemPowerState = NULL;
hmCore = (HMODULE) LoadLibrary(_T("coredll.dll"));
if(hmCore == NULL) 
return NULL;
gpfnSetSystemPowerState = (PFN_SetSystemPowerState) GetProcAddress(hmCore, _T("SetSystemPowerState"));
FreeLibrary(hmCore);

if (!PwrBtnSocInit(Identifier))
goto InitFailed;

g_hPwrBtnEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
g_hHTimerEvent = CreateEvent(NULL, FALSE, FALSE, NULL);//added by me///////////////////////////////////////////

g_hWaitAppCloseEvent = CreateEvent(NULL,FALSE,FALSE,PM_POWERBTN_WAIT_APP_CLOSE_EVENT);
if(g_hPwrBtnEvent == NULL || g_hWaitAppCloseEvent == NULL)
goto InitFailed;

if (!(InterruptInitialize(g_oalSysInfo.pwrbtnInfo.dwSysIntr, g_hPwrBtnEvent, NULL, 0))) 
{
DEBUGMSG(DBG_ATLAS_ZONE_INIT | DBG_ATLAS_ZONE_ERROR, (TEXT("PwrBUTTON INTR INIT Failed\r\n")));
goto InitFailed;
}

if(g_hPwrBtnThread == NULL)
{
g_hPwrBtnThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) PwrButtonIntrThread, NULL, 0, NULL);
if ( g_hPwrBtnThread == NULL) 
{
DEBUGMSG(DBG_ATLAS_ZONE_INIT | DBG_ATLAS_ZONE_ERROR, (TEXT("Fatal Error! Failed to create PwrButton threads.\r\n")));
goto InitFailed;

}

//////////////////////////////////////....added by me.......................
if (!(InterruptInitialize(SYSINTR_TIMER2, g_hHLTimerEvent, NULL, 0)))
{
RETAILMSG(1, (TEXT("SYSINTR_TIMER2 INTR INIT Failed\r\n")));
}
////////////////////////////////////................end..................

if (g_oalSysInfo.pwrbtnInfo.bCloseWmpOnSleep)
{
if (NULL == g_hCloseWmpEvent)
{
g_hCloseWmpEvent = CreateEvent(NULL,FALSE,FALSE,PM_POWERBTN_CLOSE_WMPLAYER_EVENT);
}
if (NULL == g_hCloseWmpThread)
{
g_hCloseWmpThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) CloseWmpThread, NULL, 0, NULL);
}
if (NULL == g_hCloseWmpEvent || NULL == g_hCloseWmpThread)
{
DEBUGMSG(DBG_ATLAS_ZONE_INIT | DBG_ATLAS_ZONE_ERROR, (TEXT("Fatal Error! Failed to create CloseWmpThread! r\n")));
goto InitFailed;
}
}

//create _T("SHARE_POWER_NOTIFY_EVENT") event, if sleep event come from extern force, will skip this time pwr
ghevNotifyEvent = CreateEvent(NULL, FALSE, FALSE, PM_POWER_NOTIFY_EVENT);
if(ghevNotifyEvent == NULL)
{
RETAILMSG(1,(TEXT("PWR_Init:: create ghevNotifyEvent failure\r\n")));
}

if ( !CeSetThreadPriority(g_hPwrBtnThread, ATLAS_THRDPRI_POWER))
{
DEBUGMSG(DBG_ATLAS_ZONE_INIT | DBG_ATLAS_ZONE_ERROR, (TEXT("Power Button ERROR: CeSetThreadPriority ERROR:%d\n"), GetLastError()));
goto InitFailed;
}


DEBUGMSG(DBG_ATLAS_ZONE_INIT, (TEXT("-PwrButton PWR Init\r\n")));
return g_hPwrBtnThread;

InitFailed:

PWR_Deinit(0);

return NULL;
}
--------------------------------------------
当加上红色的代码时就会出错,当然,我已经将SYSINTR_TIMER2和IRQ_TIMER2在[BSP]\kernel\oal\intr.c文件中的BSPIntrInit里静态连接上了。
这个事情困扰了好几天,还是没找出问题所在。



[解决办法]
g_hHTimerEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
InterruptInitialize(SYSINTR_TIMER2, g_hHLTimerEvent, NULL, 0)

是不是多打了一個 L??

Paul, Chao @ Techware


[解决办法]
LZ,你的这个g_hHTimerEvent在哪儿使用的呢?该不会是在PwrButtonIntrThread线程里WaitForSingleObject的吧?
如果是的话那InterruptInitialize肯定会失败了~

在InterruptInitialize之前,不能使用即将关联的事件!

[解决办法]
把下面调个位置看看
//////////////////////////////////////....added by me....................... 
if (!(InterruptInitialize(SYSINTR_TIMER2, g_hHLTimerEvent, NULL, 0))) 

RETAILMSG(1, (TEXT("SYSINTR_TIMER2 INTR INIT Failed\r\n"))); 

////////////////////////////////////................end.................. 


if(g_hPwrBtnThread == NULL) 

g_hPwrBtnThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) PwrButtonIntrThread, NULL, 0, NULL); 
if ( g_hPwrBtnThread == NULL) 

DEBUGMSG(DBG_ATLAS_ZONE_INIT | DBG_ATLAS_ZONE_ERROR, (TEXT("Fatal Error! Failed to create PwrButton threads.\r\n"))); 
goto InitFailed; 

}
[解决办法]

探讨
g_hHTimerEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
InterruptInitialize(SYSINTR_TIMER2, g_hHLTimerEvent, NULL, 0)

是不是多打了一個 L??

Paul, Chao @ Techware



[解决办法]
1. 在 %_TARGETPLATROOT%\src\kernel\oal\intr.c BSPIntrInit() 中加入
OALIntrStaticTranslate(SYSINTR_TIMER2, IRQ_TIMER2);



2. 用 
dwIRQ = IRQ_TIMER2;
KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwIRQ, sizeof(dwIRQ), &dwSysIntr, sizeof(dwSysIntr), NULL)
去取得 dwSysIntr, 再 InterruptInitialize(dwSysIntr, g_hHLTimerEvent, NULL, 0)


這 2 個方法皆是令 kernel 將 SysIntr 與 Irq 產生對應關係, 可擇一使用.

Paul, Chao @ Techware
[解决办法]
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwPhoneInterruptIrqID, sizeof(DWORD), &(g_dwSpeakerSwitch), sizeof(DWORD), NULL))
{
// invalid SDIO SYSINTR value!
RETAILMSG(1, (TEXT("Error obtaining MMC CD SYSINTR value!\n")));
g_dwSpeakerSwitch = SYSINTR_UNDEFINED;
return ERROR_INVALID_DATA;
}
 
if(!InterruptInitialize(g_dwSpeakerSwitch, g_SpeakerSwitchEvent, NULL, 0)) 
{
RETAILMSG( 1,( TEXT("AMPSwitchInit: InterruptInitialize ERROR!\r\n")));
return FALSE;
}

这是一段动态申请中断和初始化的代码,建议用动态,这样不会牵一发动全身,你参考一下

热点排行