📄 main.c
字号:
//**********************************************************************************************************
// The Software is proprietary, confidential, and valuable to Realtek Semiconductor
// Corporation ("Realtek"). All rights, including but not limited to copyrights,
// patents, trademarks, trade secrets, mask work rights, and other similar rights and interests,
// are reserved to Realtek. Without prior written consent from Realtek, copying, reproduction,
// modification, distribution, or otherwise is strictly prohibited. The Software shall be
// kept strictly in confidence, and shall not be disclosed to or otherwise accessed by
// any third party. @ <2003> - <2008> The Software is provided "AS IS" without any warranty of any kind,
// express, implied, statutory or otherwise.
//**********************************************************************************************************
//----------------------------------------------------------------------------------------------------
// ID Code : Main.c No.0000
// Update Note :
//----------------------------------------------------------------------------------------------------
#define __MAIN__
#include "Common\Header\Include.h"
//--------------------------------------------------
// Main Process
//--------------------------------------------------
void main(void)
{
do
{
CMainSystemInitial();
while(CMainDetectSystemPower() && CMainResetCheck())
{
CMiscIspDebugProc();
CTimerHandler();
CKeyHandler();
CModeHandler();
#if(_OSD_TYPE == _BENQ_OSD)
COsdHandlerBenq();
#else
COsdHandlerGeneric();
#endif
Alignment();
CDdcciHandler();
}
}
while(_TRUE);
}
//--------------------------------------------------
// System Initial
//--------------------------------------------------
void CMainSystemInitial(void)
{
// Initial MCU
CMcuInitial();
// Initial I/O state
CMainIOInitial();
#if(_D0_INPUT_PORT_TYPE == _D0_DP_PORT)
D0_HPD_LOW();
#elif(_D1_INPUT_PORT_TYPE == _D1_DP_PORT)
D1_HPD_LOW();
#endif
// Initial timer events
CTimerInitialTimerEvent();
// Check eeprom and load eeprom settings
CEepromStartupCheck();
CTimerDelayXms(200);
COsdDispInitial();
// If system power detection is fail, we will be locked here.
while(!CMainDetectSystemPower());
// V010 Patch Note (19) : Modify Source Scan Handler.
// Initial source settings
CSourceInitialSetting();
// Initial scaler settings
CScalerInitial();
// Initial key scan status
CKeyInitial();
#if(_TOUCH_SENSOR == _ON)
CKeyOneTouchSensorLedOff();
#endif
// DAC Chip reset
#if(_EXT_DAC_SUPPORT == _ON)
CHdmiResetDAC();
#endif
// Initial user settings
CMainUserInitial();
// Initial video settings
#if(_VIDEO_SUPPORT == _ON)
CVideoInitial();
#endif
// Initial uart settings
#if(_DEBUG_TOOL == _RS232)
CUartInitial();
#endif
#if(_DCR_MODE == _DCR_TYPE_3)
CDcrInitial();
#endif
#if(_DP_SUPPORT == _ON)
CMainDpIntInitial();
#endif
#if(_D0_INPUT_PORT_TYPE == _D0_DP_PORT)
D0_HPD_HIGH();
#elif(_D1_INPUT_PORT_TYPE == _D1_DP_PORT)
D1_HPD_HIGH();
#endif
#if(_AUDIO_SUPPORT == _ON)
CAdjustAudioMute(_ON);
#endif
CTimerEnaleTimerCount();
}
//--------------------------------------------------
// Description : I/O Initial
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CMainIOInitial(void)
{
CMiscSetPinShare();
CPowerPanelPowerOff();
CPowerLightPowerOff();
CScalerSetDataPortByte(_TCON_ADDR_PORT_8B, _TCON_RSDS_PWR_CTL_C3, 0x03);
#if(((_MCU_TYPE == _REALTEK_RTD2120) || (_MCU_TYPE == _REALTEK_RTD2122)) && (_WATCHDOG_TIMER == _ON) && (_SYSTEMPOWER_DETECT_SUPPORT == _ON))
MCU_WATCHDOG_TIMER_FF36 = 0x87;
#endif
}
//--------------------------------------------------
// Description : User Initial
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CMainUserInitial(void)
{
#if(_TOUCH_SENSOR == _ON)
bBUZZER = _HIGH;
#endif
D0_HPD_HIGH();
// User can make some initial settings at firmware startup
CLR_PANELPOWERSTATUS();
CLR_LIGHTPOWERSTATUS();
CLR_FRAMESYNCSTATUS();
CLR_POWERSWITCH();
CLR_FIRST_ADCCLOCK();
CLR_KEYREPEATENABLE();
#if(_HDMI_SUPPORT == _ON)
CLR_HDMIINPUT();
CLR_AUDIOPLLLOCKREADY();
CLR_AVRESUME();
CLR_AUDIOWAITINGTIMEOUT();
#endif
SET_FIRST_LOADFONT();
CLR_INTERLACE_MODE();
//Anderson 080129 for Filed Merge Support Start
#if(_FRC_SUPPORT == _ON)
CLR_FRCSTATUS();
CLR_FRC422STATUS();//Anderson 080422 for New FRC Structure
#if(_FIELD_MERGE_SUPPORT == _ON)
CLR_FIELDMERGE_MODE();
#endif
#endif // End of #if(_FRC_SUPPORT == _ON)
//Anderson 080129 for Filed Merge Support End
CLR_USE_TRANSITION_RESULT();
#if((_DEBUG_TOOL == _ISP_FOR_RTD2120) || (_DEBUG_TOOL == _ISP_FOR_EMBEDDED))
CDdcciInitial();
#endif
#if(_OSD_TYPE == _BENQ_OSD)
COsdBankSwitchCancelTimerBenq();
#else
COsdBankSwitchCancelTimerGeneric();
#endif
ucCurrState = _PWOFF_STATE;
CScalerPageSelect(_PAGEB);
CScalerSetByte(_PB_DP_PWR_CTL_B4,0x00);
CScalerSetByte(_PB_DP_Z0_CALIBRATION_B6,0x00);
if(GET_LASTPOWER_STATUS() == _OFF)
{
#if(_AUDIO_SUPPORT == _ON)
CAdjustAudioMute(_ON);
CAdjustAudioPower(_OFF);
#endif
#if(_TOUCH_SENSOR == _ON)
CKeyOneTouchSensorLedOff();
#endif
CLR_POWERSTATUS();
CPowerPanelOff();
CPowerADCAPLLOff();
CPowerLVDSOff();
CPowerDPLLOff();
CPowerPWMOff();
CScalerDisableDisplayTiming();
CPowerTMDSOff();
#if(_MCU_TYPE == _REALTEK_EMBEDDED)
CMcuSelectFlashClk(_XTAL_CLK); //yc 20080415
CTimerDelayXms(10);
#endif
CPowerM2PLLOff();//cyyeh 20080326
#if((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
CPowerMPLLOff(); // cyyeh 20080611
#endif
CScalerPageSelect(_PAGE0);
#if(_MCU_TYPE == _REALTEK_EMBEDDED)
CScalerSetBit(_P0_ADC_POWER_C6, ~(_BIT6 | _BIT5 | _BIT4 ), _BIT3);//0917 sephinroth
#else
//1126 sephinroth
CScalerSetBit(_P0_ADC_POWER_C6, ~(_BIT6 | _BIT5 | _BIT4 | _BIT3), 0);
#if(_PCB_TYPE == _RTD2545LR_QISDA_PCB)
MCU_PIN_SHARE2_FF02 = 0x0E;
#endif
#endif
CScalerSetByte(_P0_HS_SCHMITT_TRIGGER_CTRL_F4, 0x00);//0917 sephinroth
CScalerPageSelect(_PAGEB);
//CScalerSetByte(_PB_DP_PWR_CTL_B4,0x00);
//CScalerSetByte(_PB_DP_Z0_CALIBRATION_B6,0x00);
CScalerSetByte(_PB_DP_RESERVED_01_BB, 0x00); //0917 sephinroth
CScalerSetByte(_HOST_CTRL_01, 0x46);
CEepromSaveSystemData();
}
}
//--------------------------------------------------
// Description : System Power Detect
// Input Value : None
// Output Value : None
//--------------------------------------------------
bit CMainDetectSystemPower(void)
{
bit flag = 1;
#if(_SYSTEMPOWER_DETECT_SUPPORT == _ON)
// It's an example F/W for RTD2120.
MCU_ADC_CTRL_FF0B = 0x80;
while((MCU_ADC_CTRL_FF0B & _BIT7) != 0x00)
{
#if(((_MCU_TYPE == _REALTEK_RTD2120) || (_MCU_TYPE == _REALTEK_RTD2122)) && (_WATCHDOG_TIMER == _ON))
CTimerDelayXms(20);
MCU_WATCHDOG_TIMER_FF36 = MCU_WATCHDOG_TIMER_FF36 | 0x40;
#endif
}
if((bSYSTEMPOWERDETECT & 0xfc) < 0xe0)
flag = 0;
#endif // End of #if(_SYSTEMPOWER_DETECT_SUPPORT == _ON)
#if(((_MCU_TYPE == _REALTEK_RTD2120) || (_MCU_TYPE == _REALTEK_RTD2122)) && (_WATCHDOG_TIMER == _ON) && (_SYSTEMPOWER_DETECT_SUPPORT == _ON))
if(flag)
{
MCU_WATCHDOG_TIMER_FF36 = 0x00;
return _TRUE;
}
else
{
CTimerDelayXms(20);
MCU_WATCHDOG_TIMER_FF36 = MCU_WATCHDOG_TIMER_FF36 | 0x40;
return _FALSE;
}
#else
if(flag)
return _TRUE;
else
return _FALSE;
#endif // End of #if(((_MCU_TYPE == _REALTEK_RTD2120) || (_MCU_TYPE == _REALTEK_RTD2122)) && (_WATCHDOG_TIMER == _ON) && (_SYSTEMPOWER_DETECT_SUPPORT == _ON))
}
//--------------------------------------------------
// Description : Reset Check
// Input Value : None
// Output Value : None
//--------------------------------------------------
bit CMainResetCheck(void)
{
#if(_RESET_CHECK_SUPPORT == _ON)
WORD CheckCounter=0;
/* while(!GETSCALERSDIO3())
{
if(bSCALERSCLK)
CLRSCALERSCLK();
else
SETSCALERSCLK();
}
CScalerRead(_ID_REG_00, 1, pData, _NON_AUTOINC);
*/
#if(_SCALER_TYPE == _RTD2545LR)
do
{
CheckCounter++;
if(CheckCounter == 2000) return _FALSE;
CTimerDelayXms(1);
pData[0]=0xff;
CScalerRead(_ID_REG_00, 1, pData, _NON_AUTOINC);
}while((pData[0] != 0x51)&&(pData[0] != 0x52));
#endif
#if(_SCALER_TYPE == _RTD2545LR)
if(((pData[0] != 0x51)&&(pData[0] != 0x52)) || (!((bit)CScalerGetBit(_HOST_CTRL_01, _BIT6))))
#elif(_SCALER_TYPE == _RTD2472D)
if((pData[0] != 0x01) || (!((bit)CScalerGetBit(_HOST_CTRL_01, _BIT6))))
#elif((_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
if((pData[0] != 0x08) || (!((bit)CScalerGetBit(_HOST_CTRL_01, _BIT6))))
#else
No Setting !! //cyyeh 20080611
#endif
return _FALSE;
#endif // End of #if(_RESET_CHECK_SUPPORT == _ON)
return _TRUE;
}
//Anderson 080512 for Debug Message Support Start
/*
//Anderson 080213 for Debug Message Support Start
//--------------------------------------------------
// Debug Process
//--------------------------------------------------
void CMainIspDebugProc(void)
{
#if((_DEBUG_MESSAGE_SUPPORT == _ON) && ((_DEBUG_TOOL == _ISP_FOR_RTD2120) || (_DEBUG_TOOL == _ISP_FOR_EMBEDDED)))
//Debug Message Test Start
if(!GET_LIGHTPOWERSTATUS())
CMiscIspDebugProc("Current State =", ucCurrState);
//Debug Message Test End
CMiscIspDebugProc("", _NO_VALUE);
#else
CMiscIspDebugProc();
#endif
}
//Anderson 080213 for Debug Message Support End
*/
//Anderson 080512 for Debug Message Support End
//--------------------------------------------------
// DP initial Process
//--------------------------------------------------
#if(_DP_SUPPORT == _ON)
void CMainDpIntInitial(void)
{
#if (_DP_DEBUG == _ON)
pDataInt[0]=0;
pDataInt[1]=0;
pDataInt[2]=0;
pDataInt[3]=0;
pDataInt[4]=0;
#endif // end of #if (_DP_DEBUG == _ON)
IE|=0x01;
IP|=0x01;
CDpInitial();
CDpInterruptInitial();
SET_DPHOTPLUG();
}
#endif //End of #if(_DP_SUPPORT == _ON)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -