阅读:3802回复:4
请教wince-lover个问题,关于button的
我的按键中的中断是和s3c2440a的eint0口相接。处理代码如下,在PWR_IST中如果要实现一按按键后,PWR_IST接到中断后执行唤醒功能,应该如何在PWR_IST添加代码?还有就是GetSystemPowerState是如何得到当前电源的状态的?POWER_STATE(dwStateFlags)是如何知道当前电源的状态的
PPWR_CONTEXT PWR_Init(PVOID Context) { if ( (pPWR->ISTEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) != NULL) { if( InterruptInitialize(SYSINTR_POWER, pPWR->ISTEvent, NULL, 0) ) { if ( (pPWR->IST = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) PWR_IST, pPWR, 0, NULL)) != NULL) { ...... } } } } static DWORD PWR_IST(PPWR_CONTEXT pPWR) { int CurrStatus = RUN; DWORD we; WCHAR state[1024] = {0}; LPWSTR pState = &state[0]; DWORD dwBufChars = (sizeof(state) / sizeof(state[0])); DWORD dwStateFlags = 0; DWORD dwErr; if (!pPWR) return ERROR_INVALID_PARAMETER; while (1) { __try { we = WaitForSingleObject(pPWR->ISTEvent, INFINITE); RETAILMSG(1,(TEXT("\r\nPWR_IST: pPWR->State = 0x%x \r\n"), pPWR->State)); //#define GetSystemPowerState WIN32_DEV_CALL(DWORD, 18, (LPCWSTR pBuffer, DWORD Length, PDWORD pFlags)) dwErr = GetSystemPowerState(pState, dwBufChars, &dwStateFlags); if (ERROR_SUCCESS != dwErr) { RETAILMSG(1, (TEXT("PMGET!GetSystemPowerState:ERROR:%d\n"), dwErr)); } else { RETAILMSG(1, (TEXT("PMGET! System Power state is '%s', flags 0x%08x\n"), state, dwStateFlags)); switch (POWER_STATE(dwStateFlags)) { case POWER_STATE_ON: break; case POWER_STATE_OFF: break; case POWER_STATE_CRITICAL: break; case POWER_STATE_BOOT: break; case POWER_STATE_IDLE: break; case POWER_STATE_SUSPEND: break; case POWER_STATE_RESET: break; case 0: break; default: break; } } switch (pPWR->State) { case RUN: RETAILMSG(1, (TEXT("PWR_IST: RUN\r\n"))); if (CurrStatus == SUSPEND) { pPWR->State = RUN; CurrStatus = RUN; InterruptDone(SYSINTR_POWER); SetSystemPowerState( NULL, POWER_STATE_ON, POWER_FORCE ); continue; } else if (CurrStatus == RESUME) { if ( wcscmp(state,TEXT("unattended")) == 0 ) { RETAILMSG(1, (TEXT("Unattended Power Off Mode\r\n"))); pPWR->State = RUN; CurrStatus = SUSPEND; continue; } else { pPWR->State = RUN; CurrStatus = RUN; InterruptDone(SYSINTR_POWER); SetSystemPowerState( NULL, POWER_STATE_ON, POWER_FORCE ); continue; } //else if ( wcscmp(state,TEXT("resuming")) == 0 ) //{ //RETAILMSG(1, (TEXT("Still resuming...\r\n"))); //Sleep(1000); //SetEvent(pPWR->ISTEvent); //continue; //} } break; case INITIALIZE: // Keep from reading our clear on read INTx registers // during init. RETAILMSG(1, (TEXT("PWR_IST: INITIALIZE\r\n"))); Sleep(10); continue; break; case SUSPEND: RETAILMSG(1, (TEXT("PWR_IST: SUSPEND\r\n"))); //continue; break; case RESUME: continue; break; case ADC_ERROR: RETAILMSG(1,(TEXT("PWR_IST: %s \r\n"), pPWR->State == RESUME ? L"RESUME" : L"ADC_ERROR" )); pPWR->State = RUN; CurrStatus = RESUME; // clear any potential pending ADC interrupt InterruptDone(SYSINTR_POWER); Sleep(200); SetEvent(pPWR->ISTEvent); //SetSystemPowerState( NULL, POWER_STATE_ON, POWER_FORCE ); continue; break; case UNINITIALIZED: RETAILMSG(1,(TEXT("PWR_IST: ExitThread \r\n"))); ExitThread(ERROR_SUCCESS); return ERROR_SUCCESS; default: RETAILMSG(1,(TEXT("PWR_IST: unknown state: %u\r\n"), pPWR->State)); TEST_TRAP; continue; break; } // // get status // // EnterCriticalSection(&pPWR->RegCS); // // if ( !pPWR->ResetRegReady ) { // } else { // // get & restore the cleared registers // pPWR->ResetRegReady = FALSE; // } LeaveCriticalSection(&pPWR->RegCS); // clear the interrupt before power off InterruptDone(SYSINTR_POWER); CurrStatus = SUSPEND; SetSystemPowerState( NULL, POWER_STATE_SUSPEND, POWER_FORCE ); } _except(EXCEPTION_EXECUTE_HANDLER) { RETAILMSG(1,(TEXT("!!! PWR_IST EXCEPTION: 0x%X !!!\r\n"), GetExceptionCode() )); } } } |
|
沙发#
发布于:2007-04-11 21:54
执行唤醒,不需要在PWR_IST中添加代码.系统的挂起和唤醒是在OEMPowerOff这个函数中实现的.POWER_STATE(dwStateFlags)我也不清楚,你查查帮助吧.
|
|
板凳#
发布于:2007-04-13 17:50
引用第0楼lgsspku于2007-04-11 16:40发表的“请教wince-lover个问题,关于button的”: 你现在是不能唤醒系统吗? |
|
地板#
发布于:2009-02-16 18:43
请问wince_lover,我的中断处理程序和楼主的一样,现在能休眠,但是不能唤醒系统,应该怎样修改
|
|
地下室#
发布于:2010-02-04 18:03
请教一下wince_lover兄,我看了你07年的一个帖子关于电池驱动和触摸屏互斥的?你如何解决的2个驱动之间的句柄共享问题?下面这段代码
在DdsiTouchPanelEnable函数中增加 if(ghBattTouchMutex == NULL ) { ghBattTouchMutex = CreateMutex( NULL, FALSE, BATTERY_TOUCH_MUTEX ); } 在PddpTouchPanelDeallocateVm函数中增加 if(ghBattTouchMutex) { CloseHandle( ghBattTouchMutex ); ghBattTouchMutex = NULL ; } 在DdsiTouchPanelGetPoint函数中读触摸屏采样之前加上 if(ghBattTouchMutex ) { WaitForSingleObject(ghBattTouchMutex, 5000); } 在读完之后加上 if(ghBattTouchMutex ) { ReleaseMutex(ghBattTouchMutex); } 其中ghBattTouchMutex需要在2个驱动之间共享,这一点如何解决的,谢谢先,呵呵 |
|