Example #1
0
BOOL
PWR_PowerUp(DWORD pContext)
{
	PWRBTN_INF((_T("[PWR] PWR_PowerUp(0x%08x)\r\n"), pContext));

	// Do not Disable Interrupt for Power Bottun
	// Also Do not Clear Pending.
	// After Wake Up. Button Driver Should Get Interrupt
	// and Set System Power State to Resume...
	// Interrupt Disable
	Button_pwrbtn_disable_interrupt();
	//Button_rstbtn_disable_interrupt();

	// Port Initialize as External Interrupt
	Button_port_initialize();

	// Interrupt Siganl Method and Filtering
	Button_pwrbtn_set_interrupt_method(EINT_SIGNAL_RISE_EDGE);
	Button_pwrbtn_set_filter_method(EINT_FILTER_DELAY, 0);
	//Button_rstbtn_set_interrupt_method(EINT_SIGNAL_FALL_EDGE);
	//Button_rstbtn_set_filter_method(EINT_FILTER_DELAY, 0);

	// Clear Interrupt Pending
	Button_pwrbtn_clear_interrupt_pending();
	//Button_rstbtn_clear_interrupt_pending();

	// Enable Interrupt
	Button_pwrbtn_enable_interrupt();
	//Button_rstbtn_enable_interrupt();

	return TRUE;
}
Example #2
0
BOOL
PWR_PowerDown(DWORD pContext)
{
	PWRBTN_INF((_T("[PWR] PWR_PowerDown(0x%08x)\r\n"), pContext));

	// Interrupt Disable and Clear Pending
	Button_pwrbtn_disable_interrupt();
	Button_pwrbtn_clear_interrupt_pending();
	Button_rstbtn_disable_interrupt();
	Button_rstbtn_clear_interrupt_pending();

	return TRUE;
}
INT WINAPI PowerButtonThread(void)
{
	DWORD nBtnCount = 0;

	PWRBTN_INF((_T("[PWR:INF] ++PowerButtonThread()\r\n")));

	while(!g_bExitThread)
	{
		WaitForSingleObject(g_hEventPowerBtn, INFINITE);

		if(g_bExitThread)
		{
			break;
		}

		Button_pwrbtn_disable_interrupt();			// Mask EINT
		Button_pwrbtn_clear_interrupt_pending();		// Clear Interrupt Pending

		InterruptDone(g_dwSysIntrPowerBtn);

		while(Button_pwrbtn_is_pushed())
		{
			// Wait for Button Released...
			Sleep(10);
		}

		nBtnCount++;
		PWRBTN_INF((_T("[PWR] Power Button Event [%d]\r\n"), nBtnCount));

		//PowerPolicyNotify(PPN_POWERBUTTONPRESSED,0);
		SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE);

		Button_pwrbtn_enable_interrupt();			// UnMask EINT
	}

	PWRBTN_INF((_T("[PWR:INF] --PowerButtonThread()\r\n")));

	return 0;
}
Example #4
0
BOOL PWR_Deinit(DWORD pContext)
{
	PWRBTN_MSG((_T("[PWR] ++PWR_Deinit(0x%08x)\r\n"), pContext));

	g_bExitThread = TRUE;

	if (g_hThreadPowerBtn)		// Make Sure if thread is exist
	{
		Button_pwrbtn_disable_interrupt();
		Button_pwrbtn_clear_interrupt_pending();

		// Signal Thread to Finish
		SetEvent(g_hEventPowerBtn);
		// Wait for Thread to Finish
		WaitForSingleObject(g_hThreadPowerBtn, INFINITE);
		CloseHandle(g_hThreadPowerBtn);
		g_hThreadPowerBtn = NULL;
	}

	if (g_hThreadResetBtn)		// Make Sure if thread is exist
	{
		Button_rstbtn_disable_interrupt();
		Button_rstbtn_clear_interrupt_pending();

		// Signal Thread to Finish
		SetEvent(g_hEventResetBtn);
		// Wait for Thread to Finish
		WaitForSingleObject(g_hThreadResetBtn, INFINITE);
		CloseHandle(g_hThreadResetBtn);
		g_hThreadResetBtn = NULL;
	}

	PWR_ReleaseResources();

	PWRBTN_MSG((_T("[PWR] --PWR_Deinit()\r\n")));

	return TRUE;
}
Example #5
0
INT WINAPI PowerButtonThread(void)
{
	DWORD nBtnCount = 0;
	WCHAR  state[1024] = {0};
	LPWSTR pState = &state[0];
	DWORD dwBufChars = (sizeof(state) / sizeof(state[0]));
	DWORD  dwStateFlags = 0;
	DWORD dwErr;

	PWRBTN_INF((_T("[PWR:INF] ++PowerButtonThread()\r\n")));

	while(!g_bExitThread)
	{
		WaitForSingleObject(g_hEventPowerBtn, INFINITE);

		if(g_bExitThread)
		{
			break;
		}

		Button_pwrbtn_disable_interrupt();			// Mask EINT
		Button_pwrbtn_clear_interrupt_pending();		// Clear Interrupt Pending

		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));
		}

		InterruptDone(g_dwSysIntrPowerBtn);

#ifndef    SLEEP_AGING_TEST
		while(Button_pwrbtn_is_pushed())
		{
			// Wait for Button Released...
			Sleep(10);
		}
#endif

		nBtnCount++;
		PWRBTN_INF((_T("[PWR] Power Button Event [%d]\r\n"), nBtnCount));

		//SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE);
		//PowerPolicyNotify(PPN_POWERBUTTONPRESSED,0);

		if ( wcscmp(state,TEXT("screenoff")) == 0 )
		{
			RETAILMSG(1,(TEXT("setsystempowerstate to ON from screen off\r\n")));
			SetSystemPowerState( NULL, POWER_STATE_ON, POWER_FORCE );
		}
		else if ( wcscmp(state,TEXT("backlightoff")) == 0 )
		{

		#ifdef WPC
			RETAILMSG(1,(TEXT("setsystempowerstate to ON from backlight off\r\n")));
			SetSystemPowerState( NULL, POWER_STATE_ON, POWER_FORCE );
		#endif
		#ifdef SMARTFON
		  	 RETAILMSG(1,(TEXT("setsystempowerstate to IDLE from backlight off\r\n")));
			SetSystemPowerState( TEXT("useridle"), POWER_STATE_IDLE, POWER_FORCE );
		#endif
		}
		else
		{
		#ifdef WPC
			//SetSystemPowerState( NULL, POWER_STATE_SUSPEND, POWER_FORCE );
			PowerPolicyNotify(PPN_POWERBUTTONPRESSED,0);
		#endif
		#ifdef SMARTFON
			RETAILMSG(1,(TEXT("setsystempowerstate to IDLE from on\r\n")));
			SetSystemPowerState( TEXT("useridle"), POWER_STATE_IDLE, POWER_FORCE );
		#endif
		}

		Button_pwrbtn_enable_interrupt();			// UnMask EINT
#ifdef    SLEEP_AGING_TEST
        Sleep(2000);
        SetEvent(g_hEventPowerBtn);
#endif
	}

	PWRBTN_INF((_T("[PWR:INF] --PowerButtonThread()\r\n")));

	return 0;
}
Example #6
0
DWORD
PWR_Init(DWORD dwContext)
{
	PWRBTN_MSG((_T("[PWR] ++PWR_Init(0x%08x)\r\n"), dwContext));

	if (PWR_AllocResources() == FALSE)
	{
		PWRBTN_ERR((_T("[PWR:ERR] PWR_Init() : PWR_AllocResources() Failed \n\r")));

		goto CleanUp;
	}

	Button_initialize_register_address((void *)g_pGPIOReg);

	// Interrupt Disable and Clear Pending
	Button_pwrbtn_disable_interrupt();
	//Button_rstbtn_disable_interrupt();

	// Initialize Port as External Interrupt
	Button_port_initialize();

	// Create Power Button Thread
	g_hThreadPowerBtn = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) PowerButtonThread, NULL, 0, NULL);
	if (g_hThreadPowerBtn == NULL )
	{
		PWRBTN_ERR((_T("[PWR:ERR] PWR_Init() : CreateThread() Power Button Failed \n\r")));
		goto CleanUp;
	}

	// Create Reset Button Thread
//	g_hThreadResetBtn = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ResetButtonThread, NULL, 0, NULL);
//	if (g_hThreadResetBtn == NULL )
//	{
//		PWRBTN_ERR((_T("[PWR:ERR] PWR_Init() : CreateThread() Reset Button Failed \n\r")));
//		goto CleanUp;
//	}

	// Interrupt Siganl Method and Filtering
	Button_pwrbtn_set_interrupt_method(EINT_SIGNAL_RISE_EDGE);
	Button_pwrbtn_set_filter_method(EINT_FILTER_DELAY, 0);
	//Button_rstbtn_set_interrupt_method(EINT_SIGNAL_FALL_EDGE);
	//Button_rstbtn_set_filter_method(EINT_FILTER_DELAY, 0);

	// Clear Interrupt Pending
	Button_pwrbtn_clear_interrupt_pending();
	//Button_rstbtn_clear_interrupt_pending();

	// Enable Interrupt
	Button_pwrbtn_enable_interrupt();
	//Button_rstbtn_enable_interrupt();

	PWRBTN_MSG((_T("[PWR] --PWR_Init()\r\n")));

	return TRUE;

CleanUp:

	PWRBTN_ERR((_T("[PWR:ERR] --PWR_Init() : Failed\r\n")));

	PWR_Deinit(0);

	return FALSE;
}