/*******************************/
DWORD PBT_IntrThread(PVOID pArg)
{
DWORD ret;
//PBT_InitializeAddresses();
//PBT_EnableInterrupt();
gPwrButtonIntrEvent[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
gPwrButtonIntrEvent[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
gPwrButtonIntrEvent[2] = CreateEvent(NULL, FALSE, FALSE, NULL);
gPwrButtonIntrEvent[3] = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!(InterruptInitialize(g_PwrButtonSysIntr, gPwrButtonIntrEvent[0], 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gPwrButtonIntrEvent[0]);
return 0;
}
if (!(InterruptInitialize(g_Key2SysIntr, gPwrButtonIntrEvent[1], 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gPwrButtonIntrEvent[1]);
return 0;
}
if (!(InterruptInitialize(g_Key3SysIntr, gPwrButtonIntrEvent[2], 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gPwrButtonIntrEvent[2]);
return 0;
}
if (!(InterruptInitialize(g_Key4SysIntr, gPwrButtonIntrEvent[3], 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gPwrButtonIntrEvent[3]);
return 0;
}
while (1)
{
//ret = WaitForSingleObject(gPwrButtonIntrEvent, INFINITE);
//ret = WaitForMultipleObjects(gPwrButtonIntrEvent, INFINITE);
ret = WaitForMultipleObjects(4,gPwrButtonIntrEvent,FALSE,INFINITE);
//if((ret==WAIT_OBJECT_0)&&(g_bKillIST==FALSE ))
switch(ret)
{
case WAIT_OBJECT_0: //按键1
if(PBT_IsPushed()==1)
{
Sleep(20);
if(PBT_IsPushed()==1)
{
SetEvent(gReadKeyEvent[0]);
RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
}
InterruptDone(g_PwrButtonSysIntr);
RETAILMSG(1, (TEXT("The Eint0 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case WAIT_OBJECT_0+1:
if(PBT_IsPushed()==2)
{
Sleep(20);
if(PBT_IsPushed()==2)
{
SetEvent(gReadKeyEvent[1]);
}
}
InterruptDone(g_Key2SysIntr);
RETAILMSG(1, (TEXT("The Eint1 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case WAIT_OBJECT_0+2:
if(PBT_IsPushed()==4)
{
Sleep(20);
if(PBT_IsPushed()==4)
{
SetEvent(gReadKeyEvent[2]);
//RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
}
InterruptDone(g_Key3SysIntr);
RETAILMSG(1, (TEXT("The Eint2 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case WAIT_OBJECT_0+3:
if(PBT_IsPushed()==8)
{
Sleep(20);
if(PBT_IsPushed()==8)
{
SetEvent(gReadKeyEvent[3]);
//RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
}
InterruptDone(g_Key4SysIntr);
RETAILMSG(1, (TEXT("The Eint4 is Done!!!!!!!LTH~~~~~\r\n")));
break;
default:
CloseHandle(gPwrButtonIntrEvent[0]);
CloseHandle(gPwrButtonIntrEvent[1]);
CloseHandle(gPwrButtonIntrEvent[2]);
CloseHandle(gPwrButtonIntrEvent[3]);
return 0;
}
}
return 1;
}
总是返回WAIT_OBJECT_0??????????为什么啊??我用多个外部中断关联到这个IST上,这样做有问题吗?
你的上个帖子我已经说过,WaitForMultipleObjects不能用于等待经过InterruptInitialize处理的事件。
可以将多个中断关联到同一个事件,然后使用WaitForSingleObject,在中断程序中判断是哪个中断过来的,然后再进行相应的处理。
帮顶,Veabol正解。。。
LZ想了解WaitForMultipleObjects,不妨看看背光驱动,比较典型
引用: 引用 1 楼 veabol 的回复:
你的上个帖子我已经说过,WaitForMultipleObjects不能用于等待经过InterruptInitialize处理的事件。
可以将多个中断关联到同一个事件,然后使用WaitForSingleObject,在中断程序中判断是哪个中断过来的,然后再进行相应的处理。
背光、触摸屏驱动都是典型例子。呵呵
需要将你的按键按下的中断和事件绑定。
http://www.cnblogs.com/we-hjb/archive/2009/05/26/1490461.html
这篇文章推荐过很多次了。。很好的中断开发入门文章
http://www.cnblogs.com/we-hjb/archive/2009/05/26/1490461.html
再说一句,,这个文章中IST的介绍已经说的很详细了。LZ可以参考的
/*******************************/
DWORD PBT_IntrThread(PVOID pArg)
{
DWORD ret;
//PBT_InitializeAddresses();
//PBT_EnableInterrupt();
// gPwrButtonIntrEvent[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
// gPwrButtonIntrEvent[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
// gPwrButtonIntrEvent[2] = CreateEvent(NULL, FALSE, FALSE, NULL);
// gPwrButtonIntrEvent[3] = CreateEvent(NULL, FALSE, FALSE, NULL);
gKeyWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
//多个中断关联到一个事件上
if (!(InterruptInitialize(g_Key1SysIntr, gKeyWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gKeyWaitEvent);
return 0;
}
if (!(InterruptInitialize(g_Key2SysIntr, gKeyWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gKeyWaitEvent);
return 0;
}
if (!(InterruptInitialize(g_Key3SysIntr, gKeyWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gKeyWaitEvent);
return 0;
}
if (!(InterruptInitialize(g_Key4SysIntr, gKeyWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gKeyWaitEvent);
return 0;
}
while (1)
{
ret = WaitForSingleObject(gKeyWaitEvent, INFINITE);
//ret = WaitForMultipleObjects(gPwrButtonIntrEvent, INFINITE);
//ret = WaitForMultipleObjects(4,gPwrButtonIntrEvent,FALSE,INFINITE);
if((ret==WAIT_OBJECT_0)&&(g_bKillIST==FALSE ))
{
switch(PBT_IsPushed())
{
case 1: //按键1
//if(PBT_IsPushed()==1)
Sleep(20);
if(PBT_IsPushed()==1)
{
SetEvent(gReadKeyEvent[0]);
RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
InterruptDone(g_Key1SysIntr);
RETAILMSG(1, (TEXT("The Eint0 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case 2:
//if(PBT_IsPushed()==2)
{
Sleep(20);
if(PBT_IsPushed()==2)
{
SetEvent(gReadKeyEvent[1]);
}
}
InterruptDone(g_Key2SysIntr);
RETAILMSG(1, (TEXT("The Eint1 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case 3:
//if(PBT_IsPushed()==4)
{
Sleep(20);
if(PBT_IsPushed()==3)
{
SetEvent(gReadKeyEvent[2]);
//RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
}
InterruptDone(g_Key3SysIntr);
RETAILMSG(1, (TEXT("The Eint2 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case 4:
//if(PBT_IsPushed()==8)
{
Sleep(20);
if(PBT_IsPushed()==4)
{
SetEvent(gReadKeyEvent[3]);
//RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
}
InterruptDone(g_Key4SysIntr);
RETAILMSG(1, (TEXT("The Eint4 is Done!!!!!!!LTH~~~~~\r\n")));
break;
default:
//CloseHandle(gPwrButtonIntrEvent[0]);
//CloseHandle(gPwrButtonIntrEvent[1]);
//CloseHandle(gPwrButtonIntrEvent[2]);
//CloseHandle(gPwrButtonIntrEvent[3]);
break;
}
}
else {
CloseHandle(gKeyWaitEvent);
return 0;
}
}
return 1;
}
}
我把多个中断关联到一个事件上,刚开始4个按键都能用,按几下有的就不能用了,最后甚至都不能用?为什么啊?是不是哪儿没有释放?
检测出哪个中断之后清一下相应的PND之类的位试试。
你这样在每个case下面进行interruptDone,可能存在当多个key同时按下的时候,有可能会漏掉。
试试在最后面,将中断都clear一下。
InterruptDone(g_Key1SysIntr);
InterruptDone(g_Key2SysIntr);
InterruptDone(g_Key3SysIntr);
InterruptDone(g_Key4SysIntr);
感谢各位热心帮忙,这个问题分比较少,要结贴了,虽然有的兄弟没有得分,偶心里依然感激,呵呵 *eeworld热心的朋友不少