|
驱动层部分代码
- /////////////////////////////////////////////////////////////////////
- //=============================================================================
- //Title : xxx_IntrThread
- //Detail: Receive INTR EVENT from gpio for xxx communication
- //Input : PVOID pArg
- //Output: DWORD
- //Author: Mercury
- //Data : 2009-12-26
- //=============================================================================
- DWORD xxx_DetectThread(PVOID pArg)
- {
- //变量定义
- //Sleep(1);
- while (1)
- {
- dwRet = WaitForMultipleObjects(2, rghEvents, FALSE, INFINITE);
- if(pMcuCtl->bDeinit) {
-
- return 0;
- }
- switch(dwRet) {
- case WAIT_OBJECT_0:
- RETAILMSG(1, (TEXT("mcu_DetectThread Wait deinit\r\n")));
- //deinit event
- return 0;
- break;
-
- case WAIT_OBJECT_0+1:
- OperationCS8953(READ, &sendOut[0], 2);
- #if 1
- RETAILMSG(1,(TEXT("the %d number SentOut Value for point variable is %x\r\n"),i,sendOut[i]));
- #endif
- SetEvent(gReadKeyEvent[0]); /* 通知读函数, 外部中断产生 */
- }
- break;
- default:
- //error
- dwAction = 0x00;//MCU_STAT_NOCHANGE;
- break;
- }
- //do real action
- }
- return 0;
- }
- extern "C" DWORD XXX_Init(DWORD Index)
- {
- RETAILMSG(1,(TEXT("++XXX_Init!\r\n ")));
- //事件创建部分。。省略部分代码
- pXXXCtl->hDetectThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) XXX_DetectThread, (LPVOID)pXXXCtl, 0, &IDThread);
- if (pXXXCtl->hDetectThread == 0)
- {
- RETAILMSG(1,(TEXT("XXX_Init::: CreateThread Failed\r\n")));
- goto Error;
- }
- //初始化中断 。。省略部分代码
- return(DWORD)pXXXCtl;
-
- Error:
- (VOID)XXX_Deinit((DWORD)pXXXCtl);
- RETAILMSG(1,(TEXT("--error !XXX_Init!\r\n ")));
- #endif
- return(0);
- }
- extern "C" DWORD xxx_Read(DWORD dwData,
- LPVOID pBuf,
- DWORD Len)
- {
- DWORD ret;
- unsigned char *pReadBuffer = NULL;
- if ((pBuf == NULL) || (Len <= 0))
- return 0;
- pReadBuffer = (unsigned char *)MapPtrToProcess(pBuf, GetCallerProcess());
- *pReadBuffer = NULL;
-
- ret = WaitForMultipleObjects(2, gReadKeyEvent, FALSE, INFINITE);
- if (ret == WAIT_OBJECT_0)
- {
- ResetEvent(gReadKeyEvent[0]);
- *pReadBuffer = sendOut[0];
- RETAILMSG(1,(TEXT("READ EFFECT VALUE!\r\n")));/* 获取有效值 */
- //return 1;
- }
- else if(ret == (WAIT_OBJECT_0 + 1))
- {
- ResetEvent(gReadKeyEvent[1]);
- RETAILMSG(1,(TEXT("OUT\r\n")));/* 驱动关闭 */
- //return 1;
- }
- return(0);
- }
复制代码 |
|