?? detect.c
字號:
#include <math.h>
#include "types.h"
#include "global.h"
#include "ms_reg.h"
#include "board.h"
#include "ms_rwreg.h"
#include "power.h"
#include "debug.h"
#include "misc.h"
#include "menu.h"
#include "UserPref.h"
#include "msOSD.h"
#include "mStar.h"
#include "Adjust.h"
#define DetectMsg 1
#if DetectMsg
#define Out_i printData
#define Out_s printMsg
#else
#define Out_i
#define Out_s
#endif
#define HPeriod_Torlance 10 // for mode change
#define VTotal_Torlance 10 // for mode change
// time of one loop is 34 when no input
#define ValidTimingStableCount 30//15
#define SyncLossStableCount 20//30
#define SwitchInputPortCount 10//15 // half or SyncLossStableCount to disable osd while switch input port
#define SwitchAnalogCount 10//15//7 // switch SOG/CSync-Separate by 4 times on switch input port
#define HFreq_Torlance 15 // 1.5 KHz
#define VFreq_Torlance 15 // 1.5 Hz
#define VTotal_Delta 50
#define MaxInputHFreq 855 // 80.0 KHz
#define MinInputHFreq 100//285 // 28.5 KHz
#define MaxInputVFreq 765//865 // 76.5 Hz
#define MinInputVFreq 400 // 50.0 Hz
extern InputModeType code StandardMode[];
extern BYTE InputTimingStableCounter;
extern BYTE TimingChangeDebunce;
BYTE code DVIPhaseTbl[];
BYTE mStar_FineTuneDVIPhase(BYTE channelReg,BYTE channel);
Bool mStar_FindMode(void);
BYTE mStar_GetInputStatus(void);
Bool IsCableNotConnected(void);
Bool mStar_SyncLossStateDetect(void);
Bool mStar_ValidTimingDetect(void);
void mStar_AutoDVI(void);
//*******************************************************************
// Function Name: mStar_MonitorInputTiming
//
// Decscription: Detect input timing
//
// callee: mStar_SyncLossStateDetect(), mStar_ValidTimingDetect(), mStar_AutoDVI() in detect.c
// mStar_SetInputPort(), mStar_SetAnalogInputPort() in mstar.c
//
// caller: main() in main.c
//*******************************************************************
void mStar_MonitorInputTiming(void)
{
if (!PowerOnFlag)
return;
// detect whether input signal is changing
if (!InputTimingChangeFlag)
{
if (SyncLossState())
{
if (!FreeRunModeFlag)
Set_InputTimingChangeFlag();
else if (mStar_SyncLossStateDetect()) // detect mode while no Sync/suspend/standby/disconnect
{
Set_InputTimingChangeFlag();
}
else if (InputTimingStableCounter)
{
// input timing is stable
if (InputTimingStableCounter%SwitchInputPortCount==0)
{
// switch input port while current port has no input.
// detection time for each port is programmable according to requirement
SrcInputType=(SrcInputType+1)%Input_Nums;
mStar_SetupInputPort();
if (SrcInputType==Input_Digital)
mStar_AutoDVI(); //do auto tracking DVI
}
}
}
else // valid timing
{
// check if input timing is changing
if (mStar_ValidTimingDetect())
{
SrcFlags|=SyncLoss;
Set_InputTimingChangeFlag();
}
}
}
//=============================================================================
//=============================================================================
if (InputTimingChangeFlag) // input timing is unstable
{
Clr_InputTimingChangeFlag();
Clr_DoModeSettingFlag();
TimingChangeDebunce++;
if (!SyncLossState())// && !InputTimingStableFlag) // prevent from SOG
{
if (TimingChangeDebunce<=3)
{
SrcFlags|=SyncLoss;
return;
}
}
mStar_PrepareForTimingChange();
// Power_TurnOffGreenLed(); // turn off green led
// Power_TurnOnAmberLed(); // turn on amber led
}
else // input timing is stable
{
TimingChangeDebunce=0;
InputTimingStableCounter++; // counter timing stable times
if (InputTimingStableCounter==0)
InputTimingStableCounter=1;
if (!InputTimingStableFlag)
{
if ((!SyncLossState() && InputTimingStableCounter>=ValidTimingStableCount) || // set timing stable flag
(SyncLossState() && InputTimingStableCounter>=SyncLossStableCount))
{
Set_InputTimingStableFlag();// set flag to search for input mode
Set_DoModeSettingFlag();
//printData("input timing stable %d", SrcInputType);
}
}
}
}
//*******************************************************************
// Function Name: mStar_ModeHandler
//
// Decscription: Programming scaler while input timing is changing
//
// callee: mStar_SyncLossStateDetect(), mStar_ValidTimingDetect(), mStar_AutoDVI() in detect.c
// mStar_SetInputPort(), mStar_SetAnalogInputPort() in mstar.c
//
// caller: main() in main.c
//*******************************************************************
void mStar_ModeHandler(void)
{
if (!DoModeSettingFlag) // while timing change & stable
return;
Clr_DoModeSettingFlag();
if (!SyncLossState()) // no sync
{
if (!mStar_FindMode()) // search mode index
{
Set_InputTimingChangeFlag(); // search mode faile
return;
}
if (!UnsupportedModeFlag) //supported mode
{
Out_i("input timing index = %d", SrcModeIndex);
ReadModeSetting(); // restore user's settings from NVRAM for each mode
if (mStar_SetupMode()==FALSE) // setup scaler
{
Set_InputTimingChangeFlag(); // setup mode failed
mStar_SetupFreeRunMode(); // setup freerun mode
Out_s("Failed to setup mode");
return;
}
if (UnsupportedModeFlag)
{
Out_s("Failed: Out of panel spec");
}
}
else
Out_s("unsupported mode");
}
if (SyncLossState() || UnsupportedModeFlag)
{
mStar_SetupFreeRunMode(); // setup freerun mode
// Power_TurnOffGreenLed(); // turn off green led
// Power_TurnOnAmberLed(); // turn on amber led
}
else
{
if(!FactoryModeFlag)
{
Power_TurnOnGreenLed(); // turn on green led
Power_TurnOffAmberLed(); // turn off amber led
}
else
{
Power_TurnOffGreenLed(); // turn off green led
Power_TurnOnAmberLed(); // turn on amber led
}
}
if (!CableNotConnectedFlag || !SyncLossState())
{
if (DoBurninModeFlag)
{
Clr_DoBurninModeFlag();
mStar_WriteByte(FWC, 0); // disable background color function.
}
}
Power_TurnOnPanel(); // turn on panel
Menu_InitAction(); // initial menu osd state
//jon add
if (FlgPowerOnOpenAudio && PowerOnFlag) //for void bo-bo voice
{
FlgPowerOnOpenAudio=0;
VolumeMuteOff(); //open volume
}
}
void mStar_PrepareForTimingChange(void)
{
PowerDownCounter=0;
Clr_ForcePowerSavingFlag();
Clr_InputTimingStableFlag(); // reset input timing stable and wait for timing stable
if (PowerSavingFlag)
Power_PowerOnSystem();
else
Power_TurnOffPanel();
mStar_SetupFreeRunMode();
Osd_Hide();
#if UseINT
mStar_WriteByte(INTENA, 0);
#endif
if (InputTimingStableFlag)
{
mStar_WriteByte(SWRST, GPR_B|ADCR_B);// Reset Graphic port to re-counter input hfreq & vtotal
Delay1ms(3);
mStar_WriteByte(SWRST, 0);
Delay1ms(20);
if (SrcInputType==Input_Digital)
{
mStar_WriteByte(MISCFC, 0x20);
mStar_AutoDVI();
}
}
InputTimingStableCounter=0;
SrcFlags&=~(bUnsupportMode|bUserMode|bNativeMode);
mStar_WriteByte(DBFC, 0x00); // enable double bufer.
mStar_WriteByte(REGBK, REGBANKADC);
mStar_WriteByte(DBFC, 0x00); // enable ADC's double bufer.
mStar_WriteByte(REGBK, REGBANKSCALER);
}
//==========================================================
BYTE GetBestBandwidth(BYTE channel, BYTE *errA)
{
BYTE errB;
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
mStar_WriteByte(TESTEN, channel|TSTEN_B); // set test channed
mStar_WriteByte(TESTA0, 0x20); // set high bandwidth
mStar_WriteByte(TESTEN, channel); // set test channed
Delay1ms(1);
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
*errA=mStar_ReadByte(DVI_ERST);
mStar_WriteByte(TESTEN, channel|TSTEN_B); // set test channed
#if ChipID>=ChipAD
mStar_WriteByte(TESTA0, 0x08); // set medium bandwidth
#else
mStar_WriteByte(TESTA0, 0x00); // set medium bandwidth
#endif
mStar_WriteByte(TESTEN, channel); // set test channed
Delay1ms(1);
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
errB=mStar_ReadByte(DVI_ERST);
mStar_WriteByte(TESTEN, channel); // set test channed
#if ChipID>=ChipAD
if (*errA>errB)
{
*errA=errB;
return 0x8;
}
#else
if (*errA>errB)
{
*errA=errB;
return 0x0;
}
#endif
return 0x20;
}
BYTE mStar_FineTuneBandwidth(void)
{
BYTE errRed, bwRed;
BYTE errGreen, bwGreen;
BYTE errBlue, bwBlue;
bwRed=GetBestBandwidth(RED_CHANNEL, &errRed);
bwGreen=GetBestBandwidth(GREEN_CHANNEL, &errGreen);
bwBlue=GetBestBandwidth(BLUE_CHANNEL, &errBlue);
if (errRed>errGreen)
{
if (errGreen>errBlue)
return bwBlue;
else
return bwGreen;
}
else
{
if (errRed>errBlue)
return bwBlue;
else
return bwRed;
}
}
BYTE code DVIPhaseTbl[]=
{// 0 1 2 3 4 5 6 7 8 9
0x40, 0x01, 0x03, 0x07, 0x0F, 0x17, 0x13, 0x11, 0x10, 0x31,
0x33, 0x37, 0x3F, 0x27, 0x23, 0x21, 0x20, 0x61, 0x63, 0x67,
0x6F, 0x77, 0x73, 0x71, 0x70, 0x51, 0x53, 0x57, 0x5F, 0x47,
0x43, 0x41
};
BYTE code DVIPhaseTbl2[]=
{// 0 4 8 12 16 20 24 28
0x00, 0x1F, 0x30, 0x2F, 0x60, 0x7F, 0x50, 0x4F
};
BYTE GetLinearPhaseValue(BYTE value)
{
BYTE i;
for (i=0; i<0x20; i++)
if (DVIPhaseTbl[i]==value)
break;
if (i>=0x20)
{
for (i=0; i<8; i++)
if (DVIPhaseTbl2[i]==value)
break;
if (i>=8)
i=0;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -