DWORD io_12INTSysIntr=SYSINTR_PIO_CIR;
DWORD WINAPI AdsThread(LPVOID pArg){ //GPIO 中断线程
DWORD ret;
gWaitEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
if(!gWaitEvent){
RETAILMSG(1,(TEXT("Create AdsThread Event error\r\n")));
return 0;
}
RETAILMSG(1,(TEXT(":::Create ads IO_INTR SYSINTR_PIO_CIR %x\n"),SYSINTR_PIO_CIR));
if ( !(InterruptInitialize(io_12INTSysIntr,gWaitEvent,0,0))){
RETAILMSG(1,(TEXT("ERROR:EINT:InterruptInitialize failed.\r\n")));
CloseHandle(gWaitEvent);
return 0;
}
else {
RETAILMSG(1,(TEXT(":::Create ads IO_INTR link ok\r\n")));
}
while(1){
ret = WaitForSingleObject(gWaitEvent,INFINITE);
RETAILMSG(1,(TEXT(":::EINT_IntrThread 0gpio12.\r\n")));
if (ret == WAIT_OBJECT_0){
RETAILMSG(1,(TEXT(":::EINT_IntrThread gpio12.\r\n")));
}
else {
// CloseHandle(gWaitEvent);
RETAILMSG(1,(TEXT(":::EINT_IntrThread Exit.\r\n")));
return 0;
}
InterruptDone(io_12INTSysIntr);
}
return 0;
}
HANDLE ADS_Init(DWORD dwContext)
{
DWORD dwRet=1;
volatile UINT32 *p2;
HANDLE hNewThread;
DWORD IDThread;
RETAILMSG(1,(TEXT("STRINGS:ADS_Init\n")));
v_pIOPRegs =(volatile IOPreg*)VirtualAlloc(0, sizeof(IOPreg),
MEM_RESERVE, PAGE_NOACCESS);
RETAILMSG(1,(L":::VirtualAlloc reservation @%8.8lx\r\n", v_pIOPRegs));
// the lenth is 0xf0000,why?
if(v_pIOPRegs == NULL)
{
RETAILMSG (1,(TEXT( "v_pIOPRegs is not allocated\n\r ")));
return 0;
}
// RETAILMSG(1,(L"recv data count %d\r\n",sizeof(IOPreg)));
if(!VirtualCopy((PVOID)v_pIOPRegs, (PVOID)(IOP_BASE>>8),
sizeof(IOPreg), PAGE_READWRITE|PAGE_NOCACHE| PAGE_PHYSICAL) )
{
RETAILMSG (1,(TEXT( "v_pIOPRegs is not mapped\n\r ")));
return 0;
}
RETAILMSG(1,(TEXT( ":::v_pIOPRegs is mapped to %x\n\r "), v_pIOPRegs));
// p2=&v_pIOPRegs->PBDDR;//设为输入端
// *p2=0xef;
// v_pIOPRegs->GPIOBIntEn=0x10;//GPIO12 中断
// v_pIOPRegs->GPIOBIntType1=0x10;//edge 触发
// v_pIOPRegs->GPIOBIntType2=0x10;//上升沿触发
//v_pIOPRegs->GPIOBEOI ?
hNewThread=CreateThread(NULL,0,AdsThread,NULL,0,&IDThread);
RETAILMSG(1,(L":::ADS handle=%I64u\r\n",hNewThread));
if(!hNewThread){
RETAILMSG(1,(TEXT(":::Create AdsThread error\r\n")));
return 0;
}
return hNewThread;
}