请教WINCE驱动问题
因为要用到一个中断,下降沿触发,所以自己尝试着写了一个中断驱动,运行起来没有什么问题,就是在关掉应用程序后再次打开应用程序后中断程序能进去,但是下降沿再也没有什么反应了:初始化函数如下:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD XPI_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
RETAILMSG(1,(TEXT("************: XPI_OPEN***********\r\n")));
g_pGPIOReg = (volatile GPIO_REG*)DrvLib_MapIoSpace(BASE_REG_PA_GPIO, sizeof(GPIO_REG), FALSE);
if (g_pGPIOReg == NULL) {
RETAILMSG(TRUE, (TEXT(":VirtualAlloc GPIO failed!\r\n")));
}
g_pGPIOReg->GPH0.GP_CON &= 0xfffffff0;
g_pGPIOReg->GPH0.GP_CON |= 0x0000000F;//set the pin EXT_INIT
g_pGPIOReg->GPH0.GP_PUD &= 0xfffffffc;//
g_pGPIOReg->GPH0.GP_PUD |= 0x00000002;//pull-up enable
g_pGPIOReg->EINTCON.EXT_INT0_CON &= 0xfffffff0;
g_pGPIOReg->EINTCON.EXT_INT0_CON |= 0x00000002;//falling edge trigered
g_pGPIOReg->EINTFLT.EXT_FLT0_CON._FLT_CON0 &= 0xffffff00;
g_pGPIOReg->EINTFLT.EXT_FLT0_CON._FLT_CON0 |= 0x000000c0;//enable delay filter
g_pGPIOReg->EINTMSK.EXT_INT0_MASK &= 0xffffffe;//enable interrupt
g_pGPIOReg->EINTPND.EXT_INT0_PEND &= 0xffffffE;
g_pGPIOReg->EINTPND.EXT_INT0_PEND |= 0x00000001;
//
m_interruptPhyId = IRQ_EINT0;
if(!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &m_interruptPhyId, sizeof(DWORD), &m_interruptSysId, sizeof(DWORD), NULL))
{
RETAILMSG(1, (TEXT("*************kernelIoControl fail\r\n")));
m_interruptSysId = SYSINTR_UNDEFINED;
return FALSE;
}
m_interruptEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(INVALID_HANDLE_VALUE == m_interruptEvent)
{
RETAILMSG(1, (TEXT(":Create m_interruptEvent fail\r\n")));
return FALSE;
}
m_interruptThread=CreateThread(NULL, //Security
0, //No Stack Size
(LPTHREAD_START_ROUTINE)Threadproc,//Interrupt Thread
NULL, //No Parameters
CREATE_SUSPENDED, //Create Suspended
lpThreadId);//Thread Id
//set the thread priority
threadpriority = 6;
if( !CeSetThreadPriority( m_interruptThread, threadpriority))
{
RETAILMSG(1,(TEXT("test: Failed setting Thread Priority.\r\n")));
return FALSE;
}
if (!InterruptInitialize(m_interruptSysId,m_interruptEvent,NULL,0))
{
ERRORMSG( 1, (TEXT("test interrupt is not initialized\n\r")));
return(FALSE);
}
//translate the event handle
hEventRecev=CreateEvent(NULL,FALSE,FALSE,_T("XPIReadEvent"));//2??§3?±?D??aNULL,ê?·?è?1¤????£?ê?·?3?ê??ˉ?aí¨?a×′ì?£?Event??×?
if(INVALID_HANDLE_VALUE == hEventRecev)
{
RETAILMSG(1, (TEXT(":Create hEventRecev failed\r\n")));
return FALSE;
}
m_ExitThread = FALSE;
RETAILMSG(1,(TEXT(":ResumeThread***********\r\n")));
ResumeThread(m_interruptThread);
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////////
上面就是创建了一个中断关联的等待线程。然后等待线程如下:
///////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI Threadproc(LPVOID lpvParam)
{
DWORDdwStatus=0;
BOOLfState = TRUE;
static BOOL count = TRUE;
RETAILMSG(1,(TEXT(":Entry test thread \r\n")));
while (!m_ExitThread)
{
dwStatus = WaitForSingleObject(m_interruptEvent,INFINITE);
if (m_ExitThread)
{
RETAILMSG(1,(TEXT(":break the thread!***********\r\n")));
break;
}
switch(dwStatus)
{
case WAIT_FAILED:
RETAILMSG(1,(TEXT(":Wait Failed!***********\r\n")));
break;
case WAIT_TIMEOUT:
RETAILMSG(1,(TEXT(":Wait time out!***********\r\n")));
break;
case WAIT_OBJECT_0+0:
SetEvent(hEventRecev);
RETAILMSG(1,(TEXT(":DAB_NXP request the communication!***********\r\n")));
break;
case WAIT_OBJECT_0+1:
RETAILMSG(1,(TEXT(":Wait Canceled!***********\r\n")));
return TRUE;
break;
}
///////////////////////////////////////////////
//////////////////////////////////////////////////
InterruptDone(m_interruptSysId);
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
关闭函数如下
/////////////////////////////////////////////////////////////////////////////////////////////////
BOOL XPI_Close(DWORD hOpenContext)
{
RETAILMSG(1,(TEXT(": XPI_CLOSE***********\r\n")));
m_ExitThread = TRUE;
SetEvent(m_interruptEvent);
if (WaitForSingleObject(m_interruptThread,2000) == WAIT_TIMEOUT)
{
TerminateThread(m_interruptThread,0);
RETAILMSG(1,(TEXT(": force to quite the thread***********\r\n")));
}
m_interruptThread = NULL;
CloseHandle(m_interruptEvent);//ó2?t?D??ó3é?μ??μí3?D??
CloseHandle(hEventRecev);//′?μY??ó|ó?3ìDòó?
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
第一次运行应用程序那个线程可以进去,下降沿也可以触发WaitForSingleObject返回,但是关闭之后第二次运行应用程序,驱动中也可以进入该线程中,但是下降沿却始终无法触发WaitForSingleObject返回,请教一下大家,是不是在close或是Deinit时还有什么没有做的操作啊?
页:
[1]