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

📄 modehandler.c

📁 GM5621原代码
💻 C
📖 第 1 页 / 共 5 页
字号:
				InputCableDetect();
	
				CurCable = SystemFlags.CableDetect;
				if(CurCable != preCableConnection)
				{
					preCableConnection = CurCable;
					SendMsg(&PowerHandlerQ, MTP_POWER_UP);
					
					if(CurCable != gmd_TRUE)
					{
						gm_Delay1ms(20);
						SendMsg(&OsdQ,MTO_NO_CABLE);
					}
					else
					{
						SendMsg(&OsdQ,MTO_NO_SYNC);
					}
				}

			}
		#endif
		if(B_SyncState != sync)
		  {
				//msgx("Active port sync state %d",(WORD)B_SyncStatePort);
				if(B_SyncState == gmd_HONVON) // if old state was gmd_HONVON, start timer.
				{
					gm_TimerStart(ModeHandlerSyncTimer_10ms_TMR, InputPortArray[gmvb_CurrentPortMain].StabilityCheckTime);
				}

				switch(sync)
				{
					 case gmd_HONVON :
						// good timing, so next time we lose sync, set sendNoSync flag to
						// gmd_TRUE so we send an MTO_NO_SYNC message.
						sendNoSync = gmd_TRUE;

						SystemFlags.SyncDetect = gmd_TRUE;
						msg = MTO_MODE_CHANGE;
						//msg("-->gmd_HONVON",0);
						break;
					 case gmd_HOFFVON :
						#if USE_AUDIO && USE_GSEL_DRVR_MODEL    // Temporarily mute audio when change port
							gm_CallDriver(DEV_AUDIO_DECODER, gmd_AUD_SET_OUTPUT_MUTE, AUDIO_MUTE_ON, NULL_PTR);
						#endif
						SystemFlags.SyncDetect = gmd_FALSE;
						//msg("-->gmd_HOFFVON",0);
						#if ALT_PWR_HANDLER_MTO_MESSAGE
							// in this mode, if transitioning from gmd_HONVOFF to gmd_HOFFVON
							// a mode change won't be sent, but rather MTO_SYNC_STANDBY
							// or MTO_SYNC_SUSPEND.
							if(B_SyncState == gmd_HONVOFF)
								msg = MTO_SYNC_STANDBY;
							else
								msg = MTO_MODE_CHANGE;
						#else
							if(B_SyncState == gmd_HONVON) // if old state was gmd_HONVON, then send message.
								msg = MTO_MODE_CHANGE;
						#endif
						break;
					 case gmd_HONVOFF :
						#if USE_AUDIO && USE_GSEL_DRVR_MODEL    // Temporarily mute audio when change port
							gm_CallDriver(DEV_AUDIO_DECODER, gmd_AUD_SET_OUTPUT_MUTE, AUDIO_MUTE_ON, NULL_PTR);
						#endif
						SystemFlags.SyncDetect = gmd_FALSE;
						//msg("-->gmd_HONVOFF",0);
						#if ALT_PWR_HANDLER_MTO_MESSAGE
							// in this mode, if transitioning from gmd_HONVOFF to gmd_HOFFVON
							// a mode change won't be sent, but rather MTO_SYNC_STANDBY
							// or MTO_SYNC_SUSPEND.
							if(B_SyncState == gmd_HOFFVON)
								msg = MTO_SYNC_SUSPEND;
							else
								msg = MTO_MODE_CHANGE;
						#else
							if(B_SyncState == gmd_HONVON) // if old state was gmd_HONVON, then send message.
								msg = MTO_MODE_CHANGE;
						#endif
						break;
					 case gmd_HOFFVOFF :
						#if USE_AUDIO && USE_GSEL_DRVR_MODEL    // Temporarily mute audio when change port
							gm_CallDriver(DEV_AUDIO_DECODER, gmd_AUD_SET_OUTPUT_MUTE, AUDIO_MUTE_ON, NULL_PTR);
						#endif
						SystemFlags.SyncDetect = gmd_FALSE;
						if(B_SyncState == gmd_HONVON) // if old state was gmd_HONVON, then send message.
							msg = MTO_MODE_CHANGE;
						//msg("-->gmd_HOFFVOFF",0);
						break;
					default:
						msg("-->Unknown!! 0x%x",(WORD)sync);
						msg("        port %d",(WORD)gmvb_CurrentPortMain);
						break;
				}
		  }
		B_SyncState = sync;
	}
	else //if(B_SyncStatePort != gmvb_CurrentPortMain)
	{  // we're not on the active port, but if the port we are looking at has
		// a valid sync, then set SyncDetect gmd_TRUE so we can come out of
		// power saving mode.
		if(sync == gmd_HONVON)
		{// we've found a new active port.
			SystemFlags.SyncDetect = gmd_TRUE;
			B_SyncStatePort = gmvb_CurrentPortMain;
		}
	}

	// see if it's time to send MTO_NO_SYNC message.
	//If no cable is connected, it is definitely in a gmd_HOFFVOFF state
	//The No cable event should overwrite no sync event
	//and no cable event should be sent only once
	if((B_SyncState != gmd_HONVON) && (gm_TimerCheck(ModeHandlerSyncTimer_10ms_TMR) != gmd_TMR_ACTIVE))
	{
		if(sendNoSync)
		{// only send NO_SYNC once until timing is stable again.
			// only send NO_CABLE once until it's connected again.
			InputCableDetect();
			gm_Delay1ms(20);
			if(SystemFlags.CableDetect==gmd_FALSE)
				msg = MTO_NO_CABLE;
			else
				msg = MTO_NO_SYNC;
			sendNoSync = gmd_FALSE;
		}
	}

	if(msg)
	{
		if(B_SyncState != gmd_HONVON)
			gm_SetDisplayFreeRunMode();	   
		SendMsg(&OsdQ,msg);
	}

}

