📄 drv0299.c
字号:
NextLoop--;
if(NextLoop)
{
sfrm[0]=MAC0299_MSB(DerotFreq);
sfrm[1]= MAC0299_LSB(DerotFreq);
STTUNER_IOREG_SetContigousRegisters(DeviceMap, IOHandle, R0299_CFRM, sfrm,2); /* Set the derotator frequency */
}
}
else
{
Result->SymbolRate = Params->SymbolRate;
}
Params->Direction = -Params->Direction; /* Change the zigzag direction */
}
while((Params->State != E299_TIMINGOK) && NextLoop); /* do..while */
if(Params->State == E299_TIMINGOK)
{
STTUNER_IOREG_GetContigousRegisters(DeviceMap, IOHandle, R0299_CFRM,2,sfrm); /* Get the derotator frequency */
/* Multiply DerotFreq with IQ wiring sense of tuner & Demod */
Params->DerotFreq = (short int)Params->TunerIQSense * (short int)MAC0299_MAKEWORD( sfrm[0],sfrm[1] );
}
else
{
Params->DerotFreq = LastDerotFreq;
}
return(Params->State);
}
/*----------------------------------------------------
FUNCTION SearchCarrier
ACTION Search a QPSK carrier with the derotator
PARAMS IN
PARAMS OUT NONE
RETURN E299_NOCARRIER if no carrier had been found, E299_CARRIEROK otherwise
------------------------------------------------------*/
D0299_SignalType_t Drv0299_SearchCarrier(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, D0299_SearchParams_t *Params, D0299_Searchresult_t *Result, STTUNER_Handle_t TopLevelHandle)
{
short int DerotMin,DerotMax;
short int DerotFreq = 0;
short int LastDerotFreq = 0;
short int NextLoop = 2;
int index = 0;
U8 cfrm[2];
STTUNER_InstanceDbase_t *Inst;
STTUNER_tuner_instance_t *TunerInstance;
/* top level public instance data */
Inst = STTUNER_GetDrvInst();
/* get the tuner instance for this driver from the top level handle */
TunerInstance = &Inst[TopLevelHandle].Sat.Tuner;
Params->State = E299_NOCARRIER;
Params->Direction = 1;
DerotMin = (short int) (((-(long)(Params->SubRange))/ 2L + Params->FreqOffset) / Params->Mclk); /* introduce 14 MHz derotator offset */
DerotMax = (short int) ((Params->SubRange/2L + Params->FreqOffset)/Params->Mclk);
DerotFreq = Params->DerotFreq;
STTUNER_IOREG_SetField(DeviceMap, IOHandle, F0299_CFD_ALGO, 1);
do
{
/* Try the terminate check here */
if(Inst[TopLevelHandle].ForceSearchTerminate==TRUE)
break;
if(Drv0299_CheckCarrier(DeviceMap, IOHandle, Params) == E299_NOCARRIER)
{
index++;
LastDerotFreq = DerotFreq;
DerotFreq = DerotFreq + ( (int)Params->TunerIQSense * index * Params->Direction * Params->DerotStep); /* Compute the next derotator position for the zig zag */
if((DerotFreq < DerotMin) || (DerotFreq > DerotMax))
NextLoop--;
if(NextLoop)
{
STTUNER_IOREG_SetField(DeviceMap, IOHandle, F0299_CFD_ALGO, 1);
cfrm[0]=MAC0299_MSB(DerotFreq);
cfrm[1]=MAC0299_LSB(DerotFreq);
STTUNER_IOREG_SetContigousRegisters(DeviceMap, IOHandle, R0299_CFRM, cfrm,2); /* Set the derotator frequency */
}
}
else
{
Result->SymbolRate = Params->SymbolRate;
}
Params->Direction = -Params->Direction; /* Change the zig-zag direction */
}
while((Params->State != E299_CARRIEROK) && NextLoop);
if(Params->State == E299_CARRIEROK)
{
STTUNER_IOREG_GetContigousRegisters(DeviceMap, IOHandle, R0299_CFRM, 2,cfrm); /* Get the derotator frequency */
/* Multiply DerotFreq with IQ wiring sense of tuner & Demod */
Params->DerotFreq = (short int)Params->TunerIQSense * (short int)MAC0299_MAKEWORD( cfrm[0],cfrm[1] );
}
else
{
Params->DerotFreq = LastDerotFreq;
}
return(Params->State);
}
/*----------------------------------------------------
FUNCTION SearchFalseLock
ACTION Search a QPSK carrier with the derotator, if there is a false lock
PARAMS IN
PARAMS OUT NONE
RETURN E299_NOCARRIER if no carrier had been found, E299_CARRIEROK otherwise
------------------------------------------------------*/
D0299_SignalType_t Drv0299_SearchFalseLock(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, D0299_SearchParams_t *Params, D0299_Searchresult_t *Result, STTUNER_Handle_t TopLevelHandle)
{
short int DerotFreq;
short int DerotStep;
short int DerotLimit;
short int DerotOffset;
short int NextLoop = 2;
int index = 1;
U8 cfrm[2];
long CurrentFreq, NewFrequency;
ST_ErrorCode_t Error;
STTUNER_InstanceDbase_t *Inst;
STTUNER_tuner_instance_t *TunerInstance;
/* top level public instance data */
Inst = STTUNER_GetDrvInst();
/* get the tuner instance for this driver from the top level handle */
TunerInstance = &Inst[TopLevelHandle].Sat.Tuner;
Params->State = E299_NOCARRIER;
DerotStep = (short int)( (Params->SymbolRate/4L) / Params->Mclk); /* cast to eliminate compiler warning --SFS */
DerotLimit = (short int)( (Params->SubRange/2L) / Params->Mclk); /* cast to eliminate compiler warning --SFS */
DerotFreq = Params->DerotFreq;
do
{
/* Try the terminate check here */
if(Inst[TopLevelHandle].ForceSearchTerminate==TRUE)
break;
DerotFreq = DerotFreq + ( (int)Params->TunerIQSense * index * Params->Direction * DerotStep); /* Compute the next derotator position for the zig zag */
CurrentFreq = Params->Frequency + ( DerotFreq * Params->Mclk)/1000;
if(MAC0299_ABS(DerotFreq) > DerotLimit) NextLoop--;
if(NextLoop)
{
/* if the False Lock is outside the derotator capture range */ /*(U32)CurrentFreq cast to eliminate compiler warning --SFS */
Error = (TunerInstance->Driver->tuner_SetFrequency)(TunerInstance->DrvHandle, (U32)CurrentFreq, (U32 *)&NewFrequency);
DerotOffset = (short int)(( (NewFrequency - CurrentFreq) * 1000 ) / Params->Mclk); /* Move the tuner */ /* cast to eliminate compiler warning --SFS */
Drv0299_WaitTuner(TunerInstance, 100); /* Is tuner Locked? */
STTUNER_IOREG_SetField(DeviceMap, IOHandle, F0299_CFD_ALGO, 1);
cfrm[0]=MAC0299_MSB(DerotOffset);
cfrm[1]=MAC0299_LSB(DerotOffset);
STTUNER_IOREG_SetContigousRegisters(DeviceMap, IOHandle, R0299_CFRM,cfrm, 2); /* Reset the derotator */
Drv0299_CheckCarrier(DeviceMap, IOHandle, Params);
if(Params->State == E299_CARRIEROK) Drv0299_CheckData(DeviceMap, IOHandle, Params);
index++;
}
Params->Direction = -Params->Direction; /* Change the zigzag direction */
}
while((Params->State != E299_DATAOK) && NextLoop);
if(Params->State == E299_DATAOK)
{
STTUNER_IOREG_GetContigousRegisters(DeviceMap, IOHandle, R0299_CFRM, 2,cfrm); /* Get the derotator frequency */
/* Multiply DerotFreq with IQ wiring sense of tuner & Demod */
Params->DerotFreq = (short int)Params->TunerIQSense * (short int)MAC0299_MAKEWORD( cfrm[0],cfrm[1]);
Params->Frequency = CurrentFreq;
}
return(Params->State);
}
/*----------------------------------------------------
FUNCTION Searchlock
ACTION Search for data
PARAMS IN
PARAMS OUT
RETURN E299_NODATA if data not founded, E299_DATAOK otherwise
------------------------------------------------------*/
D0299_SignalType_t Drv0299_Searchlock(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, D0299_SearchParams_t *Params, D0299_Searchresult_t *Result, STTUNER_Handle_t TopLevelHandle)
{
STTUNER_InstanceDbase_t *Inst;
STTUNER_tuner_instance_t *TunerInstance;
/* top level public instance data */
Inst = STTUNER_GetDrvInst();
/* get the tuner instance for this driver from the top level handle */
TunerInstance = &Inst[TopLevelHandle].Sat.Tuner;
switch(Params->DemodIQMode)
{
case STTUNER_IQ_MODE_NORMAL:
Drv0299_IQSet(DeviceMap, IOHandle,0); /* Set to Normal */
Drv0299_CheckData(DeviceMap, IOHandle, Params);
break;
case STTUNER_IQ_MODE_INVERTED:
Drv0299_IQSet(DeviceMap, IOHandle,1); /* Set to Inverted */
Drv0299_CheckData(DeviceMap, IOHandle, Params);
break;
case STTUNER_IQ_MODE_AUTO:
if (Drv0299_CheckData(DeviceMap, IOHandle, Params) == E299_NODATA) /* Check for data */
{
Drv0299_IQInvertion(DeviceMap, IOHandle); /* Invert I and Q */
if(Drv0299_CheckData(DeviceMap, IOHandle, Params) == E299_NODATA) /* Check for data */
{
Drv0299_IQInvertion(DeviceMap, IOHandle); /* Invert I and Q */
}
}
break;
default:
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DRV0299
STTBX_Print(("%s Drv0299 SearchData inavlid IQ Mode\n"));
#endif
break;
}
return(Params->State);
}
/*----------------------------------------------------
FUNCTION SearchData
ACTION Search for data
PARAMS IN Params->Tdata => Time to wait for data
PARAMS OUT Params->State => Result of the search
RETURN E299_NODATA if data not founded, E299_DATAOK otherwise
------------------------------------------------------*/
D0299_SignalType_t Drv0299_SearchData(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, D0299_SearchParams_t *Params, D0299_Searchresult_t *Result, STTUNER_Handle_t TopLevelHandle)
{
short int DerotFreq;
short int DerotStep;
short int DerotLimit;
short int NextLoop = 2;
int index = 1;
U8 cfrm[2];
long CurrentFreq;
STTUNER_InstanceDbase_t *Inst;
STTUNER_tuner_instance_t *TunerInstance;
/* top level public instance data */
Inst = STTUNER_GetDrvInst();
/* get the tuner instance for this driver from the top level handle */
TunerInstance = &Inst[TopLevelHandle].Sat.Tuner;
DerotStep = (short int)( (Params->SymbolRate/4L) / Params->Mclk); /* cast to eliminate compiler warning --SFS */
DerotLimit = (short int)( (Params->SubRange/2L) / Params->Mclk); /* cast to eliminate compiler warning --SFS */
DerotFreq = Params->DerotFreq;
CurrentFreq = Params->Frequency + ( ((long)(DerotFreq)) * Params->Mclk)/1000;
do
{
/* Try the terminate check here */
if(Inst[TopLevelHandle].ForceSearchTerminate==TRUE)
break;
if((Params->State != E299_CARRIEROK)||(Drv0299_Searchlock(DeviceMap, IOHandle, Params, Result, TopLevelHandle)!=E299_DATAOK))
{
DerotFreq = DerotFreq + ((int)Params->TunerIQSense * index * Params->Direction * DerotStep); /* Compute the next derotator position for the zig zag */
if(MAC0299_ABS(DerotFreq) > DerotLimit) NextLoop--;
if(NextLoop)
{
STTUNER_IOREG_SetField(DeviceMap, IOHandle, F0299_CFD_ALGO, 1);
cfrm[0]=MAC0299_MSB(DerotFreq);
cfrm[1]=MAC0299_LSB(DerotFreq);
STTUNER_IOREG_SetContigousRegisters(DeviceMap, IOHandle, R0299_CFRM, cfrm,2); /* Reset the derotator */
SystemWaitFor(Params->Ttiming);
Drv0299_CheckCarrier(DeviceMap, IOHandle, Params);
index++;
}
}
Params->Direction = -Params->Direction; /* Change the zigzag direction */
}
while((Params->State != E299_DATAOK) && NextLoop);
if(Params->State == E299_DATAOK)
{
STTUNER_IOREG_GetContigousRegisters(DeviceMap, IOHandle, R0299_CFRM, 2,cfrm); /* Get the derotator frequency */
/* Multiply DerotFreq with IQ wiring sense of tuner & Demod */
Params->DerotFreq = (short int)Params->TunerIQSense * (short int)MAC0299_MAKEWORD( cfrm[0],cfrm[1] );
}
return(Params->State);
}
#endif
#ifdef STTUNER_MINIDRIVER
D0299_SignalType_t Drv0299_Searchlock(D0299_SearchParams_t *Params)
{
switch(Params->DemodIQMode)
{
case STTUNER_IQ_MODE_NORMAL:
Drv0299_IQSet(0); /* Set to Normal */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -