⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driv0299.c

📁 这是DVB tuner驱动部分和其它相关的源码和一些技术资料文档.
💻 C
📖 第 1 页 / 共 3 页
字号:
    int     i;    /* =======================================================================    -- Data capture time (in ms)    -- -------------------------    -- This time is due to the Viterbi synchronisation.    --    --    For each authorized inner code, the Viterbi search time is calculated,    --    and the results are cumulated in ViterbiSearch.    */    for(i=0;i<5;i++)    {        if (((Er >> i)& 0x01) == 0x01)        {            switch(i)            {                case 0:                    /*    inner code 1/2    */                    InnerCode = 2000;    /* 2.0 */                    break;                case 1:                    /*    inner code 2/3    */                    InnerCode = 1500;     /* 1.5 */                    break;                case 2:                    /*    inner code 3/4  */                    InnerCode = 1333;    /* 1.333 */                    break;                case 3:                    /*    inner code 5/6    */                    InnerCode = 1200;    /* 1.2 */                    break;                case 4:                    /*    inner code 7/8    */                    InnerCode = 1143;    /* 1.143 */                    break;            }            Tviterbi +=(int)((PhaseNumber[i]*averaging[Sn]*InnerCode)/SymbolRate);            if(HigherRate < InnerCode)                HigherRate = InnerCode;        }    }    /*      time out calculation (TimeOut)    --    ------------------------------    --    This value indicates the maximum duration of the synchro word research.    */    TimeOut   = (int)((HigherRate * 16384L * ((long)To + 1))/(2*SymbolRate));  /* cast To to long (eliminate compiler warning --SFS */    /*    Hysteresis duration (Hysteresis)    --    ------------------------------    */    THysteresis = (int)((HigherRate * 26112L * ((long)Hy +1))/(2*SymbolRate));    /*    26112= 16*204*8 bits *//* cast Hy to long (eliminate compiler warning --SFS */    /* a guard time of 1 mS is added */    return (1 + Tviterbi + TimeOut + THysteresis);}/*****************************************************--FUNCTION  ::    InitParams--ACTION    ::    Set Params fields that are never changed during search algorithm--PARAMS IN ::    NONE--PARAMS OUT::    NONE--RETURN    ::    NONE--***************************************************/void InitParams(STV0299_ControlBlock_t *Dev_p){    int        stdby,dirclk,k,m,p,    m1,betaagc1,    agc2coef,MasterClock;    /*    Read registers (in burst mode)    */    RegGetRegisters(Dev_p, R_RCR,2);        /*    Read RCR and MCR registers    */    RegGetOneRegister(Dev_p, R_AGC1C);    RegGetRegisters(Dev_p, R_AGC1R,2);        /*    Read AGC1R and AGC2O registers */    /*    Get fields values    */    stdby=FieldGetVal(Dev_p, STDBY);    dirclk=FieldGetVal(Dev_p, DIRCLK);    k=FieldGetVal(Dev_p, K);    m=FieldGetVal(Dev_p, M);    p=FieldGetVal(Dev_p, P);    m1=FieldGetVal(Dev_p, AGC1_REF);    betaagc1=FieldGetVal(Dev_p, BETA_AGC1);    agc2coef=FieldGetVal(Dev_p, AGC2COEF);    /*    Initial calculations    */    MasterClock = (int)CalcMasterClkFrequency(Dev_p, stdby,dirclk,k,m,p);  /* cast to match parameter type --SFS */    Dev_p->Params.Tagc1 = (int)(CalcAGC1TimeConstant(m1,MasterClock,betaagc1)/20L);  /* cast to match parameter type --SFS */    Dev_p->Params.Tagc2 = (int)(CalcAGC2TimeConstant(agc2coef,m1,MasterClock)/1000000L);  /* cast to match parameter type --SFS */    Dev_p->Params.MasterClock = MasterClock;    Dev_p->Params.Mclk = MasterClock/65536L;    Dev_p->Params.RollOff = RegGetRollOff(Dev_p);    /* Added defensive check against Mclk == 0 to avoid potential       divide by zero exceptions throughout the code.  In practice       Mclk should never equal zero - if it does, something       seriously bad has happened!  In the event that Mclk is       zero at this point we reset it to 1 to ensure       driver computations involving Mclk do not produce       exceptions.     */    if (Dev_p->Params.Mclk == 0)        Dev_p->Params.Mclk = 1; /* Serious error - reset to avoid exceptions */}/*****************************************************--FUNCTION  ::    InitParams--ACTION    ::    Set Params fields that are used by the search algorithm--PARAMS IN ::    Frequency    =>    Frequency used to start zig zag--                SymbolRate    =>    searched symbol rate--                SearchRange =>    Range of the search--                DerotStep    =>    Size of derotator's steps used in the carrier search (in per thousand of symbol frequency)--PARAMS OUT::    NONE--RETURN    ::    NONE--***************************************************/void InitSearch(STV0299_ControlBlock_t *Dev_p, int Frequency, int SymbolRate,                int SearchRange, int DerotStep){    TNR_Status_t TunerStatus;    U32 BandWidth;    /* Obtain current tuner status */    TNR_GetStatus(TNR_HANDLE(Dev_p), &TunerStatus);    /* Select closest bandwidth for tuner */    TNR_SetBandWidth(TNR_HANDLE(Dev_p),                     (U32)(CarrierWidth(SymbolRate, Dev_p->Params.RollOff)/1000 + 3000),                     &BandWidth);    /* cast to U32 type to match function argument & eliminate compiler warning --SFS */    Dev_p->Params.Frequency = Frequency;    Dev_p->Params.SymbolRate = SymbolRate;    Dev_p->Params.SearchRange = SearchRange;    Dev_p->Params.DerotPercent = DerotStep;    Dev_p->Params.TunerBW = (long) BandWidth*1000;  /* cast from U32 to long to eliminate compiler warning --SFS */    Dev_p->Params.TunerStep = (long)TunerStatus.TunerStep;    Dev_p->Params.TunerIF = (long)TunerStatus.IntermediateFrequency;    Dev_p->Result.SignalType = NOAGC1;    Dev_p->Result.Frequency = 0;    Dev_p->Result.SymbolRate = 0;}/*****************************************************--FUNCTION  ::    SearchTiming--ACTION    ::    Perform an Fs/2 zig zag to found timing--PARAMS IN ::    NONE--PARAMS OUT::    NONE--RETURN    ::    NOTIMING if no valid timing had been found, TIMINGOK otherwise--***************************************************/SIGNALTYPE SearchTiming(STV0299_ControlBlock_t *Dev_p, SEARCHPARAMS *pParams, SEARCHRESULT *pResult){    short int    DerotStep,    DerotFreq = 0,    LastDerotFreq = 0,    DerotLimit,    NextLoop = 2;    int     index = 0;    pParams->State = NOTIMING;    pParams->Direction = 1;    /* timing loop computation & symbol rate optimisation    */    DerotLimit = (short int)((pParams->SubRange/2L)/pParams->Mclk);  /* cast to eliminate compiler warning --SFS */    DerotStep = (short int)((pParams->SymbolRate/2L)/pParams->Mclk); /* cast to eliminate compiler warning --SFS */    do    {        if(CheckTiming(Dev_p, pParams)==NOTIMING)        {            index++;            LastDerotFreq = DerotFreq;            DerotFreq += index*pParams->Direction*DerotStep;    /*    Compute the next derotator position for the zig zag    */            if(ABS(DerotFreq) > DerotLimit)                NextLoop--;            if(NextLoop)            {                FieldSetVal(Dev_p, DEROTATORFREQUENCYMSB,MSB(DerotFreq));                FieldSetVal(Dev_p, DEROTATORFREQUENCYLSB,LSB(DerotFreq));                RegSetRegisters(Dev_p, R_CFRM,2);                             /*    Set the derotator frequency    */            }        }        else        {            pResult->SymbolRate = pParams->SymbolRate;        }        pParams->Direction = -pParams->Direction;            /*    Change the zigzag direction    */    }    while((pParams->State!=TIMINGOK) && NextLoop);    if(pParams->State == TIMINGOK)    {        RegGetRegisters(Dev_p, R_CFRM,2);                                 /*    Get the derotator frequency    */        pParams->DerotFreq = (short int) MAKEWORD(            FieldGetVal(Dev_p, DEROTATORFREQUENCYMSB),            FieldGetVal(Dev_p, DEROTATORFREQUENCYLSB)            );    }    else    {        pParams->DerotFreq = LastDerotFreq;    }    return pParams->State;}/*****************************************************--FUNCTION  ::    SearchCarrier--ACTION    ::    Search a QPSK carrier with the derotator--PARAMS IN ::--PARAMS OUT::    NONE--RETURN    ::    NOCARRIER if no carrier had been found, CARRIEROK otherwise--***************************************************/SIGNALTYPE SearchCarrier(STV0299_ControlBlock_t *Dev_p, SEARCHPARAMS *pParams, SEARCHRESULT *pResult){    short int    DerotFreq = 0,    LastDerotFreq = 0,    DerotLimit,    NextLoop = 2;    int     index = 0;    pParams->State = NOCARRIER;    pParams->Direction = 1;    DerotLimit = (short int)((pParams->SubRange/2L)/pParams->Mclk); /* cast to eliminate compiler warning --SFS */    DerotFreq = pParams->DerotFreq;    RegSetField(Dev_p, CFD_ALGO, 1);    do    {        if(CheckCarrier(Dev_p, pParams)==NOCARRIER)        {            index++;            LastDerotFreq = DerotFreq;            DerotFreq += index*pParams->Direction*pParams->DerotStep;    /*    Compute the next derotator position for the zig zag    */            if(ABS(DerotFreq) > DerotLimit)                NextLoop--;            if(NextLoop)            {                RegSetField(Dev_p, CFD_ALGO, 1);                FieldSetVal(Dev_p, DEROTATORFREQUENCYMSB,MSB(DerotFreq));                FieldSetVal(Dev_p, DEROTATORFREQUENCYLSB,LSB(DerotFreq));                RegSetRegisters(Dev_p, R_CFRM,2);                             /*    Set the derotator frequency    */            }        }        else        {            pResult->SymbolRate = pParams->SymbolRate;        }        pParams->Direction = -pParams->Direction;            /*    Change the zigzag direction    */    }    while(    (pParams->State!=CARRIEROK) && NextLoop);    if(pParams->State == CARRIEROK)    {        RegGetRegisters(Dev_p, R_CFRM,2);                                 /*    Get the derotator frequency    */        pParams->DerotFreq = (short int) MAKEWORD(            FieldGetVal(Dev_p, DEROTATORFREQUENCYMSB),            FieldGetVal(Dev_p, DEROTATORFREQUENCYLSB)            );    }    else    {        pParams->DerotFreq = LastDerotFreq;    }    return pParams->State;}/*****************************************************--FUNCTION    ::    SearchFalseLock--ACTION    ::    Search a QPSK carrier with the derotator, if there is a false lock--PARAMS IN    ::--PARAMS OUT::    NONE--RETURN    ::    NOCARRIER if no carrier had been found, CARRIEROK otherwise--***************************************************/SIGNALTYPE SearchFalseLock(STV0299_ControlBlock_t *Dev_p, SEARCHPARAMS *pParams, SEARCHRESULT *pResult){    short int    DerotFreq,    DerotStep,    DerotLimit,    DerotOffset,    NextLoop = 2;    int     index = 1;    long    CurrentFreq, NewFrequency;    pParams->State = NOCARRIER;    DerotStep = (short int)((pParams->SymbolRate/4L)/pParams->Mclk); /* cast to eliminate compiler warning --SFS */    DerotLimit = (short int)((pParams->SubRange/2L)/pParams->Mclk);  /* cast to eliminate compiler warning --SFS */    DerotFreq = pParams->DerotFreq;    do    {        DerotFreq += index*pParams->Direction*DerotStep;        /*    Compute the next derotator position for the zig zag    */        CurrentFreq = pParams->Frequency + (DerotFreq*pParams->Mclk)/1000;        if(ABS(DerotFreq) > DerotLimit)            NextLoop--;        if(NextLoop)        {            /* if the False Lock is outside the derotator capture range    */            TNR_SetFrequency(TNR_HANDLE(Dev_p), (U32)CurrentFreq, (U32 *)&NewFrequency); /*(U32)CurrentFreq cast to eliminate compiler warning --SFS */            DerotOffset = (short int)(((NewFrequency - CurrentFreq) * pParams->Mclk )/1000);        /*    Move the tuner    */ /* cast to eliminate compiler warning --SFS */            WaitTuner(Dev_p, 100);                                    /*    Is tuner Locked    ?    */            RegSetField(Dev_p, CFD_ALGO, 1);            FieldSetVal(Dev_p, DEROTATORFREQUENCYMSB,MSB(DerotOffset));            FieldSetVal(Dev_p, DEROTATORFREQUENCYLSB,LSB(DerotOffset));            RegSetRegisters(Dev_p, R_CFRM,2);                         /*    Reset the derotator frequency    */            CheckCarrier(Dev_p, pParams);            if(pParams->State == CARRIEROK)                CheckData(Dev_p, pParams);            index++;        }        pParams->Direction = -pParams->Direction;            /*    Change the zigzag direction    */    }    while((pParams->State != DATAOK) && NextLoop);    if(pParams->State == DATAOK)    {        RegGetRegisters(Dev_p, R_CFRM,2);                                 /*    Get the derotator frequency    */        pParams->DerotFreq = (short int) MAKEWORD(            FieldGetVal(Dev_p, DEROTATORFREQUENCYMSB),            FieldGetVal(Dev_p, DEROTATORFREQUENCYLSB)            );        pParams->Frequency = CurrentFreq;    }    return pParams->State;}/****************************************************--FUNCTION  ::    SearchData--ACTION    ::    Search for data--PARAMS IN ::    pParams->Tdata    =>    Time to wait for data--PARAMS OUT::    pParams->State    =>    Result of the search--RETURN    ::    NODATA if data not founded, DATAOK otherwise--**************************************************/SIGNALTYPE SearchData(STV0299_ControlBlock_t *Dev_p, SEARCHPARAMS *pParams, SEARCHRESULT *pResult){    if(CheckData(Dev_p, pParams)==NODATA)        /*    Check for data    */    {        IQInvertion(Dev_p);                    /*    Invert I and Q    */        if(CheckData(Dev_p, pParams) == NODATA)/*    Check for data    */        {            IQInvertion(Dev_p);                /*    Invert I and Q    */            SearchFalseLock(Dev_p, pParams, pResult);    /*    we have found a false lock    */        }    }    return pParams->State;}/****************************************************--FUNCTION    ::    CheckRange--ACTION    ::    Check if the founded frequency is in the correct range--PARAMS IN    ::    pParams->BaseFreq =>--PARAMS OUT::    pParams->State    =>    Result of the check--RETURN    ::    RANGEOK if check success, OUTOFRANGE otherwise--***************************************************/SIGNALTYPE CheckRange(STV0299_ControlBlock_t *Dev_p, SEARCHPARAMS *pParams, SEARCHRESULT *pResult){	int	RangeOffset,		TransponderFrequency;    RangeOffset = (int)(pParams->SearchRange / 2000);  /* cast to eliminate compiler warning --SFS */    TransponderFrequency = (int)(pParams->Frequency +

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -