⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 power_control.c

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 C
📖 第 1 页 / 共 2 页
字号:
		PWRCON_MSG((_T("[PWRCON] DllMain() : Process Attach\r\n")));
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		PWRCON_MSG((_T("[PWRCON] DllMain() : Process Detach\r\n")));
	}

	return TRUE;
}

BOOL PWC_Deinit(DWORD pContext)
{
	PWRCON_MSG((_T("[PWRCON] ++PWC_Deinit(0x%08x)\r\n"), pContext));

	g_bExitThread = TRUE;

	if (g_hThreadPowerMon)		// Make Sure if thread is exist
	{
		// Signal Thread to Finish
		if (g_hMsgQueue)
		{
			CloseMsgQueue(g_hMsgQueue);	// Closing the MsgQueue will force ReadMsgQueue to return
			g_hMsgQueue = NULL;
		}

		// Wait for Thread to Finish
		WaitForSingleObject(g_hThreadPowerMon, INFINITE);
		CloseHandle(g_hThreadPowerMon);
		g_hThreadPowerMon = NULL;
	}

	PWC_ReleaseResources();

	PWRCON_MSG((_T("[PWRCON] --PWC_Deinit()\r\n")));

	return TRUE;
}

DWORD
PWC_Init(DWORD dwContext)
{
	PWRCON_INF((_T("[PWRCON:INF] ++PWC_Init(0x%08x)\r\n"), dwContext));

	if (PWC_AllocResources() == FALSE)
	{
		PWRCON_ERR((_T("[PWRCON:ERR] PWC_Init() : PWC_AllocResources() Failed \n\r")));
		goto CleanUp;
	}

	PwrCon_initialize_register_address((void *)g_pSysConReg);

	// Create power Monitor Thread
	g_hThreadPowerMon = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) PowerMonitorThread, NULL, 0, NULL);
	if (g_hThreadPowerMon == NULL )
	{
		PWRCON_ERR((_T("[PWRCON:ERR] PWC_Init() : CreateThread() Power Monitor Failed \n\r")));
		goto CleanUp;
	}

	PWRCON_INF((_T("[PWRCON:INF] --PWC_Init()\r\n")));

	return TRUE;

CleanUp:

	PWRCON_ERR((_T("[PWRCON:ERR] --PWC_Init() : Failed\r\n")));

	PWC_Deinit(0);

	return FALSE;
}

DWORD
PWC_Open(DWORD pContext, DWORD dwAccess, DWORD dwShareMode)
{
	PWRCON_MSG((_T("[PWRCON] PWC_Open(0x%08x, 0x%08x, 0x%08x)\r\n"), pContext, dwAccess, dwShareMode));
	return (0x12345678);
}

BOOL
PWC_Close(DWORD pContext)
{
	PWRCON_MSG((_T("[PWRCON] PWC_Close(0x%08x)\r\n"), pContext));
	return TRUE;
}

DWORD
PWC_Read (DWORD pContext,  LPVOID pBuf, DWORD Len)
{
	PWRCON_MSG((_T("[PWRCON] PWC_Read(0x%08x, 0x%08x, 0x%08x)\r\n"), pContext, pBuf, Len));
	return (0);	// End of File
}

DWORD
PWC_Write(DWORD pContext, LPCVOID pBuf, DWORD Len)
{
	PWRCON_MSG((_T("[PWRCON] PWC_Write(0x%08x, 0x%08x, 0x%08x)\r\n"), pContext, pBuf, Len));
	return (0);	// Number of Byte
}

DWORD
PWC_Seek (DWORD pContext, long pos, DWORD type)
{
	PWRCON_MSG((_T("[PWRCON] PWC_Seek(0x%08x, 0x%08x, 0x%08x)\r\n"), pContext, pos, type));
	return (DWORD)-1;	// Failure
}

BOOL
PWC_PowerUp(DWORD pContext)
{
	PWRCON_MSG((_T("[PWRCON] PWC_PowerUp(0x%08x)\r\n"), pContext));

	return TRUE;
}

BOOL
PWC_PowerDown(DWORD pContext)
{
	PWRCON_MSG((_T("[PWRCON] PWC_PowerDown(0x%08x)\r\n"), pContext));

	return TRUE;
}

BOOL
PWC_IOControl(DWORD pContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
	BOOL bRet = TRUE;
	DWORD dwIndex;

	if (pContext != 0x12345678)
	{
		PWRCON_ERR((_T("[PWRCON:ERR] PWC_IOControl(0x%08x, 0x%08x) : Invalid Handle\r\n"), pContext, dwCode));
		SetLastError(ERROR_INVALID_HANDLE);
		return FALSE;
	}
	if ( !( (dwCode == IOCTL_PWRCON_SET_POWER_ON)
		|| (dwCode == IOCTL_PWRCON_SET_POWER_OFF)
		|| (dwCode == IOCTL_POWER_CAPABILITIES)
		|| (dwCode == IOCTL_POWER_QUERY)
		|| (dwCode == IOCTL_POWER_SET)	))
	{
		PWRCON_ERR((_T("[PWRCON:ERR] PWC_IOControl() : Unknown IOCTL [0x%08x]\r\n"), dwCode));
		SetLastError (ERROR_INVALID_ACCESS);
		return FALSE;
	}

	switch(dwCode)
	{
#if	0	// Not Power Managable
	case IOCTL_POWER_CAPABILITIES:
	case IOCTL_POWER_QUERY:
	case IOCTL_POWER_SET:
		break;
#endif

	case IOCTL_PWRCON_SET_POWER_ON:
		if ((dwLenIn < sizeof(DWORD)) || (NULL == pBufIn))
		{
			PWRCON_ERR((_T("[PWRCON:ERR] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON) : Invalid Parameter\r\n")));
			SetLastError (ERROR_INVALID_PARAMETER);
			bRet = FALSE;
			break;
		}

		dwIndex = (DWORD)(*pBufIn);

		EnterCriticalSection(&csPowerCon);

		switch(dwIndex)
		{
		case PWR_IP_IROM:
			g_aIPPowerStatus[dwIndex] = TRUE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON, %d) : BLKPWR_DOMAIN_IROM On\r\n"), dwIndex));
			PwrCon_set_block_power_on(BLKPWR_DOMAIN_IROM);
			break;
		case PWR_IP_ETM:
			g_aIPPowerStatus[dwIndex] = TRUE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON, %d) : BLKPWR_DOMAIN_ETM On\r\n"), dwIndex));
			PwrCon_set_block_power_on(BLKPWR_DOMAIN_ETM);
			break;
		case PWR_IP_SDMA0:		// Domain S
		case PWR_IP_SDMA1:
		case PWR_IP_SECURITY:
			g_aIPPowerStatus[dwIndex] = TRUE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON, %d) : BLKPWR_DOMAIN_S On\r\n"), dwIndex));
			PwrCon_set_block_power_on(BLKPWR_DOMAIN_S);
			break;
		case PWR_IP_ROTATOR:	// Domain F
		case PWR_IP_POST:
		case PWR_IP_DISPCON:
			g_aIPPowerStatus[dwIndex] = TRUE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON, %d) : BLKPWR_DOMAIN_F On\r\n"), dwIndex));
			PwrCon_set_block_power_on(BLKPWR_DOMAIN_F);
			break;
		case PWR_IP_2D:			// Domain P
		case PWR_IP_TVENC:
		case PWR_IP_TVSC:
			g_aIPPowerStatus[dwIndex] = TRUE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON, %d) : BLKPWR_DOMAIN_P On\r\n"), dwIndex));
			PwrCon_set_block_power_on(BLKPWR_DOMAIN_P);
			break;
		case PWR_IP_JPEG:		// Domain I
		case PWR_IP_CAMIF:
			g_aIPPowerStatus[dwIndex] = TRUE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON, %d) : BLKPWR_DOMAIN_I On\r\n"), dwIndex));
			PwrCon_set_block_power_on(BLKPWR_DOMAIN_I);
			break;
		case PWR_IP_MFC:		// Domain V
			g_aIPPowerStatus[dwIndex] = TRUE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON, %d) : BLKPWR_DOMAIN_V On\r\n"), dwIndex));
			PwrCon_set_block_power_on(BLKPWR_DOMAIN_V);
			break;
		default:
			PWRCON_ERR((_T("[PWRCON:ERR] PWC_IOControl(IOCTL_PWRCON_SET_POWER_ON, %d) : Invalid Parameter\r\n"), dwIndex));
			SetLastError (ERROR_INVALID_PARAMETER);
			bRet = FALSE;
		}

		LeaveCriticalSection(&csPowerCon);

		break;

	case IOCTL_PWRCON_SET_POWER_OFF:
		if ((dwLenIn < sizeof(DWORD)) || (NULL == pBufIn))
		{
			PWRCON_ERR((_T("[PWRCON:ERR] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF) : Invalid Parameter\r\n")));
			SetLastError (ERROR_INVALID_PARAMETER);
			bRet = FALSE;
			break;
		}

		dwIndex = (DWORD)(*pBufIn);

		EnterCriticalSection(&csPowerCon);

		switch(dwIndex)
		{
		case PWR_IP_IROM:
			g_aIPPowerStatus[dwIndex] = FALSE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF, %d) : BLKPWR_DOMAIN_IROM Off\r\n"), dwIndex));
			PwrCon_set_block_power_off(BLKPWR_DOMAIN_IROM);
			break;
		case PWR_IP_ETM:
			g_aIPPowerStatus[dwIndex] = FALSE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF, %d) : BLKPWR_DOMAIN_ETM Off\r\n"), dwIndex));
			PwrCon_set_block_power_off(BLKPWR_DOMAIN_ETM);
			break;
		case PWR_IP_SDMA0:		// Domain S
		case PWR_IP_SDMA1:
		case PWR_IP_SECURITY:
			g_aIPPowerStatus[dwIndex] = FALSE;
			if ( (g_aIPPowerStatus[PWR_IP_SDMA0] == FALSE)
				&& (g_aIPPowerStatus[PWR_IP_SDMA1] == FALSE)
				&& (g_aIPPowerStatus[PWR_IP_SECURITY] == FALSE) )
			{
				PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF, %d) : BLKPWR_DOMAIN_S Off\r\n"), dwIndex));
				PwrCon_set_block_power_off(BLKPWR_DOMAIN_S);
			}
			break;
		case PWR_IP_ROTATOR:	// Domain F
		case PWR_IP_POST:
		case PWR_IP_DISPCON:
			g_aIPPowerStatus[dwIndex] = FALSE;
			if ( (g_aIPPowerStatus[PWR_IP_ROTATOR] == FALSE)
				&& (g_aIPPowerStatus[PWR_IP_POST] == FALSE)
				&& (g_aIPPowerStatus[PWR_IP_DISPCON] == FALSE) )
			{
				PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF, %d) : BLKPWR_DOMAIN_F Off\r\n"), dwIndex));
				PwrCon_set_block_power_off(BLKPWR_DOMAIN_F);
			}
			break;
		case PWR_IP_2D:			// Domain P
		case PWR_IP_TVENC:
		case PWR_IP_TVSC:
			g_aIPPowerStatus[dwIndex] = FALSE;
			if ( (g_aIPPowerStatus[PWR_IP_2D] == FALSE)
				&& (g_aIPPowerStatus[PWR_IP_TVENC] == FALSE)
				&& (g_aIPPowerStatus[PWR_IP_TVSC] == FALSE) )
			{
				PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF, %d) : BLKPWR_DOMAIN_P Off\r\n"), dwIndex));
				PwrCon_set_block_power_off(BLKPWR_DOMAIN_P);
			}
			break;
		case PWR_IP_JPEG:		// Domain I
		case PWR_IP_CAMIF:
			g_aIPPowerStatus[dwIndex] = FALSE;
			if ( (g_aIPPowerStatus[PWR_IP_JPEG] == FALSE)
				&& (g_aIPPowerStatus[PWR_IP_CAMIF] == FALSE) )
			{
				PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF, %d) : BLKPWR_DOMAIN_I Off\r\n"), dwIndex));
				PwrCon_set_block_power_off(BLKPWR_DOMAIN_I);
			}
			break;
		case PWR_IP_MFC:		// Domain V
			g_aIPPowerStatus[dwIndex] = FALSE;
			PWRCON_INF((_T("[PWRCON:INF] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF, %d) : BLKPWR_DOMAIN_V Off\r\n"), dwIndex));
			PwrCon_set_block_power_off(BLKPWR_DOMAIN_V);
			break;
		default:
			PWRCON_ERR((_T("[PWRCON:ERR] PWC_IOControl(IOCTL_PWRCON_SET_POWER_OFF, %d) : Invalid Parameter\r\n"), dwIndex));
			SetLastError (ERROR_INVALID_PARAMETER);
			bRet = FALSE;
		}

		LeaveCriticalSection(&csPowerCon);

		break;
	}

	return bRet;
}

// EOF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -