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

📄 power.cpp

📁 Sm501 VGA芯片wince下驱动代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		case POWER_MODE_CTRL_MODE_MODE1:
			gate_reg = POWER_MODE1_GATE;
			break;
		}

		if (gate_reg)
		{
			// Get current gates.
			DWORD gate = peekRegisterDWord(gate_reg);

			switch (State)
			{
			case VGXPowerOn:
				if ((gate & m_PowerInfo[Module].dwGateMask) == 0)
					pokeRegisterDWord(gate_reg, gate | m_PowerInfo[Module].dwGateMask);
				m_PowerInfo[Module].CurrentState = VGXPowerOn;
				dwResult = VGXPM_RET_SUCCESS;
				break;

			case VGXPowerOff:
				if ((gate & m_PowerInfo[Module].dwGateMask) == 1)
					pokeRegisterDWord(gate_reg, gate & ~m_PowerInfo[Module].dwGateMask);
				m_PowerInfo[Module].CurrentState = VGXPowerOff;
				dwResult = VGXPM_RET_SUCCESS;
				break;

			default:
				MESSAGE(MESSAGE_ZONE, (TEXT("SMI::SetModulePower: invalid state has been specified\r\n")));
			}
		}
		else
		{
			MESSAGE(MESSAGE_ZONE, (TEXT("SMI::SetModulePower: cannot change module state - the chip is in sleep mode\r\n")));
			dwResult = VGXPM_RET_SLEEP_MODE;
		}
	}
	else
	{
		MESSAGE(MESSAGE_ZONE, (TEXT("SMI::SetModulePower: invalid module has been specified\r\n")));
	}

	MESSAGE(MESSAGE_ZONE, (TEXT("-SMI::SetModulePower\r\n")));

	LeaveCriticalSection(&m_PowerCriticalSection);

	return dwResult;
}


///////////////////////////////////////////////////////////////////////////////
// Sets the amount of idle ticks before the mofule will be switched off.

DWORD SMI::SetTicksToPowerDown(VGXPM_MODULES Module, DWORD dwCount)
{
	EnterCriticalSection(&m_PowerCriticalSection);

	DWORD dwResult = VGXPM_RET_INVALID_PARAMETER;

	// Make sure we are within range
	if (Module < VGXPM_MODULE_COUNT)
	{
		m_PowerInfo[Module].dwLastCallTickCount = GetTickCountSafe();
		m_PowerInfo[Module].dwTicksToPowerDown  = dwCount;
		dwResult = VGXPM_RET_SUCCESS;
	}
	else
	{
		MESSAGE(MESSAGE_ZONE, (TEXT("SMI::SetTicksToPowerDown: invalid module has been specified\r\n")));
	}

	LeaveCriticalSection(&m_PowerCriticalSection);

	return dwResult;
}


///////////////////////////////////////////////////////////////////////////////
// Sets new clock array.

VOID SMI::SetClockArray(CLOCK_ARRAY& Array)
{
	EnterCriticalSection(&m_PowerCriticalSection);

	MoveMemory(&m_ClockInfo, &Array, sizeof(m_ClockInfo));

	LeaveCriticalSection(&m_PowerCriticalSection);
}


///////////////////////////////////////////////////////////////////////////////
// Determines whether or not the power monitor is enabled on the module.

DWORD SMI::GetModuleMonitorEnabled(VGXPM_MODULES Module, BOOL& bEnabled)
{
	DWORD dwResult = VGXPM_RET_INVALID_PARAMETER;

	// Make sure we are within range
	if (Module < VGXPM_MODULE_COUNT)
	{
		bEnabled = m_PowerInfo[Module].bMonitorEnabled;
		dwResult = VGXPM_RET_SUCCESS;
	}
	else
	{
		MESSAGE(MESSAGE_ZONE, (TEXT("SMI::GetModuleMonitorEnabled: invalid module has been specified\r\n")));
	}

	return dwResult;
}


///////////////////////////////////////////////////////////////////////////////
// Returns the current power state for the specified module.

DWORD SMI::GetModulePower(VGXPM_MODULES Module, VGX_POWER_STATE& State)
{
	DWORD dwResult = VGXPM_RET_INVALID_PARAMETER;

	// Make sure we are within range
	if (Module < VGXPM_MODULE_COUNT)
	{
		State = m_PowerInfo[Module].CurrentState;
		dwResult = VGXPM_RET_SUCCESS;
	}
	else
	{
		MESSAGE(MESSAGE_ZONE, (TEXT("SMI::GetModulePower: invalid module has been specified\r\n")));
	}

	return dwResult;
}


///////////////////////////////////////////////////////////////////////////////
// Returnes the amount of ticks since the last API call related to this module.

DWORD SMI::GetLastCallTickCount(VGXPM_MODULES Module, DWORD& dwCount)
{
	DWORD dwResult = VGXPM_RET_INVALID_PARAMETER;

	// Make sure we are within range
	if (Module < VGXPM_MODULE_COUNT)
	{
		dwCount = m_PowerInfo[Module].dwLastCallTickCount;
		dwResult = VGXPM_RET_SUCCESS;
	}
	else
	{
		MESSAGE(MESSAGE_ZONE, (TEXT("SMI::GetLastCallTickCount: invalid module has been specified\r\n")));
	}

	return dwResult;
}


///////////////////////////////////////////////////////////////////////////////
// Returnes the amount of idle ticks before the mofule will be switched off.

DWORD SMI::GetTicksToPowerDown(VGXPM_MODULES Module, DWORD& dwCount)
{
	DWORD dwResult = VGXPM_RET_INVALID_PARAMETER;

	// Make sure we are within range
	if (Module < VGXPM_MODULE_COUNT)
	{
		dwCount = m_PowerInfo[Module].dwTicksToPowerDown;
		dwResult = VGXPM_RET_SUCCESS;
	}
	else
	{
		MESSAGE(MESSAGE_ZONE, (TEXT("SMI::GetTicksToPowerDown: invalid module has been specified\r\n")));
	}

	return dwResult;
}


///////////////////////////////////////////////////////////////////////////////
// Returnes the current clock array.

VOID SMI::GetClockArray(CLOCK_ARRAY& Array)
{
	MoveMemory(&Array, &m_ClockInfo, sizeof(m_ClockInfo));
}


///////////////////////////////////////////////////////////////////////////////
// Initializes the message queue and creates a thread.

DWORD SMI::InitPowerManagement()
{
	MESSAGE(MESSAGE_ZONE, (TEXT("+SMI::InitPowerManagement\r\n")));

	///////////////////////////////////////////////////////////////////////////
	// Init defaults.

	m_hPMMessageQueue  = NULL;
	m_hPMNotifications = NULL;
	m_hPMThread        = NULL;

	m_dwClockSave  = 0;
	m_dwGateSave   = 0;
	m_dwPLL2Output = 0;

	m_bProtectClockSource = TRUE;
	m_bInPowerHandler = FALSE;
	m_bResetPowerManagement = FALSE;

	InitializeCriticalSection(&m_PowerCriticalSection);


	///////////////////////////////////////////////////////////////////////////
	// Init the clock info

	INIT_CLOCK_INFO(m_ClockInfo)


	///////////////////////////////////////////////////////////////////////////
	// Init 320x240

	// 8 bit per pixel
	INIT_CLOCK_INFO_RES(320, 240, 8)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	// 16 bit per pixel
	INIT_CLOCK_INFO_RES(320, 240, 16)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	// 32 bit per pixel
	INIT_CLOCK_INFO_RES(320, 240, 32)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()


	///////////////////////////////////////////////////////////////////////////
	// Init 400x300

	// 8 bit per pixel
	INIT_CLOCK_INFO_RES(400, 300, 8)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	// 16 bit per pixel
	INIT_CLOCK_INFO_RES(400, 300, 16)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	// 32 bit per pixel
	INIT_CLOCK_INFO_RES(400, 300, 32)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()


	///////////////////////////////////////////////////////////////////////////
	// Init 640x480

	// 8 bit per pixel
	INIT_CLOCK_INFO_RES(640, 480, 8)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	// 16 bit per pixel
	INIT_CLOCK_INFO_RES(640, 480, 16)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	// 32 bit per pixel
	INIT_CLOCK_INFO_RES(640, 480, 32)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()


	///////////////////////////////////////////////////////////////////////////
	// Init 720x540

	// 8 bit per pixel
	INIT_CLOCK_INFO_RES(720, 540, 8)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	// 16 bit per pixel
	INIT_CLOCK_INFO_RES(720, 540, 16)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	// 32 bit per pixel
	INIT_CLOCK_INFO_RES(720, 540, 32)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

	INIT_CLOCK_INFO_POWER(VGXPowerReduced)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()

	INIT_CLOCK_INFO_POWER (VGXPowerMinimal)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_36()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_72()


	///////////////////////////////////////////////////////////////////////////
	// Init 800x480

	// 8 bit per pixel
	INIT_CLOCK_INFO_RES(800, 480, 8)

	INIT_CLOCK_INFO_POWER(VGXPowerOn)
	INIT_CLOCK_INFO_PLL2(288)
	INIT_CLOCK_INFO_PLL2_288_MCLK_72()
	INIT_CLOCK_INFO_PLL2_288_M2XCLK_144()

⌨️ 快捷键说明

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