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

📄 tuner.c

📁 这是DVB tuner驱动部分和其它相关的源码和一些技术资料文档.
💻 C
📖 第 1 页 / 共 4 页
字号:
                    SatConfig.ToneState =                                         Tuner_p->CurrentTunerInfo.ScanInfo.LNBToneState;                    /* Invoke new configuration */                    Error = SAT_SetConfig(Tuner_p->SatHandle,                                          &SatConfig);                    if (Error != TUNER_NO_ERROR)                        return Error;                    /* Calc the downconverted frequency used by the auto scan                     * routine.                     */                    Tuner_p->ScanInfo.FrequencyLO = Band_p->LO;                    ScanFrequency = Tuner_p->ScanInfo.NextFrequency -                                    Tuner_p->ScanInfo.FrequencyLO;#ifdef STTUNER_DEBUG                    STTBX_Report((STTBX_REPORT_LEVEL_INFO,                                  "DEMOD_ScanFrequency() with F=%u IF=%u.\n",                                  Tuner_p->ScanInfo.NextFrequency,                                  ScanFrequency));#endif                    /* Set required FEC rates - according to device capability */                    Fec = Tuner_p->CurrentTunerInfo.ScanInfo.FECRates &                          Tuner_p->Capability.FECRates;                    DEMOD_SetFECRates(Tuner_p->DemodHandle,                                      Fec);                    /* Currently no support for selecting modulation scheme */                    /* !!! Work to do !!! */                    /* Perform auto search algorithm */                    Error = DEMOD_ScanFrequency(Tuner_p->DemodHandle,                                                ScanFrequency,                                                Tuner_p->CurrentTunerInfo.ScanInfo.SymbolRate,                                                (Tuner_p->SymbolWidthMin * 1000) / 2,                                                TNR_TUNER_STEP,                                                DEMOD_DEROTATOR_STEP,                                                &ScanSuccess,                                                &NewFrequency);                    if (Error != TUNER_NO_ERROR)                        return Error;                    if ( ScanSuccess )                    {                        /* Polarization */                        Tuner_p->CurrentTunerInfo.ScanInfo.Polarization =                            SatConfig.Polarization;                        /* Compute actual frequency -- add on the LNB */                        Tuner_p->ScanInfo.NextFrequency =                            Tuner_p->CurrentTunerInfo.Frequency =                            NewFrequency + Tuner_p->ScanInfo.FrequencyLO;                        /* Extract remaining tuner info from h/w */                        Error = GetTunerInfo(Tuner_p);                        if (Error != TUNER_NO_ERROR)                            return Error;                        /* Update status and lock count ready for tracking */                        *Event_p = STTUNER_EV_LOCKED;                    }                }            }            else            {                /* Invalid band specified */                Error = TUNER_ERROR_BAD_PARAMETER;            }        }    }    return Error;}/*****************************************************************************Name: ProcessTracking()Description:    This routine calls the DEMOD device in order to perform derotator    centring or tracking.  This process ensures we maintain a tuner lock    for the currently tuned frequency.Parameters:    Tuner_p,    pointer to the tuner control block.    Event_p,    pointer to area to store event:    STTUNER_EV_NO_OPERATION,    no event has occurred i.e. lock is ok.    STTUNER_EV_UNLOCKED,        the lost lock count has been exceeded and                                no further attempts at tracking should be                                attempted.Return Value:    TUNER_NO_ERROR,     the operation completed without error.    I2C_xxxx,           there was a problem accessing a device.See Also:    Nothing.*****************************************************************************/static TUNER_ErrorCode_t ProcessTracking(TUNER_ControlBlock_t *Tuner_p,                                         STTUNER_EventType_t *Event_p){    TUNER_ErrorCode_t Error;    STTUNER_EventType_t Event = STTUNER_EV_NO_OPERATION;    BOOL IsLocked, IsSignal;    U32 IF;    /* Tracking */    Error = DEMOD_Tracking(Tuner_p->DemodHandle,                           FALSE,                           &IF,                           &IsSignal);    if (Error == TUNER_NO_ERROR)    {        /* The tracking function returns and intermediate frequency, we must add         * the LNB back on.         */        Tuner_p->CurrentTunerInfo.Frequency =            IF + Tuner_p->ScanInfo.FrequencyLO;        Error = DEMOD_IsLocked(Tuner_p->DemodHandle,                               &IsLocked);        if (Error == TUNER_NO_ERROR)        {            if (IsLocked && IsSignal)                Tuner_p->ScanInfo.LockCount = NUMBER_LOST_BEFORE_UNLOCK;            else                Tuner_p->ScanInfo.LockCount--;            if (Tuner_p->ScanInfo.LockCount == 0)            {                Event = STTUNER_EV_UNLOCKED;            }            else            {                Error = GetTunerInfo(Tuner_p);            }        }    }    if (Error != TUNER_NO_ERROR)        Event = STTUNER_EV_UNLOCKED;    *Event_p = Event;    return Error;} /* ProcessTracking() *//*****************************************************************************Name: ProcessThresholds()Description:Parameters:    Tuner_p,    pointer to the tuner control block.    Event_p,    pointer to area to store event:    STTUNER_EV_NO_OPERATION,    no event has occurred i.e. lock is ok.    STTUNER_EV_SIGNAL_CHANGE,   the signal quality has changed threshold.Return Value:    TUNER_NO_ERROR,     the operation completed without error.    I2C_xxxx,           there was a problem accessing a device.See Also:    Nothing.*****************************************************************************/static TUNER_ErrorCode_t ProcessThresholds(TUNER_ControlBlock_t *Tuner_p,                                           STTUNER_EventType_t *Event_p){    TUNER_ErrorCode_t Error = ST_NO_ERROR;    U32 CurrentSignal, LastSignal;    STTUNER_SignalThreshold_t *Threshold_p;    U32 *ThresholdHits;    U32 i, HitCount;    /* Assume signal threshold is ok i.e. no event */    *Event_p = STTUNER_EV_NO_OPERATION;    ThresholdHits = Tuner_p->ThresholdHits;    /* Calculate current signal and last signal values */    CurrentSignal = ( Tuner_p->QualityFormat == STTUNER_QUALITY_BER ) ?                    Tuner_p->CurrentTunerInfo.BitErrorRate :                    Tuner_p->CurrentTunerInfo.SignalQuality;    LastSignal = Tuner_p->LastSignal;    if (CurrentSignal == LastSignal ||        Tuner_p->ThresholdList.NumElements == 0)        return Error; /* No need to proceed -- no change in signal */    /* Re-set last signal indicator */    Tuner_p->LastSignal = CurrentSignal;    /* Set threshold pointer to start of threshold list */    Threshold_p = Tuner_p->ThresholdList.ThresholdList;    i = 0;                          /* List element counter */    HitCount = 0;                   /* Number of hits */    /* Calculate all theshold hits */    while ( i < Tuner_p->ThresholdList.NumElements )    {        if (CurrentSignal >= Threshold_p->SignalLow &&            CurrentSignal <= Threshold_p->SignalHigh)            ThresholdHits[HitCount++] = i; /* Hit found */        i++;        Threshold_p++;    }    /* The current signal may either:     * a) Not exist in any threshold (HitCount == 0)     * b) Exist in a one or more thresholds (HitCount >= 1)     */    if (HitCount > 0)    {        /* Unless all thresholds are different to the last threshold,         * there will not be a signal change event.         * In the case where all thresholds are different from the         * last threshold, we arbitrarily choose index = 0 as the         * new threshold and signal an event.         */        for (i = 0;             i < HitCount && ThresholdHits[i] != Tuner_p->LastThreshold;             i++) /* Do nothing */ ;        /* Check for all thresholds not equal to last threshold */        if (i == HitCount)        {            /* Threshold has changed, we should ensure an event is             * generated.             */            *Event_p = STTUNER_EV_SIGNAL_CHANGE;            Tuner_p->LastThreshold = ThresholdHits[0];        }    }    else    {        /* The hit count is zero -- no thresholds hold the current         * signal value.  An event must be generated unless this was         * the case last time we checked.         */        if (Tuner_p->LastThreshold != ((U32)-1))        {            *Event_p = STTUNER_EV_SIGNAL_CHANGE;            Tuner_p->LastThreshold = ((U32)-1);        }    }    return Error;} /* ProcessTracking() *//*****************************************************************************GetTunerInfo()Description:    Calls the DEMOD device in order to get the current demodulation settings    for updating the current tuner info.  This information will eventually    be forwarded back up to the STTUNER API tuner info.Parameters:    Tuner_p,    pointer to the TUNER control block.Return Value:    TUNER_NO_ERROR,     the operation completed without error.    I2C_xxxx,           there was a problem accessing a device.See Also:    Nothing.*****************************************************************************/static TUNER_ErrorCode_t GetTunerInfo(TUNER_ControlBlock_t *Tuner_p){    TUNER_ErrorCode_t Error;    /* Get the current demodulation parameters */    if ((Error = DEMOD_GetAGC(Tuner_p->DemodHandle,                 &Tuner_p->CurrentTunerInfo.ScanInfo.AGC)) != TUNER_NO_ERROR ||        (Error = DEMOD_GetSignalQuality(Tuner_p->DemodHandle,                 &Tuner_p->CurrentTunerInfo.SignalQuality,                 &Tuner_p->CurrentTunerInfo.BitErrorRate)) != TUNER_NO_ERROR ||        (Error = DEMOD_GetModulation(Tuner_p->DemodHandle,                 &Tuner_p->CurrentTunerInfo.ScanInfo.Modulation)) != TUNER_NO_ERROR ||        (Error = DEMOD_GetFECRate(Tuner_p->DemodHandle,                 &Tuner_p->CurrentTunerInfo.ScanInfo.FECRates)) != TUNER_NO_ERROR)    {        return Error;    }    /* The following code will be included if you wish to introduce 'random noise'     * into the generated signal quality values.  This is useful for testing     * for signal threshold events.     */#if STTUNER_SIGNAL_NOISE    {        static BOOL SRand = TRUE;        U32 r;        if (SRand)        {            srand((unsigned int)time_now());            SRand = FALSE;        }        /* Calculate percentage fluctuation from current position */        r = rand() % 100;               /* Percent change */        Tuner_p->CurrentTunerInfo.SignalQuality -= (            (((Tuner_p->CurrentTunerInfo.SignalQuality << 7) * r) / 100) >> 7        );        /* Estimate ber from signal quality based on a linear relationship */        Tuner_p->CurrentTunerInfo.BitErrorRate = ( MAX_BER - (            (Tuner_p->CurrentTunerInfo.SignalQuality * MAX_BER) / 100 ));    }#endif    return TUNER_NO_ERROR;} /* GetTunerInfo() *//*****************************************************************************LNBPowerDown()Description:    This routine calls the SAT device in order to remove power to the LNB.Parameters:    Tuner_p,        pointer to the TUNER control block.Return Value:    None.See Also:    Nothing.*****************************************************************************/static void LNBPowerDown(TUNER_ControlBlock_t *Tuner_p){    SAT_Config_t SatConfig;    /* Attempt to turn the LNB power off, as the scan has finished */    if (SAT_GetConfig(Tuner_p->SatHandle, &SatConfig) == SAT_NO_ERROR)    {        SatConfig.LNBStatus = SAT_LNB_OFF;        SAT_SetConfig(Tuner_p->SatHandle, &SatConfig);    }} /* LNBPowerDown() *//* End of tuner.c */

⌨️ 快捷键说明

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