//******************************************************************
//	DESCRIPTION: This function is to check and update current mode in nvram,
//		if it is in nvram, then return true; otherwise, return false.
//	SYNTAX		:   BYTE CheckAndUpdateCurrentModeInNvram(void)
//  PARAMETERS	:   type
//	RETURN		:	gmd_TRUE if mode in specified nvram type
//					gmd_FALSE if not in nvram
//					gmd_FAIL  if reading nvram error
//******************************************************************
static BYTE __near  CheckAndUpdateCurrentModeInNvram(void)
{
	BYTE result = gmd_FALSE;

	if(ReadModeDependentEntry() == gmd_OK)
	{
		result = gmd_TRUE;
		UpdateInputParameterSettings();
		#ifdef UserPrefVFStartValue
		if(!UserPrefVFStartValue)
			UserPrefVFStartValue   = UN_SAVE_VFSTART;   //If UserPrefVFStartValue==0, the VF_START_OFFSET is wrong, make it un_save mode 
		#endif 

	}
	else
	{// update user preferences from mode table.
		UpdateModeDependentSettings();
		#ifdef UserPrefVFStartValue
			UserPrefVFStartValue   = UN_SAVE_VFSTART;   //un save mdoe
		#endif 
	}

	//return results
	return result;
}

//******************************************************************
// DESCRIPTION  :   This function takes the values and polarity of
//		Hsync and and Vsync, determined by the IFM block and tries to find a
//		match in the mode definition table by comparing those values with the
//		standard ones, allowing a diferrence indicated by the threshold values
//		for Hsync and Vsync. If no perfect match is found, the function tries to
//		get a mode from the estimated mode table that has the VTotal value
//		as near to the determined VTotal value.  If even this can not be found
//		the function will signalize unsupported mode. If a matching mode is found
//		in the standard mode table, then the function checks the nvram to see if
//		this mode has been saved and if so loads the user preferrences and exits.
//
// SYNTAX		:   void DetermineMode()
// PARAMETERS	:   none
// RETURN		:   It sets gmd_OUT_RANGE bit at Flag in gmvw_InputFlagsMain
//					if the mode was not found in the definition tables
//******************************************************************
static void __near DetermineMode(void)
{
	EstimatedModeType ROM * EstModeTablePtr; // pointer to mode entry that matches input format - set up by mode handler
	StandardModeType  ROM * ModeTablePtr;


	msgx("Determine Mode", 0);
#if defined(PHOENIX_U) && CHECK_DVI_OVER_CLK
	if(gmvw_InputFlagsMain & gmd_DVI_OVER_CLK)
	{
		gmvw_InputFlagsMain |= gmd_OUT_RANGE;
		msg("DVI clock out of range",0);
		return;
	}
#endif	

	if((gmvw_InputHFreqMain < MIN_INPUT_H_FREQ) || (gmvw_InputHFreqMain > MAX_INPUT_H_FREQ))
	{// input H frequency is too fast or too slow
		gmvw_InputFlagsMain |= gmd_OUT_RANGE;
		msg("HFreq: %d", gmvw_InputHFreqMain);
		return;
	}

	if((gmvw_InputVFreqMain < MIN_INPUT_V_FREQ) || (gmvw_InputVFreqMain > MAX_INPUT_V_FREQ))
	{// input V frequency is too fast or too slow
		gmvw_InputFlagsMain |= gmd_OUT_RANGE;
		msg("VFreq: %d", gmvw_InputVFreqMain);
		return;
	}
	// check the Vf to see whether it meets the panel requirement.
	if((gmvw_InputVFreqMain > (PanelMaxVFreq*10)) || (gmvw_InputVFreqMain < (PanelMinVFreq*10)))
	{	// if Vf is too fast, check whether the reduce VFreq meets the panels' min VFreq requirement
		// if not, the mode will be OutOfRange. 7/15/02 BenH PDR#3397
		if ((gmvw_InputVFreqMain/2) < (PanelMinVFreq*10))
		{
			gmvw_InputFlagsMain |= gmd_OUT_RANGE;
			msg(" input Vf is OOR.",0);
			return;
		}
	}

	msg("Mode Search:",0);
	msgx(" gmvw_InputHFreqMain  %d",gmvw_InputHFreqMain);
	msgx(" gmvw_InputVTotalMain %d",gmvw_InputVTotalMain);
	msgx(" gmvw_InputVFreqMain  %d",gmvw_InputVFreqMain);

	// reset saved mode index for new mode checking
	B_InputSaveIndex = NonSavedModeLookUpIndex;

	// If in supported range, search standard mode table.
	// For DVI, use IBD measurements to get IP window parameters instead of mode
	// Look up table
	if (InputPortArray[gmvb_CurrentPortMain].Port == IP_DVI)
	{
	#ifndef TUCSON
			//Setup DVI clock for each mode change.
	     		 if(gm_CheckDVIClock() == gmd_FALSE)
			{
				msg("DetermineMode:  SetupDVIClock Failed!!!", 0);
			}
			else
			{
				msg("DetermineMode:  SetupDVIEqualizer", 0);
			}
			gmvw_InputWidthMain    = gm_ReadIBDParameter(IBD_HWIDTH) & 0xfffe;	// make an even number
			gmvw_InputHeightMain   = gm_ReadIBDParameter(IBD_VLENGTH) & 0xfffe;	// make an even number
			gmvw_InputHTotalMain   = gm_ReadIBDParameter(IBD_HTOTAL);
			W_SrcModeWidth  = gmvw_InputWidthMain;
	#endif
	}
	else
	{
#if (SUPPORT_VESA_CVT_MODES)
		if(cvt_IsCVT())
		{
			msg(" mode is CVT timing", 0);
			cvt_CalcTiming();
		}
		else
#endif //(SUPPORT_VESA_CVT_MODES)
		{
			ModeTablePtr = SearchModeTable();

			// check if mode table indicates this should be interlaced.  If hardware
			// indicates it is not interlaced then set ModeTablePtr to nil so we do
			// an estimated mode search
			if ((ModeTablePtr->ModeType & gmd_INTERLACED) != (gmvw_InputFlagsMain & gmd_INTERLACED))   //ModeType maybe gmd_INTERLACED + the others. So, not really be "equal"
//			if ((ModeTablePtr->ModeType == gmd_INTERLACED) && (!(gmvw_InputFlagsMain & gmd_INTERLACED)))
				
				ModeTablePtr = NULL_PTR;

			// Not found in standard mode table but still in supported range.
			if (!ModeTablePtr)
			{
				msg(" mode not found in standard mode table", 0);
				// Find a close estimated mode based on VTotal
				EstModeTablePtr = EstSearchModeTable();
				//if standard or estimated mode is not found, then this mode
				// is unsupported
				if (!EstModeTablePtr)
				{// Set unsupported bit input format flags.
					msg(" mode not found in estimated mode table", 0);
					gmvw_InputFlagsMain |= gmd_OUT_RANGE;
					return;
				}
			}
		 #ifdef PHOENIX_U
			SetupHVStartVariables();
	        UserPrefHStartBestValue = gmvw_InputHStartMain; 
		    UserPrefVStartBestValue = gmvw_InputVStartMain;	   	
		    UserPrefHTotalBestValue = gmvw_InputHTotalMain;	
		 #endif
			if(ModeTablePtr->ModeType & gmd_VIDEO_SRC)
				gmvw_InputFlagsMain |= (ModeTablePtr->ModeType & gmd_VIDEO_SRC);			
//				gmvw_InputFlagsMain |= gmd_VIDEO_SRC;
		#ifdef PHOENIX_U  //1080P needs to set ADC_CLAMP_CONTROL as 0x7
		if ((abs(gmvw_InputHFreqMain- 675) <= 50) && (abs(gmvw_InputVTotalMain- 1125) <= 20)||
			(abs(gmvw_InputHFreqMain- 560) <= 50) && (abs(gmvw_InputVTotalMain- 1125) <= 20))   //Check if it's 1080P(60Hz) or 1080P(50Hz)
				gm_WriteRegByte(ADC_CLAMP_CONTROL, 0x7);
			else
				gm_WriteRegByte(ADC_CLAMP_CONTROL, 0x0);
		#endif
		
			////////////////////////////////////////////////////////////////////////////////
			//	Check ModeDependent settings stored in NVRAM
			// Check the NVRAM only for the Normal mode.
			// If the input is SubSample mode, ignore checking NVRAM.
			if(!(gmvw_InputFlagsMain & gmd_VIDEO_SRC))
			{
				if (gmvw_InputWidthMain <= PanelWidth)
				{
					BYTE result;

					//to check and update current mode in nvram,
					result = CheckAndUpdateCurrentModeInNvram();
					if(result != gmd_TRUE )
						B_InputSaveIndex = NonSavedModeLookUpIndex;
				}
			}// if(!(gmvw_InputFlagsMain & gmd_VIDEO_SRC))
		}//if not CVT
	}//else not DVI
	/////////////////////////////////////////////////////////////////////////////
	#if DEBUG_MH && DEBUG_MSG
		if (gmvw_InputFlagsMain & gmd_ESTIMATED)
			msg("Estimated mode# %d", (WORD)ModeTableIndex);
		else if(gmvw_InputFlagsMain & gmd_CVT_MODE_RB)
				msg("CVT Reduced Blanking",0);
		else if(gmvw_InputFlagsMain & gmd_CVT_MODE)
				msg("CVT Standard Timing",0);
		else
			msg("Std mode# %d", (WORD)ModeTableIndex);

		 msg("Input HFreq %d",  gmvw_InputHFreqMain);
		 msg("Input VFreq %d",  gmvw_InputVFreqMain);
		 msg("Input HTotal %d", gmvw_InputHTotalMain);
		 msg("Input VTotal %d", gmvw_InputVTotalMain);
	#endif // DEBUG_MH
}
//******************************************************************
// DESCRIPTION  :   This function takes the values and polarity of
//                  Hsync and and Vsync, determined by the IFM block
//                  and tries to find a match in the mode definition
//                  table by comparing those values with the standard
//                  ones, allowing a diferrence indicated by the
//                  threshold values for Hsync and Vsync.
// SYNTEX		:   SearchModeTable()
// PARAMETERS	:   void
// RETURN       :   Returns pointer to mode table entry if mode was
//					succesfully detected else NULL.
//******************************************************************
static StandardModeType ROM * __near SearchModeTable(void)
{
	BYTE i;
	BYTE LocalIndex;
	StandardModeType ROM * LocalTablePtr;

	for (i=0; ;i++) //end of table is denoted by ModeTableIndex = 0xff
	{
		if(InputPortArray[gmvb_CurrentPortMain].StdModeArray != NULL_PTR)
			LocalIndex = InputPortArray[gmvb_CurrentPortMain].StdModeArray[i];
		else

			LocalIndex = i;

		// exit if end of table

⌨️ 快捷键说明

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