📄 d0361_drv.c
字号:
offset=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_CRL_FREQ3);
offset <<=16;
offsetvar=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_CRL_FREQ2);
offsetvar <<=8;
offset = offset | offsetvar;
offsetvar=0;
offsetvar=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_CRL_FREQ1);
offset =offset | offsetvar ;
if(signvalue==1)
{
offset |=0xff000000;/*** Here sign extension made for the negative number**/
}
offset =offset /16384;/***offset calculation done according to data sheet of STV0360***/
if(pResult->Mode==0)
{
/*******it is 2k mode***************/
offset=((offset*4464)/1000);/*** 1 FFT BIN=4.464khz***/
}
else
{
/*******it is 8k mode***************/
offset=((offset*11)/10);/*** 1 FFT BIN=1.1khz***/
}
offset= offset*2; /*** In 361 actual offset shown is half***/
/****This block of code ensures the frequency to be corrected only when***
*** the offset is in range between 140khz to 180khz both positive and negative***
****direction . This takes care of 166khz offset which sometimes needed******
****to get far away from some interfering analog carrier in some European countries.*****/
/* if(((offset>=140) && (offset<=180)) ||((offset<=-140) && (offset>=-180)))
{
pParams->Frequency-=offset;
}*/
/*** Here +/-166 khz offset taken into consideration and the excess
offset lying between +/- 140 to 180 khz will be returned to
user for fine tunning ****/
if((offset>=140) && (offset<=180))
{
if(pResult->Sense==0)
{
pParams->Frequency +=166;
}
else
{
pParams->Frequency -=166;
}
}
else if((offset<=-140) && (offset>=-180))
{
if(pResult->Sense==0)
{
pParams->Frequency -=166;
}
else
{
pParams->Frequency +=166;
}
}
/***pResult data structure retains the recent data after tuner locks***/
pResult->Frequency=pParams->Frequency;
/************************************************************************/
pResult->Echo_pos=STTUNER_IOREG_GetField(DeviceMap,IOHandle,LONG_ECHO);
if(pParams->TrlNormRateFineTunning == FALSE)
{
/* fine tuning of timing offset if required */
STTUNER_IOREG_GetContigousRegisters(DeviceMap,IOHandle,R_TRL_CTL,5,trl_ctl);
timing_offset=trl_ctl[3]+ 256*trl_ctl[4];
if (timing_offset>=32768) timing_offset-=65536;
trl_nomrate= (512*trl_ctl[2]+trl_ctl[1]*2 + ((trl_ctl[0]&0x80)>>7));
timing_offset=((signed)(1000000/trl_nomrate)*timing_offset)/2048;
if (timing_offset<=0)
{
timing_offset=(timing_offset-11)/22;
step=-1;
}
else
{
timing_offset=(timing_offset+11)/22;
step=1;
}
for (counter=0;counter<abs(timing_offset);counter++)
{
trl_nomrate+=step;
Rtrl_ctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_TRL_CTL);
trl_ctl1[0]=((trl_nomrate%2)<<7) | (Rtrl_ctl & 0x7f) ;
trl_ctl1[1]=trl_nomrate/2;
STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R_TRL_CTL,trl_ctl1,2);
SystemWaitFor(1);
}
pParams->TrlNormRateFineTunning =TRUE;
if(pParams->ChannelBWStatus == STTUNER_CHAN_BW_6M)
{
pParams->Channel_6M_Trl_Done = TRUE;
pParams->Channel_6M_Trl[0] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_LSB);
pParams->Channel_6M_Trl[1] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_LO);
pParams->Channel_6M_Trl[2] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_HI);
}
if(pParams->ChannelBWStatus == STTUNER_CHAN_BW_7M)
{
pParams->Channel_7M_Trl_Done = TRUE;
pParams->Channel_7M_Trl[0] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_LSB);
pParams->Channel_7M_Trl[1] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_LO);
pParams->Channel_7M_Trl[2] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_HI);
}
if(pParams->ChannelBWStatus == STTUNER_CHAN_BW_8M)
{
pParams->Channel_8M_Trl_Done = TRUE;
pParams->Channel_8M_Trl[0] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_LSB);
pParams->Channel_8M_Trl[1] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_LO);
pParams->Channel_8M_Trl[2] = STTUNER_IOREG_GetField(DeviceMap,IOHandle,TRL_NOMRATE_HI);
}
/* end of fine tuning */
}/*** End of if(pParams->TrlNormRateFineTunning == FALSE) ***/
}
else
pResult->Locked = FALSE;
error = FE_361_SEARCH_FAILED;
}
else
error = FE_361_BAD_PARAMETER;
}
else
error = FE_361_INVALID_HANDLE;
pResult->SignalStatus = pParams->State;
pResult->State = STTUNER_IOREG_GetField(DeviceMap,IOHandle,CORE_STATE_STAT);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,FORCE, (pParams->Force & 2)>>1);
return error;
}
/*****************************************************
--FUNCTION :: FE_361_Search
--ACTION :: Search for a valid transponder
--PARAMS IN :: Handle ==> Front End Handle
pSearch ==> Search parameters
pResult ==> Result of the search
--PARAMS OUT:: NONE
--RETURN :: Error (if any)
--***************************************************/
FE_361_Error_t FE_361_Search(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle,FE_361_InternalParams_t *pParams, FE_361_SearchResult_t *pResult,STTUNER_tuner_instance_t *TunerInstance)
{
U8 trl_ctl[3],gain_src[2];
FE_361_Error_t error = FE_361_NO_ERROR;
U8 Rgain_src,Rtrl_ctl;
#ifndef HOST_PC
if (pParams->ChannelBW == STTUNER_CHAN_BW_6M)
{
Rgain_src=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_GAIN_SRC1);
gain_src[0]=(Rgain_src & 0xf0) | M6_F_GAIN_SRC_HI;
gain_src[1]=M6_F_GAIN_SRC_LO;
STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R_GAIN_SRC1,gain_src,2);
if(pParams->Channel_6M_Trl_Done == FALSE)
{
Rtrl_ctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_TRL_CTL);
trl_ctl[0]=(Rtrl_ctl & 0x7f) | (M6_F_TRL_NOMRATE0<<7);
trl_ctl[1]=M6_F_TRL_NOMRATE8_1;
trl_ctl[2]=M6_F_TRL_NOMRATE16_9;
}/*** end of if(pParams.Channel_6M_Trl_Done == FALSE)**/
else
{
Rtrl_ctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_TRL_CTL);
trl_ctl[0]=(Rtrl_ctl & 0x7f) | (pParams->Channel_6M_Trl[0]<<7);
trl_ctl[1]=pParams->Channel_6M_Trl[1];
trl_ctl[2]=pParams->Channel_6M_Trl[2];
}/*** end of ELSE of if(pParams->Channel_6M_Trl_Done == FALSE)**/
STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R_TRL_CTL,trl_ctl,3);
}/*** end of STTUNER_CHAN_BW_6M ***/
else if (pParams->ChannelBW == STTUNER_CHAN_BW_7M)
{
Rgain_src=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_GAIN_SRC1);
gain_src[0]=(Rgain_src & 0xf0) | M7_F_GAIN_SRC_HI;
gain_src[1]=M7_F_GAIN_SRC_LO;
STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R_GAIN_SRC1,gain_src,2);
if(pParams->Channel_7M_Trl_Done == FALSE)
{
Rtrl_ctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_TRL_CTL);
trl_ctl[0]=(Rtrl_ctl & 0x7f) | (M7_F_TRL_NOMRATE0<<7);
trl_ctl[1]=M7_F_TRL_NOMRATE8_1;
trl_ctl[2]=M7_F_TRL_NOMRATE16_9;
}/*** end of if(pParams->Channel_7M_Trl_Done == FALSE) **/
else
{
Rtrl_ctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_TRL_CTL);
trl_ctl[0]=(Rtrl_ctl & 0x7f) | (pParams->Channel_7M_Trl[0]<<7);
trl_ctl[1]=pParams->Channel_7M_Trl[1];
trl_ctl[2]=pParams->Channel_7M_Trl[2];
}/*** end of ELSE if(pParams->Channel_7M_Trl_Done == FALSE) **/
STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R_TRL_CTL,trl_ctl,3);
}/**** End of STTUNER_CHAN_BW_7M ***/
else /* Channel Bandwidth = 8M) */
{
Rgain_src=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_GAIN_SRC1);
gain_src[0]=(Rgain_src & 0xf0) |M8_F_GAIN_SRC_HI;
gain_src[1]=M8_F_GAIN_SRC_LO;
STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R_GAIN_SRC1,gain_src,2);
if(pParams->Channel_8M_Trl_Done == FALSE)
{
Rtrl_ctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_TRL_CTL);
trl_ctl[0]=(Rtrl_ctl & 0x7f)| (M8_F_TRL_NOMRATE0<<7);
trl_ctl[1]=M8_F_TRL_NOMRATE8_1;
trl_ctl[2]=M8_F_TRL_NOMRATE16_9;
}/*** end of if(pParams->Channel_8M_Trl_Done == FALSE) **/
else
{
Rtrl_ctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_TRL_CTL);
trl_ctl[0]=(Rtrl_ctl & 0x7f) | (pParams->Channel_8M_Trl[0]<<7);
trl_ctl[1]=pParams->Channel_8M_Trl[1];
trl_ctl[2]=pParams->Channel_8M_Trl[2];
}/*** end of ELSE of if(pParams->Channel_8M_Trl_Done == FALSE) **/
STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R_TRL_CTL,trl_ctl,3);
}/*** end of STTUNER_CHAN_BW_8M ***/
#endif
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,pParams->EchoPos) ;
/* dcdc */
#ifdef HOST_PC
repeator = TunerGetRepeator();
TunerSetRepeator(1);
#endif
/** error checking is done here for the fix of the bug GNBvd20315 **/
error=FE_361_TunerSet(TunerInstance->DrvHandle,pParams);
if(error != FE_361_NO_ERROR )
{
return error;
}
#ifdef HOST_PC
TunerSetRepeator(repeator);
#endif
/*TunerSetRepeator(0);*/
/* dcdc */
STTUNER_IOREG_SetField(DeviceMap,IOHandle,VTH0,0x1E) ;
STTUNER_IOREG_SetField(DeviceMap,IOHandle,VTH1,0x14) ;
STTUNER_IOREG_SetField(DeviceMap,IOHandle,VTH2,0xF) ;
STTUNER_IOREG_SetField(DeviceMap,IOHandle,VTH3,0x9) ;
STTUNER_IOREG_SetField(DeviceMap,IOHandle,VTH4,0x0) ;
STTUNER_IOREG_SetField(DeviceMap,IOHandle,VTH5,0x5) ;
STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_PR,0xAF);
STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_VSEARCH,0x30);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,FORCE,(pParams->Force & 1)) ;
STTUNER_IOREG_SetField(DeviceMap,IOHandle,FRAPTCR,1) ;
if (pParams->Inv == STTUNER_INVERSION_NONE)
STTUNER_IOREG_SetField(DeviceMap,IOHandle,INV_SPECTR,1) ;
else if (pParams->Inv == STTUNER_INVERSION)
STTUNER_IOREG_SetField(DeviceMap,IOHandle,INV_SPECTR,0) ;
else if (pParams->Inv == STTUNER_INVERSION_AUTO)
{
if (pParams->Sense==1) STTUNER_IOREG_SetField(DeviceMap,IOHandle,INV_SPECTR,0) ;
else STTUNER_IOREG_SetField(DeviceMap,IOHandle,INV_SPECTR,1);
}
else if ( (pParams->Inv == STTUNER_INVERSION_UNK) && (!pParams->first_lock))
{
if (pParams->Sense==1) STTUNER_IOREG_SetField(DeviceMap,IOHandle,INV_SPECTR,0) ;
else STTUNER_IOREG_SetField(DeviceMap,IOHandle,INV_SPECTR,1) ;
}
/***********************/
if ((pParams->Frequency == 0) || (pParams->Tuner == STTUNER_TUNER_NONE))
{
error = FE_361_MISSING_PARAMETER;
}
else
{
pParams->State = FE_361_SearchRun(DeviceMap, IOHandle,pParams,TunerInstance);
FE_361_SearchTerm(DeviceMap,IOHandle,pParams,pResult);
}
/** end of first else **/
return error;
}
/*****************************************************
--FUNCTION :: FE_361_LookFor
--ACTION :: Intermediate layer before launching Search
--PARAMS IN :: Handle ==> Front End Handle
pSearch ==> Search parameters
pResult ==> Result of the search
--PARAMS OUT:: NONE
--RETURN :: Error (if any)
--***************************************************/
FE_361_Error_t FE_361_LookFor(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, FE_361_SearchParams_t *pSearch, FE_361_SearchResult_t *pResult,STTUNER_tuner_instance_t *TunerInstance)
{
U8 trials[6];
S8 num_trials,index;
FE_361_Error_t error = FE_361_NO_ERROR;
U8 flag_spec_inv;
U8 flag_freq_off;
U32 frequency;
U8 flag,inv;
S8 delta_freq;
FE_361_InternalParams_t pParams;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -