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

📄 modehandler.c

📁 GM5621原代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
	$Workfile:   modehandler.c  $
	$Revision:   1.263  $
	$Date:   Aug 24 2006 21:27:54  $
*/

//******************************************************************
//
//          Copyright (C) 2002. GENESIS MICROCHIP INC.
//  All rights reserved.  No part of this program may be reproduced.
//
//	Genesis Microchip Corp., 2150 Gold Street
//			Alviso, CA 95002	USA
//  Genesis Microchip Inc., 165 Commerce Valley Dr. West
//          Thornhill, Ontario, Canada, L3T 7V8
//
//================================================================
//
//  MODULE: modehandler.c
//
//******************************************************************
#include "inc\all.h"
#include <stdlib.h>

#define	DEBUG_MH    		1
#define  DEBUG_MH_EXTENDED 0

#if DEBUG_MH && DEBUG_MSG
	#define	msg(a,b)	gm_Print((const char far *)a,b)
#else
	#define msg(a,b)
#endif

#if DEBUG_MH_EXTENDED && DEBUG_MSG
	#define	msgx(a,b)	gm_Print((const char far *)a,b)
#else
	#define msgx(a,b)
#endif

#ifdef PHOENIX_U	
			// gm57xx IROM
		   #define gB_DDC2Bi_channel        (*((BYTE *)0x0096))
#elif defined(PHOENIX)
		   // gm56xx IROM
		   #define gB_DDC2Bi_channel        (*((BYTE *)0x029A))
#else
		   // gm52xx IROM
		   #define gB_DDC2Bi_channel        (*((BYTE *)0x02F2))
#endif

extern gmt_MODE_TYPE cvt_IsCVT(void);
extern void cvt_CalcTiming(void);
extern WORD cvt_getVBP(void);
extern WORD cvt_getVsyncWidth(void);

#ifdef ZERO_K_MAIN		// gives cleaner display sometimes, but adds a phase skew
extern BYTE KM0PhaseOffset;
#endif

#ifdef USE_PIXCR_DATAINVIDEO
extern void PixCrDataInVideoLoad(BYTE Thresh);
#endif

#ifdef PHOENIX_U
extern void	gm_ClearHardwareFlags(void);
#endif

#if USE_AUDIO && USE_GSEL_DRVR_MODEL
extern BYTE Set_AudioMute;
#endif


//**************************************************************
//	         G L O B A L   V A R I A B L E S
//**************************************************************
SystemInfoNVRAMType	SystemInfo;

//**************************************************************
//	         L O C A L   V A R I A B L E S
//**************************************************************
// global variables used in this file.
MHInfo_type MHInfo[NUM_CHANNELS];
BYTE ModeTableIndex;

#if USE_COMPONENT_INPUT_ON_RGB
static PreDefCompSetting ROM PREDEF_COMPONENT_TBL[] = {
	#if defined(RD3_57XX) && ( BOARD == RD3_57XX )
	//ModeIndex, 	HPosition, 		VPosition	InputPhase	   // For 57xx-RD3 B-version
	{		42, 		0x8A, 		0x14,		0x36},         //*** NTSC/480I/525I -  720 x  240 x 60I ***  42
	{		44, 		0x9A, 		0x1D,		0x32},         //*** PAL (N) 625I -  720 x  288 x 50I *** 44
	{		45, 		0x92, 		0x37,		0x28},         //*** 576P/625P -  720 x  756 x 50P *** 45
	{		46, 		0x146, 		0x27,		0x1E},         //*** (HDTV) 720P - 1280 x  720 x 60P *** 46
	{		47, 		0x146, 		0x27,		0x1E},         //*** (HDTV) 720P - 1280 x  720 x 50P *** 47
	{		48, 		0x118, 		0x1E,		0x1C},         //*** (HDTV) 1080I - 1920 x 1080 x 60I *** 48
	{		49, 		0x118, 		0x1E,		0x1C},         //*** (HDTV) 1080I - 1920 x 1080 x 50I *** 49
	{		50, 		0x87, 		0x2f,		0x28},         //*** 480P/525P -  720 x  483 x 60P *** 50
	{		52, 		0x115,		0x40,		0x2E},		   //*** (HDTV) 1080P(60Hz) - 1920 x 1080 x 60P *** 52
	{		53, 		0x115,		0x40,		0x2E},		   //*** (HDTV) 1080P(50Hz) - 1920 x 1080 x 50P *** 53
	{		0xff,		0,	   		0,			0x0},
	};
	#elif defined(EV_BD_B_57XX) && ( BOARD == EV_BD_B_57XX )
	{		42, 		0x8A, 		0x14,		0x36},         //*** NTSC/480I/525I -  720 x  240 x 60I ***  42
	{		44, 		0x9A, 		0x1D,		0x36},         //*** PAL (N) 625I -  720 x  288 x 50I *** 44
	{		45, 		0x92, 		0x37,		0x34},         //*** 576P/625P -  720 x  756 x 50P *** 45
	{		46, 		0x146, 		0x27,		0x00},         //*** (HDTV) 720P - 1280 x  720 x 60P *** 46
	{		47, 		0x146, 		0x27,		0x00},         //*** (HDTV) 720P - 1280 x  720 x 50P *** 47
	{		48, 		0x118, 		0x1E,		0x00},         //*** (HDTV) 1080I - 1920 x 1080 x 60I *** 48
	{		49, 		0x118, 		0x1E,		0x00},         //*** (HDTV) 1080I - 1920 x 1080 x 50I *** 49
	{		50, 		0x87, 		0x2f,		0x34},         //*** 480P/525P -  720 x  483 x 60P *** 50
	{		52, 		0x115,		0x40,		0x10},		   //*** (HDTV) 1080P(60Hz) - 1920 x 1080 x 60P *** 52
	{		53, 		0x115,		0x40,		0x10},		   //*** (HDTV) 1080P(50Hz) - 1920 x 1080 x 50P *** 53
	{		0xff,		0,	   		0,			0x0},
	};
	#else  //Default
	{		42, 		0x8A, 		0x14,		0x36},         //*** NTSC/480I/525I -  720 x  240 x 60I ***  42
	{		44, 		0x9A, 		0x1D,		0x36},         //*** PAL (N) 625I -  720 x  288 x 50I *** 44
	{		45, 		0x92, 		0x37,		0x34},         //*** 576P/625P -  720 x  756 x 50P *** 45
	{		46, 		0x146, 		0x27,		0x00},         //*** (HDTV) 720P - 1280 x  720 x 60P *** 46
	{		47, 		0x146, 		0x27,		0x00},         //*** (HDTV) 720P - 1280 x  720 x 50P *** 47
	{		48, 		0x118, 		0x1E,		0x00},         //*** (HDTV) 1080I - 1920 x 1080 x 60I *** 48
	{		49, 		0x118, 		0x1E,		0x00},         //*** (HDTV) 1080I - 1920 x 1080 x 50I *** 49
	{		50, 		0x87, 		0x2f,		0x34},         //*** 480P/525P -  720 x  483 x 60P *** 50
	{		52, 		0x115,		0x40,		0x10},		   //*** (HDTV) 1080P(60Hz) - 1920 x 1080 x 60P *** 52
	{		53, 		0x115,		0x40,		0x10},		   //*** (HDTV) 1080P(50Hz) - 1920 x 1080 x 50P *** 53
	{		0xff,		0,	   		0,			0x0},
	};
	#endif
#endif
//**************************************************************
//	         L O C A L   D E F I N I T I O N S
//**************************************************************
#define VID_DECODER_HEIGHT_MODIFIER 	35
//**************************************************************
//	         LOCAL  FUNCTION   PROTOTYPES
//**************************************************************
static void __near DetermineMode(void);
static gmt_RET_STAT __near ModeSetup(void);
static StandardModeType  ROM * __near SearchModeTable(void);
static EstimatedModeType ROM * __near EstSearchModeTable(void);
static void __near ConfigureMUX(void);
#ifdef MUX_ON_AUDIO_PATH_ENABLE
static void __near ConfigureAudioMUX(void);
#endif
static void __near UpdateActiveSync(void);
static WORD __near GetSClkFrequency(void);
static void __near SetupScaler(void);
static void __near SetupInputConfig(void);
static void __near EnableDisplay(void);
static void __near SetInputPort(BYTE port);

#if DEBUG_MSG & DEBUG_MH
static void __near DisplayModeStats(void);
#else
#define DisplayModeStats()   
#endif

static BYTE __near CheckAndUpdateCurrentModeInNvram(void);
//static BYTE sendNoSync = gmd_TRUE;
BYTE sendNoSync = gmd_TRUE;
BYTE B_SyncStatePort = 0xff;

#if USE_LED_BLINK_NO_SYNC
	void LedNoCableCheck(void);
	void LedNoCableUpdate(void);
#else
	#define LedNoCableCheck()
	#define LedNoCableUpdate()
#endif //USE_LED_BLINK_NO_SYNC

#if THEFT_DETERRENCE_SUPPORT
extern BYTE TD_State;
#endif

extern BYTE preCableConnection;
extern BOOL FirstPowerUp;
#if UPDATE_BW_BY_MODE
extern BYTE gmvb_Input_ADC_BW;
#endif

#if !defined(TUCSON) && HDCP_ENABLE_4TH     
#if USE_SPLASH_SCREEN
extern BOOL AC_ON;
#endif
extern void Hdcp_TimingTransitionToStableEND(void);
extern gmt_RET_STAT Hdcp_TimingTransitionFromStable(void);
extern void Hdcp_TimingStable(void);
extern void Hdcp_DVI_Temporary_Off(void);
extern void Hdcp_DVI_Temporary_Off_Down(void);
extern gmt_RET_STAT Is_Hdcp_DVI_Temporary_Off(void);
extern gmt_RET_STAT Hdcp_Authentication_TimerCheck(void);
	#if HDCP_USE_DVI_HOTPLUG
	extern void Hdcp_HotPlug_Touch(void);
	static BYTE DoNotTouchHotPlug=gmd_FALSE;
	#endif
#endif


//***************************************************************
//	DESCRIPTION	:	IsTimingStable is used to determine if the timing is stable
//                on the current port.  It's a complicated based on if
//                the system is in AUTOSCAN mode, and if the
//						ModeHoldTime_10ms_TMR is running
//						This is called by main while loop.
//	SYNTAX     	:	void Mode_Handler(void)
//	PARAMETERS	:	none
//  RETURN		:	none
//
//***************************************************************
static gmt_RET_STAT _near IsTimingStable(void)
{
	// First check if we're in AUTOSCAN mode:
	if(UserPrefMHAutoScanMode)
	{
		// if the ModeHoldTime_10ms_TMR has stopped, then it's time to change
		// ports.  Return gmd_FALSE
		if(gm_TimerCheck(ModeHoldTime_10ms_TMR) == gmd_TMR_STOPPED)
			return gmd_FALSE;

		//See if we're in sleep mode.
		if(SystemFlags.MH_SleepMode)
		{// If we're in sleep mode, and the current port is a SkipAutoScan port,
		 // then skip the port.  We don't want to check syncs on a SkipAutoScan
		 // port.
			if(InputPortArray[gmvb_CurrentPortMain].SkipAutoScan)
				return gmd_FALSE;

			return gm_InputTimingIsStableMain();

		}
		else
		{// Not in Sleep mode.
			return gm_InputTimingIsStableMain();
		}
	}
	else
	{// Not in AUTOSCAN mode, just see if the timing is stable.
		if(gm_InputTimingIsStableMain() == gmd_TRUE)
			return gmd_TRUE;

	}
	return gmd_FALSE;

}

//***************************************************************
//	DESCRIPTION	:	top level mode handler.
//						This is called by main while loop.
//	SYNTAX     	:	void Mode_Handler(void)
//	PARAMETERS	:	none
//  RETURN		:	none
//
//***************************************************************
extern gmt_RET_STAT gm_IsReadInputTimingDone(void);
void Mode_Handler(void)
{
	BYTE stable;
	if( SystemFlags.ModeHandlerOff )
		return;

#if USE_AUDIO && USE_GSEL_DRVR_MODEL
	if (Set_AudioMute)
	{
		if(gm_TimerCheck(Audio_SetMuteOff_Delay_100ms) != gmd_TMR_ACTIVE)
		{
			gm_TimerStop(Audio_SetMuteOff_Delay_100ms);
			Set_AudioMute=0;
			gm_CallDriver(DEV_AUDIO_DECODER, gmd_AUD_SET_OUTPUT_MUTE,   (WORD)UserPrefAUD_Mute,   NULL_PTR);
		}
	}
#endif

	UpdateActiveSync();

#if USE_TEST_PATTERN
	if(SystemFlags.TestPatternRunning)
	{
		//no need to check sync further since test pattern is activated via keypad
		if(SystemFlags.TestPatternActiveFromKey)
			return;
	}
	else
		FF_REW_Adjust();
#else
		FF_REW_Adjust();
#endif

	// Modehandler is primarily made up of two 'if' statements.  There is one
	// main 'if' statement that checks to see if timing is stable.  If timing
	// is stable then you are on the top half of modehanlder, just below the
	// main 'if' statment.  If timing is not stable, then you are on the lower
	// half of modehanlder, below the 'else' statement.
	// Within each half (stable and unstable) there is an 'if' statement that
	// determines whether the timing has just become stable (or unstable), or
	// if it has been stable/unstable for a while.  Functions
	// gm_InputTimingTransitionToStableMain() and
	// gm_InputTimingTransitionFromStableMain() will return true if the signal
	// has just become stable/unstable, internally these functions set a flag
	// so the next time they are called, they'll return gmd_FALSE, and won't
	// return gmd_TRUE until the timing status has changed from stable to
	// unstable, or unstable to stable.

	 stable = IsTimingStable();
	 
	if(stable)
	{
		if(SystemFlags.PowerSaving || !gm_IsReadInputTimingDone())
		{ // if in PowerSaving, wait for the power to be turned back on.
		  // We can't determine mode and setup mode without the power on.
			return;
		}

		// Check to see if timing has just become stable, if it has just become
		// stable, then proceed to read the timing and determine the mode.
		if (gm_InputTimingTransitionToStableMain() == gmd_TRUE)
		{// Timing changed from unstable to stable
			msg("Input Timing becomes Stable",0);


//			gm_ReadInputTimingMain();
			//scan mode tables and set mode type (including UnsupportedMode)
      			DetermineMode();

			// check whether input timing is changed again.
			// if so, abort processing for new mode handler.
			if (gm_IsAfrSet() == gmd_TRUE)
			{
				msg("Abort Mode Handler",0);
				return;
			}

			if (!(gmvw_InputFlagsMain & gmd_OUT_RANGE))
			{// The input timing mode has been identified.  Input timing is
			 // displayable.  Setup input mode and output.
				if (ModeSetup() != gmd_TRUE)
				{
            #ifdef PHOENIX_U
					gm_SetRegBitsByte(DDS_CONTROL, FORCE_SDDS_OPLOOP |FORCE_DDDS_OPLOOP);
					gm_ForceModeSwitching();  //Fixed for ramdon Modesetup failed when swith to Component port.
				#endif
					msg("Failed to setup mode",0);
					//Failed to set up mode
               			return;
				}
				else
				{// save active port to NVRAM (if it's changed.)
					B_SyncStatePort = gmvb_CurrentPortMain;
					if(B_SyncStatePort != SystemInfo.B_LastActivePort)
						SaveSystemInfoToNVRAM();

            #if DEBUG_MH && DEBUG_MSG
      			DisplayModeStats();
            #endif

				}
				//Mode setup is done.
				//Add Customer Code here...


				LedGreen();

			}
			else if((InputPortArray[gmvb_CurrentPortMain].Port == IP_VIDEO) ||
					(InputPortArray[gmvb_CurrentPortMain].Port == IP_COMPONENT))
					
			{	// video can sometimes read an out of range mode, but the sync
					// will be good and thus not cause a mode change.  For video
					// force a mode change and keep trying if it's out of range.
					msg("gm_ForceModeSwitching",0);
					gm_ForceModeSwitching();
					B_SyncState    = gmd_HOFFVOFF;
			}

⌨️ 快捷键说明

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