📄 detect.c
字号:
}
void mStar_AutoDVI(void)
{ BYTE checkTimes=16;
BYTE rtValue=0x10;
BYTE regValue;
mStar_WriteByte(REGBK, REGBANKADC);
// auto-setting resistor impendence
mStar_WriteByte(RT_CTL, rtValue);
mStar_WriteByte(TESTEN, 0x00); // normal status
mStar_WriteByte(TESTEN, RDST_B); // freeze/read status
while (checkTimes--)
{ mStar_WriteByte(TESTEN, 0x00);
Delay1ms(1);
mStar_WriteByte(TESTEN, RDST_B); // freeze/read status
regValue=mStar_ReadByte(RT_STATUS2);
if (regValue&BIT7)
rtValue++;
else
rtValue--;
rtValue&=0x1F;
mStar_WriteByte(RT_CTL, rtValue);
}
mStar_WriteByte(TESTEN, 0x00); // normal status
// set best bandwidth
regValue=mStar_FineTuneBandwidth();
mStar_WriteByte(TESTEN, TSTEN_B);
mStar_WriteByte(TESTA0, regValue);
mStar_WriteByte(TESTEN, 0);
mStar_WriteByte(REGBK, REGBANKSCALER);
}
Bool mStar_SyncLossStateDetect(void)
{ BYTE fStatus;
Bool result=FALSE;
fStatus=mStar_GetInputStatus();
// printData("status %xH", fStatus);//mStar_ReadByte(INSTA));
// printData("stable counter %d", InputTimingStableCounter);
if (fStatus&SyncLoss)
{ if (SrcInputType<Input_Digital)
{ mStar_SetAnalogInputPort(); // switch to SOG
fStatus=mStar_GetInputStatus();
if (fStatus&SyncLoss)
{ mStar_SetAnalogInputPort(); // switch to Separate
fStatus=mStar_GetInputStatus();
if (!(fStatus&SyncLoss))
goto SyncActive;
}
else // input timing is coming
{
#if 0 //ChipID>=ChipAD
mStar_SetAnalogInputPort(); // switch to Separate
fStatus=mStar_GetInputStatus(); // check separate sync again
if (fStatus&SyncLoss)
{
mStar_SetAnalogInputPort(); // switch to SOG again
if (!(fStatus&SyncLoss))
goto SyncActive;
}
else
#endif
goto SyncActive;
}
}
#if NoCable_Detect_Enable
if (CableNotConnectedFlag) // no Cable
{ if (!IsCableNotConnected())
{ Clr_CableNotConnectedFlag();
result=FALSE;//TRUE;
}
}
else if (IsCableNotConnected()) // no Sync
{ Set_CableNotConnectedFlag();
result=FALSE;//TRUE;
}
#endif
if (PowerSavingFlag)
{ if (SrcInputType==Input_Digital)
{ if (!(mStar_ReadByte(INTCTRL)&0x40) && !(mStar_ReadByte(STATUS2)&0xF0))
{
#if 1//Albert 20031103 add for Ti4200 DVI output clock error
mStar_PowerUp();
#if NEWIC_18A
mStar_WriteByte(MISCFC, 0x28);
#else
mStar_WriteByte(MISCFC, 0x20);
#endif
mStar_AutoDVI();
Delay1ms(5);
if(!mStar_ValidTimingDetect())
{
fStatus&=~SyncLoss;
result=TRUE;
//printMsg("Digital get signal in saving !!");
}
else
mStar_PowerDown();
#else
fStatus&=~SyncLoss;
result=TRUE;
//printMsg("Digital get signal in saving !!");
#endif
}
}
else if (SrcInputType==Input_YPbPr && mStar_ReadByte(STATUS2)&0x50)
{ if (abs(HFreq(mStar_ReadWord(HSPRD_H))-156)<20)
{ fStatus&=~SyncLoss;
result=TRUE;
}
}
}
}
else
SyncActive:
result=TRUE;
if (result)
SrcFlags=(SrcFlags&0xF0)|fStatus; // clear others flags, except sync informat (polarity & w/o)
return result;
}
Bool mStar_ValidTimingDetect(void)
{ BYTE fStatus;
fStatus=mStar_GetInputStatus();
if (fStatus&SyncLoss) // no sync
{ SrcFlags=(SrcFlags&0xF0)|fStatus; // clear others flags, except sync informat (polarity & w/o)
return TRUE;
}
else
{ if (SyncPolarity(SrcFlags)!=SyncPolarity(fStatus)) // Sync polarity changed
{ SrcFlags=(SrcFlags&0xF0)|fStatus; // clear others flags, except sync informat (polarity & w/o)
if(SrcInputType==Input_656Video)
return FALSE;
return TRUE;
}
else
{ WORD tempPeriod;
SrcFlags=(SrcFlags&0xF0)|fStatus; // clear others flags, except sync informat (polarity & w/o)
tempPeriod=mStar_ReadWord(HSPRD_H)&0x1FFF;
// #if DEBUG_ENABLE
// printData("HPeriod %d", tempPeriod);
// #endif
if (InputTimingStableCounter==0)
SrcHPeriod=tempPeriod;
#if EnableVideo656Port
if(SrcInputType!=Input_656Video)
#endif
{
if (abs(tempPeriod-SrcHPeriod)>HPeriod_Torlance) // HPeriod changed
{
#if DEBUG_ENABLE
printData("HPeriod %d", tempPeriod);
#endif
return TRUE;
}
}
tempPeriod=mStar_ReadWord(VTOTAL_H)&0x7FF;
//printData("VTotal %d", tempPeriod);
if (InputTimingStableCounter==0)
SrcVTotal=tempPeriod;
if (abs(tempPeriod-SrcVTotal)>VTotal_Torlance) // vtotal changed
{
#if DEBUG_ENABLE
printData("VTotal %d", tempPeriod);
#endif
#if EnableVideo656Port
if(SrcInputType == Input_656Video)
{
if((tempPeriod<(DefVideoPalModeVTotal+VideoVTotal_Torlance))&&(tempPeriod>(DefVideoNtscModeVTotal-VideoVTotal_Torlance)))
{
return TRUE;
}
}
else
#endif
return TRUE;
}
}
}
return FALSE;
}
Bool mStar_FindMode(void)
{ WORD hFreq, vFreq;
#define fStatus hFreq
fStatus=mStar_GetInputStatus();
if (SyncPolarity(SrcFlags)!=SyncPolarity(fStatus)) // Sync polarity changed
return FALSE;
SrcFlags&=0x0F;
#undef fStaus
#if EnableVideo656Port
//Vick auto switch option
if((SrcInputType == Input_656Video)&&SyncLossState())
{
if( 0)//EnableDeinterlaceChipFlag)
{
hFreq = DefaultVideoPModeHTotal;
vFreq = DefaultVideoPModeVTotal;
}
else
{
hFreq = DefaultVideoModeHTotal;
vFreq = DefaultVideoModeVTotal;
}
}
else
{
if(SrcInputType == Input_656Video)
{
hFreq = SrcHPeriod;
vFreq = SrcVTotal;
}
else
#endif
{
hFreq=mStar_ReadWord(HSPRD_H)&0x1FFF;
if (abs(hFreq-SrcHPeriod)>HPeriod_Torlance) // HPeriod changed
return FALSE;
vFreq=mStar_ReadWord(VTOTAL_H)&0x7FF;
if (abs(vFreq-SrcVTotal)>VTotal_Torlance) // vtotal changed
return FALSE;
}
}
/////////////////////////////////////////////////////////
SrcHPeriod=hFreq;
SrcVTotal=vFreq;
hFreq=HFreq(SrcHPeriod);//((DWORD)MST_CLOCK_MHZ*10+SrcHPeriod/2)/SrcHPeriod; // round 5
vFreq=VFreq(hFreq, SrcVTotal);//((DWORD)hFreq*1000+(SrcVTotal/2))/SrcVTotal;
SrcVFreq=vFreq;
//======== for interlace mode
if (SrcInputType!=Input_Digital && mStar_ReadByte(STATUS2)&INTM_B)
{ SrcFlags|=bInterlaceMode;
vFreq*=2;
}
//====================================
#if DEBUG_ENABLE
printData("HFreq = %d", hFreq);
printData("VFreq = %d", vFreq);
#endif
#if !OutRange_Display // if unsupport must to display sail modify 200400715
// check if input timing is out of range
if (hFreq>MaxInputHFreq || hFreq<MinInputHFreq || vFreq>MaxInputVFreq || vFreq<MinInputVFreq)
{ SrcFlags|=bUnsupportMode;
Set_UnsupportedModeFreerunFlag();
return TRUE;
}
#endif
// search input mode index
{ BYTE modeIndex=0;
InputModeType *modePtr=StandardMode;
Bool found=FALSE;
#if EnableVideo656Port
if((SrcInputType == Input_656Video)||UserPrefInputType==Input_YPbPr) //jt modify YPbPr & YCbCr to compatible! 2004-03-29
{
modePtr=&StandardMode[30];//offset to avoid low 640*480
modeIndex = 30;
}
#endif
while (modePtr->HFreq)
{
if (SrcVTotal>StandardModeResolution[modePtr->ResIndex].DispHeight)
{
if (abs(hFreq-modePtr->HFreq)<HFreq_Torlance && abs(vFreq-modePtr->VFreq)<VFreq_Torlance &&
GetSyncPolarity(SrcFlags)&modePtr->Flags &&
(SrcFlags&bInterlaceMode)==(modePtr->Flags&bInterlaceMode))
{ found=TRUE;
SrcModeIndex=modeIndex;
break;
}
}
modePtr++;
modeIndex++;
}
#if WidePanel // sail add
//printData("sail fine mode %d", SrcModeIndex); // sail add
// 6: 640x480 60Hz 12: 800x600 60Hz 17: 1024x768 60Hz 40: 1280x768 60Hz 41: 1280x800 60Hz // sail add
// 0: 640x350 70Hz 2: 720x400 70Hz
if(SrcModeIndex!=6 && SrcModeIndex!=12 && SrcModeIndex!=17 && SrcModeIndex!=40
&& SrcModeIndex!=41 && SrcModeIndex!=0 && SrcModeIndex!=2)
{
SrcFlags|=bUnsupportMode; // out of range
}
#endif
#if WidePanel_16_9
if((SrcModeIndex>21&& SrcModeIndex<26)|| (SrcModeIndex>28 && SrcModeIndex<32)|| SrcModeIndex==44)
{
SrcFlags|=bUnsupportMode;
Set_UnsupportedModeFreerunFlag();
return TRUE;
}
#endif
if (!found) // out of standard input range
{
#if DEBUG_ENABLE
printMsg("cannot find mode in standard mode");
#endif
#define delta hFreq
#define minDelta vFreq
modeIndex=0;
modePtr=StandardMode;
minDelta=VTotal_Delta;
while (modePtr->HFreq)
{ if (SrcVTotal>StandardModeResolution[modePtr->ResIndex].DispHeight)
{ delta=abs(SrcVTotal-(modePtr->VTotal));
if (delta<VTotal_Delta && (SrcFlags&bInterlaceMode)==(modePtr->Flags&bInterlaceMode))
{ if (delta<minDelta)
{ minDelta=delta;
SrcModeIndex=modeIndex;
}
SrcFlags|=bUserMode;
found=TRUE;
}
}
modePtr++;
modeIndex++;
}
#undef delta
#undef minDelta
} // out of standard input range
#if DEBUG_ENABLE
printData("sail debuge SrcModeIndex = %d",SrcModeIndex);
#endif
// if unsupport must to display sail modify 200400715
#if OutRange_Display
// check if input timing is out of range
if (hFreq>MaxInputHFreq || hFreq<MinInputHFreq || vFreq>MaxInputVFreq || vFreq<MinInputVFreq
||(SrcModeIndex<43&&SrcModeIndex>39) ||SrcModeIndex==36)
{ SrcFlags|=bUnsupportMode;
}
#endif
if (!found)
SrcFlags|=bUnsupportMode;
} // search mode index
return TRUE;
}
//
BYTE mStar_GetInputStatus(void)
{ BYTE fStatus=0;
WORD inputValue;
BYTE status;
inputValue=mStar_ReadWord(HSPRD_H)&0x1FFF;
if (inputValue==0x1FFF || inputValue<10)
{
fStatus|=bHSyncLoss;
//#if DEBUG_ENABLE
//printMsg("HSyncLoss");
//#endif
}
inputValue=mStar_ReadWord(VTOTAL_H)&0x7FF;
if (inputValue==0x7FF || inputValue<200)
{
fStatus|=bVSyncLoss;
//#if DEBUG_ENABLE
//printMsg("VSyncLoss");
//#endif
}
status=mStar_ReadByte(STATUS2);
fStatus|=(status&0x03); // Get input timing polarity
if (SrcInputType==Input_Digital) // input timing is valid while current state is no sync
{ if (mStar_ReadByte(INTCTRL)&0x40)
{ fStatus|=SyncLoss;
//printMsg("no digital");
}
}
#if EnableVideo656Port
//Vick auto switch option
else if (SrcInputType==Input_656Video)
{
if(SyncLossState())
status = 3;
else
status = 15;
if( 1)//VideoDecoderDetectSync(status))
{
inputValue=mStar_ReadWord(VTOTAL_H)&0x7FF;
if((inputValue<(DefVideoPalModeVTotal+VideoVTotal_Torlance))&&(inputValue>(DefVideoNtscModeVTotal-VideoVTotal_Torlance)))
fStatus &= ~SyncLoss;
else
{
fStatus|=SyncLoss;
}
}
else
{
//printMsg("NO2");
fStatus|=SyncLoss;
}
fStatus &= 0xfc;//mask the polarity
//printData("Fs=%d", fStatus);
}
#endif
else if (SyncLossState() && !(fStatus&SyncLoss)) // input timing is valid while current state is no sync
{ if (SrcInputType<Input_Digital && status&INTM_B)
{ mStar_WriteByte(SWRST, GPR_B);
Delay1ms(1);
mStar_WriteByte(SWRST, 0);
}
Delay1ms(20);
if (InputTimingChangeFlag)
return fStatus;
status=status&mStar_ReadByte(STATUS2);
if ((status&3)!=(fStatus&3)) // polarity is stable
fStatus|=SyncLoss;
else if (status&0x30) // SOG or CSync input
{ Delay1ms(20);
if (InputTimingChangeFlag)
return fStatus;
status=mStar_ReadByte(STATUS2);
// Check if SOG/CSYNC is valid
if (abs(mStar_ReadWord(VTOTAL_H)-inputValue)>2)
fStatus|=SyncLoss;
else if (SrcInputType==Input_YPbPr)
{ if ((status&0x18)!=0x18)
fStatus|=SyncLoss;
}
#if 1 //ChipID>=ChipAD
else if (status&SOGD_B && mStar_ReadByte(SOGHSPW)>mStar_ReadWord(HSPRD_H)/5)
{ fStatus|=SyncLoss;
}
#else // befor ChipAD
else if ((status&0x50)==0x50 || (status&0xA0)==0xA0)
fStatus|=SyncLoss;
#endif
else if ((status&0x18)==0x18)
fStatus|=SyncLoss; // Check if SOG/CSYNC is valid
}
}
return fStatus;
}
#if (NEWIC_18A||NEWIC_18B)
void CheckADC(void)
{
BYTE i,j,temp,ErrorCount=0;
mStar_WriteByte(REGBK, REGBANKADC);
temp=mStar_ReadByte(TESTEN);
for(i=0;i<3;i++){
for(j=0;j<3;j++){
mStar_WriteByte(TESTEN,j);
if((mStar_ReadByte(0x1A)==0x7f&&mStar_ReadByte(0x19)==0xFF)||(mStar_ReadByte(0x1A)==0x80&&mStar_ReadByte(0x19)==0x00)){
ErrorCount++;
}
}
}
mStar_WriteByte(TESTEN, temp);
mStar_WriteByte(REGBK, REGBANKSCALER);
if(ErrorCount>=i){
mStar_WriteByte(SWRST, ADCR_B);
mStar_WriteByte(SWRST, 0);
//printMsg("Reset ADC");
}
}
#endif
#if NoCable_Detect_Enable
Bool IsCableNotConnected(void)
{
#if Dual_Input_Icon_Enable
return (SrcInputType)?(!hwDVICable_Pin):(hwDSUBCable_Pin);
#else
return hwDSUBCable_Pin;
#endif
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -