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

📄 modehandler.c

📁 GM5621原代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			else
			{
				// The input timing mode can NOT be identified.  It is unsupportable,
				// out_of_range mode.
				#ifdef PHOENIX
				LedRed();
				#endif
				SendMsg(&OsdQ,MTO_OUT_OF_RANGE);
				msg("Unsupportable Input", 0);
			}
		}
		else
		{// timing is still stable, don't do anything.
		 // msg("MH: ibd VS = %d", gm_ReadRegWord(IBD_VSTART_HI));
		 	#if !defined(TUCSON) && HDCP_ENABLE_4TH
				if (InputPortArray[gmvb_CurrentPortMain].Port == IP_DVI)
					Hdcp_TimingStable();              //To count HDCPS.IsHDCPOK
			#endif

		   CheckEstimatedMode(DEF_CHANNEL);
		}
	}
	else	//if (gm_InputTimingIsStableMain())
	{// Timing unstable
      #ifdef USE_PIXCR_DATAINVIDEO
      if(DIVControl > 0)
      {
      	gm_Print("Data In Video Stopped",0);
      	DIVControl = 0;			// stop data in video
      }
      #endif

		if (gm_InputTimingTransitionFromStableMain() == gmd_TRUE)
		{// Timing changed from stable to unstable


		#ifdef PHOENIX_U
			gm_SetRegBitsByte(DISPLAY_CONTROL1, FORCE_BKGND);        // blank the display
			gm_ForceUpdate();
		#endif

			gmvw_InputFlagsMain = 0;
			msg("Timing changed from stable to unstable", 0);
			StopADCCalibrationISR();

			#if Enable_AOC		// Louis 0822
				// DisableAOCMain();
				EnableDontUpdateAOCMain();
			#endif

			LedNoCableCheck();
			// send MTO_MODE_CHANGE to reset OSD, unless there's already a
			// message pending.
			if(IsMsg(&OsdQ) == gmd_FALSE)
				SendMsg(&OsdQ,MTO_MODE_CHANGE);
			
			#if defined(RD3_57XX) && (BOARD==RD3_57XX)
			OSD_Handler();									//Fixed OSD doesn't display if cable is remove 
			#endif

			//Add Customer Code here...
			LedOrange();

			// Port not stable, start hold timer.
			if(B_SyncStatePort == gmvb_CurrentPortMain)
			{
				gm_TimerStart(ModeHoldTime_10ms_TMR, InputPortArray[gmvb_CurrentPortMain].StabilityHoldTime);
			}
		#if !defined(TUCSON) && HDCP_ENABLE_4TH
			if (InputPortArray[gmvb_CurrentPortMain].Port == IP_DVI)
			{
			#if defined(RD3_57XX) && (BOARD==RD3_57XX)
				BYTE dvi_connect;
			#endif
				#if USE_CABLE_DETECTION_FEATURE
				// When Timing change form stable to unstable, let's check DVI cable is disconnect or not 
				// if DVI cable is disconnect, Let's change port right away if AutoScan mode is enable. 
				// Or, this is not AutoScan mode, let's temporary turn off DVI Blcok for a period. 
				// This is for bug fixed: Display snowing if Plug In&Out DVI cable in QT882 Pattern Gen HDCP signal.
					#if USE_CABLE_DETECT_TIMER
						while(gm_TimerCheck(CableDetect_10MS_TMR)==gmd_TMR_ACTIVE);
					#else
						gm_Delay10ms(CABLE_DETECT_RUNTIME); //delay time = CABLE_DETECT_RUNTIME. Make Sure we will re-detct Cable connection status right away.
					#endif
					CableDetect_Handler();   //Need to update CableDetect right away!
					#if defined(RD3_57XX) && (BOARD==RD3_57XX)
						if (InputPortArray[gmvb_CurrentPortMain].MuxInput==MUX_ON_DVI_B)
							dvi_connect=IsDvi_B_CableConnected();
						else
							dvi_connect=IsDviCableConnected();
						if(Hdcp_TimingTransitionFromStable()&& !dvi_connect)
					#else	
						if(Hdcp_TimingTransitionFromStable()&& !IsDviCableConnected())
					#endif
						{
//						SystemFlags.CableDetect = gmd_FALSE;
							SendMsg(&OsdQ,MTO_NO_CABLE);
//						gm_SetDisplayFreeRunMode();
//						sendNoSync = gmd_FALSE;
//						OSD_Handler();
							if(UserPrefMHAutoScanMode)
							{
								gm_TimerStop(ModeHoldTime_10ms_TMR); //If in AutoScan mode and DVI canble is not connected, we should change port right away!
								msg("DVI Cable is disconnect, Change Port Right away!",0);
							}
							else
							{
								Hdcp_DVI_Temporary_Off();
								PowerDownDevice(gmd_PCD_DVI);
								msg("DVI Cable is disconnect, Temporaray Power down DVI Block!",0);
							}
						}
					#endif //USE_CABLE_DETECTION_FEATURE
			}
		#endif //!defined(TUCSON) && HDCP_ENABLE_4TH
		}
		else
		{// Timing still Unstable.

			lastSyncType = gmd_NO_SYNC_STATE;	//Added for gm_GetSyncTypeMain().
			
			LedNoCableUpdate();
			if(UserPrefMHAutoScanMode)
				ChangePort();
			else
			{
				#if !defined(TUCSON) && HDCP_ENABLE_4TH
				// When AutoScan mode is disable. And, if DVI is temporary off for a period,
				// Check if it's time out already. If time out, We must turn on DVI Block again.
				// This is for bug fixed: Display snowing if Plug In&Out DVI cable in QT882 Pattern Gen HDCP signal.
					if (InputPortArray[gmvb_CurrentPortMain].Port == IP_DVI && Is_Hdcp_DVI_Temporary_Off())
					{
						if(!Hdcp_Authentication_TimerCheck())
						{
							PowerUpDevice(gmd_PCD_DVI);               //Re-Turn on DVI block again.
							SetInputPort(gmvb_CurrentPortMain);
							gm_TimerStart(ModeHoldTime_10ms_TMR, InputPortArray[gmvb_CurrentPortMain].StabilityCheckTime);
							Hdcp_DVI_Temporary_Off_Down();            //Clear HDCPS.IsTemp_DVIBlockOff flag
						}
						return;
					}
				#endif
				if (gm_TimerCheck(ModeHoldTime_10ms_TMR) != gmd_TMR_ACTIVE)
				{
					#if !defined(TUCSON) && HDCP_ENABLE_4TH && HDCP_USE_DVI_HOTPLUG
					DoNotTouchHotPlug=gmd_TRUE;
					#endif			 
					SetInputPort(gmvb_CurrentPortMain);
					gm_TimerStart(ModeHoldTime_10ms_TMR, InputPortArray[gmvb_CurrentPortMain].StabilityCheckTime);
				}
			}
		}
	}
}

//***************************************************************
//	DESCRIPTION	:	Mode handler initialization.  Initializes mode handler
//						variables placing it in a known state.  Called at startup
//						and after a soft power on.
//	SYNTAX     	:	void InitModeHandler(void)
//	PARAMETERS	:	none
//  RETURN		:	none
//***************************************************************
void InitModeHandler(void)
{
	BYTE i;
	gm_TimerStart(ModeHoldTime_10ms_TMR, InputPortArray[gmvb_CurrentPortMain].StabilityHoldTime);

	gm_SetDisplayFreeRunMode();

	SystemFlags.ModeHandlerOff = gmd_FALSE;

	// starting off with SyncDetect gmd_TRUE and B_SyncState gmd_HONVON allows us to
	// detect when we lose sync at startup.  If starting off with no sync,
	// then when the system comes up it's typically in no sync, so there will
	// be no MTO_NO_SYNC messages since there's no change in state.
	SystemFlags.SyncDetect = gmd_TRUE;

	B_SyncStatePort = gmvb_CurrentPortMain;
	B_SyncState = gmd_HONVON;
	sendNoSync = gmd_TRUE;

	for(i=0;i<NumInputPorts;i++)
	{
		InputPortSyncArray[i].B_SyncState = gmd_HOFFVOFF;
		InputPortSyncArray[i].B_SyncType = gmd_NO_SYNC_STATE;
	}

#if 0 // USE_GSEL_DRVR_MODEL
//	gm_AddDriver(vpc323_VideoDecoderEntry,DEV_VPC3230);
//	gm_CallDriver(DEV_VPC3230,gmd_VID_SET_MODE,VDD_MODE_INIT, NULL_PTR);
	
	gm_AddDriver(DEV_VID_FUNC_ENTRY,DEV_VIDEO_DECODER);
    gm_CallDriver(DEV_VIDEO_DECODER,gmd_VID_PWR_UP,NULL_PTR,NULL_PTR);
    gm_CallDriver(DEV_VIDEO_DECODER,gmd_VID_SET_MODE,VDD_MODE_INIT, NULL_PTR);
    gm_CallDriver(DEV_VIDEO_DECODER,gmd_VID_SET_OUTPUT_FORMAT,VDD_OUTTYPE_656,NULL_PTR);
//    gm_CallDriver(DEV_VIDEO_DECODER,gmd_VID_SET_MODE,VDD_MODE_NTSC,NULL_PTR);   //set default as NTSC   
	
#endif// USE_GSEL_DRVR_MODEL

	// configure current port.

//Fixed the issue of not power down to the other power blocks when system reset.
	if (InputPortArray[gmvb_CurrentPortMain].PowerDev!=gmd_PCD_RGB)
		PowerDownDevice(gmd_PCD_RGB);
	if (InputPortArray[gmvb_CurrentPortMain].PowerDev!=gmd_PCD_DVI)
		PowerDownDevice(gmd_PCD_DVI);
#ifdef VPORT_CTRL
	if (InputPortArray[gmvb_CurrentPortMain].PowerDev!=gmd_PCD_VIDEO)
		PowerDownDevice(gmd_PCD_VIDEO);
#endif	

#if !defined(TUCSON) && HDCP_ENABLE_4TH && USE_SPLASH_SCREEN  
	if (AC_ON)
		AC_ON=gmd_FALSE;
	else
#endif		
		PowerUpDevice(InputPortArray[gmvb_CurrentPortMain].PowerDev);
	
	ChangeToPort(gmvb_CurrentPortMain);

	#if(DDC2Bi_PORT == 0)
		gB_DDC2Bi_channel=gmd_VGA_DDC2Bi_CHANNEL;
		gm_DDC2BiInit(gmd_VGA_DDC2Bi_CHANNEL);
	#elif(DDC2Bi_PORT == 1)
		gB_DDC2Bi_channel=gmd_DVI_DDC2Bi_CHANNEL;
		gm_DDC2BiInit(gmd_DVI_DDC2Bi_CHANNEL);
	#endif
}

#if 0
//******************************************************************
// DESCRIPTION  : This function only applies to SOG signals, a strong white
//						image can trick the sync extraction hardware into thinking
//						there are syncs.  This function just makes absolutely sure
//						by seeing if the mode is valid, and resetting
//						InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState if
//						the mode isn't valid.
//
// PARAMETERS	:   none
// RETURN		:   none
//******************************************************************
static void __near UpdateSOGActiveSync(void)
{
	WORD  MeasHPulse;

	if(InputPortSyncArray[gmvb_CurrentPortMain].B_SyncType != gmd_SOG_SYNC)
		return;

	// first see if we have any syncs, if no syncs then move on.
	if(InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState == gmd_HOFFVOFF)
		return;

	if(SystemFlags.PowerSaving) //SystemFlags.MH_SleepMode)
	{	// if in sleep mode, we don't want to wake up unless both syncs are
		// present.
		if(InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState != gmd_HONVON)
		{
			InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState = gmd_HOFFVOFF;
			return;
		}
		// if both syncs present, make sure it's a valid mode.
		gm_ReadInputTimingMain();
		DetermineMode();
		if (gmvw_InputFlagsMain & gmd_OUT_RANGE)
		{
			InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState = gmd_HOFFVOFF;
			return;
		}
		// check hsync widths just to make sure.
		// IFM_HSYNC_SEL is enabled for SOG which results in a measured
		// Hsync pulse of 4, we have to disable IFM_HSYNC_SEL and measure
		// the pulse manually.  We can count on SOG being set up so both
		// syncs are positive.
		gm_ClearRegBitsByte(CSYNC_CONTROL, IFM_HSYNC_SEL);
		gm_Delay1ms(30);
		MeasHPulse = gm_ReadRegWord(IFM_HS_PULSE);
		gm_SetRegBitsByte(CSYNC_CONTROL, IFM_HSYNC_SEL);
		msgx("meas hsync width %d",MeasHPulse);

		if(gmvw_InputFlagsMain & gmd_ESTIMATED)
		{// if estimated, look at a few Hsyncs to see if the period is stable.
			BYTE i;
			WORD newHSPulse;

			for(i=0;i<3;i++)
			{
				gm_ClearRegBitsByte(CSYNC_CONTROL, IFM_HSYNC_SEL);
				gm_Delay1ms(30);
				newHSPulse = gm_ReadRegWord(IFM_HS_PULSE);
				msgx("estimated: meas hsync width %d",newHSPulse);
				if(abs(MeasHPulse - newHSPulse) > 4)
				{
					gm_SetRegBitsByte(CSYNC_CONTROL, IFM_HSYNC_SEL);
					InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState = gmd_HOFFVOFF;
					return;
				}
			}
			// for now, don't allow estimated modes to wake up sleep for SOG.
			InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState = gmd_HOFFVOFF;
			return;
		}
		else
		{
			DWORD CalcHPulse;

			CalcHPulse = ((DWORD)T_CLK_KHZ * 10) / gmvw_InputHFreqMain;
			CalcHPulse *= StandardModeTable[ModeTableIndex].StdHSyncWidth;
			CalcHPulse /= gmvw_InputHTotalMain;

			msgx("std hsync width %d",(WORD)CalcHPulse);
			if(abs((WORD)CalcHPulse - MeasHPulse) > 4)
			{
				msgx("**Hsync width doesn't match",0);
				InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState = gmd_HOFFVOFF;
				return;
			}
		}
	}
}
#endif

//******************************************************************
// DESCRIPTION  : This function figures when it's time to send an
//						MTO_MODE_CHANGE and MTO_NO_SYNC message to OSD.  It also
//						updates the B_SyncState and B_SyncStatePort.
//
// PARAMETERS	:   none
// RETURN		:   none
//******************************************************************
static void __near UpdateActiveSync(void)
{
	BYTE sync, msg = 0;
	BYTE CurCable;		// 1130

	// SOG is tricky, a full white image with no embedded syncs can cause sync
	// extracter to extract syncs that aren't there.
	//if(InputPortSyncArray[gmvb_CurrentPortMain].B_SyncType == gmd_SOG_SYNC)
	//	UpdateSOGActiveSync();

	// get the Active sync state...
	sync = InputPortSyncArray[gmvb_CurrentPortMain].B_SyncState;

	// some ports wake system up if there's a hint of a sync, not necessarily
	// valid syncs.  To prevent intermittent "NoSignal" messages these ports
	// (DVI) will set a PowerUpWait timer, ignore "bad" syncs until timer
	// expires.  Letting gmd_HONVON through will allow system to power up if
	// valid syncs are indeed found.
	if((gm_TimerCheck(PowerUpWait_10ms_TMR) == gmd_TMR_ACTIVE) &&
		(sync != gmd_HONVON))
			return;

#if USE_TEST_PATTERN
	//intercept message here when TestPattern is running
	if(SystemFlags.TestPatternRunning)
   {
   	if(sync==gmd_HONVON && (!SystemFlags.TestPatternActiveFromKey))
      {
			msgx("DisableTestPattern By return sync",0);
      	DisableTestPatterns();
      }
      else
	   	return;
	}
#endif

	if(B_SyncStatePort == gmvb_CurrentPortMain)
	{
		#if 1 // 1130
			if((sync != gmd_HONVON) && (FirstPowerUp == 1))
			{

⌨️ 快捷键说明

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