Example #1
0
INT WINAPI ResetButtonThread(void)
{
	PWRBTN_INF((_T("[PWR:INF] ++ResetButtonThread()\r\n")));

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

		if(g_bExitThread)
		{
			break;
		}

		Button_rstbtn_disable_interrupt();			// Mask EINT
		Button_rstbtn_clear_interrupt_pending();		// Clear Interrupt Pending

		InterruptDone(g_dwSysIntrResetBtn);

		PWRBTN_INF((_T("[PWR] Reset Button Event\r\n")));

		SetSystemPowerState(NULL, POWER_STATE_RESET, POWER_FORCE);
		//KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);

		PWRBTN_ERR((_T("[PWR:ERR] Soft Reset Failed\r\n")));

		Button_rstbtn_enable_interrupt();				// UnMask EINT
	}

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

	return 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_FALL_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 #3
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;
}
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;
}
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_FALL_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;
}