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

📄 tuner.c

📁 这是DVB tuner驱动部分和其它相关的源码和一些技术资料文档.
💻 C
📖 第 1 页 / 共 4 页
字号:
        }        /* Process the next step based on the current scan status */        switch (Tuner_p->TunerInfo.Status)        {            /* "scanning" - we must process a new scan step */            case STTUNER_STATUS_SCANNING:                if (Tuner_p->ScanExact)                {                    Error = ProcessScanExact(Tuner_p, &Event);                    /* Since we are scanning for a single frequency,                     * unless we get the locked event we should treat                     * this as scan failed.                     */                    if (Event != STTUNER_EV_LOCKED)                        Event = STTUNER_EV_SCAN_FAILED;                }                else                {                    Error = ProcessNextScan(Tuner_p, &Event);                }                break;            /* In the "locked" case we have a frequency that we must attempt             * to maintain, or track.             */            case STTUNER_STATUS_LOCKED:                Error = ProcessTracking(Tuner_p, &Event);                /* Only process thresholds if the lock wasn't lost */                if (Event == STTUNER_EV_NO_OPERATION)                    Error = ProcessThresholds(Tuner_p, &Event);                break;            /* "not found" or "unlocked" cases require no further action.             * The scan task will have to wait for user intervention.             */            case STTUNER_STATUS_UNLOCKED:                /* Check the last status to ensure that the state hasn't                 * been changed externally e.g., scan aborted.                 */                if (Tuner_p->CurrentTunerInfo.Status == STTUNER_STATUS_SCANNING)                {                    Event = STTUNER_EV_SCAN_FAILED;                    break;                }                else if (Tuner_p->CurrentTunerInfo.Status == STTUNER_STATUS_LOCKED)                {                    Event = STTUNER_EV_UNLOCKED; /* Aborted scan */                    break;                }                /* Fall through */            case STTUNER_STATUS_NOT_FOUND:                /* Fall through */            default:                Event = STTUNER_EV_NO_OPERATION;                break;        }        /* If an error has occurred, then we must end the scan now -- we can't         * recover from this condition.         */        if (Error != TUNER_NO_ERROR)        {#ifdef STTUNER_DEBUG            Tuner_p->BusErrorCount++;            STTBX_Report((STTBX_REPORT_LEVEL_ERROR,                          "Bus error count = %u.\n",                          Tuner_p->BusErrorCount));#endif            /* In the event of a bus error -- we should tidy up the current             * task appropriately.             */            if (Tuner_p->TunerInfo.Status == STTUNER_STATUS_SCANNING)                Event = STTUNER_EV_SCAN_FAILED;            else if (Tuner_p->TunerInfo.Status == STTUNER_STATUS_LOCKED)                Event = STTUNER_EV_UNLOCKED;        }        /* Check the outcome of the last operation */        switch (Event)        {            case STTUNER_EV_LOCKED:     /* We are now locked */                Tuner_p->CurrentTunerInfo.Status = STTUNER_STATUS_LOCKED;                Tuner_p->ScanInfo.LockCount = NUMBER_LOST_BEFORE_UNLOCK;                /* Reset signal indicators */                Tuner_p->LastThreshold = ((U32)-1); /* Undefined threshold */                Tuner_p->LastSignal = ((U32)-1); /* Undefined signal */                break;            case STTUNER_EV_UNLOCKED:   /* We have lost lock */                Tuner_p->CurrentTunerInfo.Status = STTUNER_STATUS_UNLOCKED;                break;            case STTUNER_EV_SCAN_FAILED: /* The last scan failed */                /* The end of the scan list has been reached -- we drop                 * to the "not found" status.  A callback may be invoked                 * soon.                 */                Tuner_p->CurrentTunerInfo.Status = STTUNER_STATUS_NOT_FOUND;                LNBPowerDown(Tuner_p);  /* Power down the LNB */                break;            case STTUNER_EV_TIMEOUT:                /* If a timeout occurs, we do not allow the scan to continue.                 * this is effectively the same as reaching the end of the                 * scan list -- we reset our status to "not found".                 */                Tuner_p->CurrentTunerInfo.Status = STTUNER_STATUS_NOT_FOUND;                break;            case STTUNER_EV_SIGNAL_CHANGE:                /* No action required.  The event will be processed in the                 * call back below...                 */                break;            default:                /* We must now proceed to the next scan step, if there is                 * one -- if there isn't a next scan step then a callback                 * might be invoked.                 */                if (Tuner_p->TunerInfo.Status == STTUNER_STATUS_SCANNING &&                    Tuner_p->ScanInfo.ScanIndex < Tuner_p->ScanList.NumElements)                {                    /* Proceed to the next element.  In order to avoid a                     * spurious callback being invoked -- we reset the event                     * to a "no op".                     */                    Tuner_p->ScanInfo.Scan_p++;                    Tuner_p->ScanInfo.ScanIndex++;                    /* Avoid task delay */                    semaphore_signal(&Tuner_p->ScanTask.TimeoutSemaphore);                }                Tuner_p->CurrentTunerInfo.Status = Tuner_p->TunerInfo.Status;                break;        }        /* Commit new tuner information -- the API level can now see it */        Tuner_p->TunerInfo = Tuner_p->CurrentTunerInfo;        /* Critical section end */        semaphore_signal(&Tuner_p->ScanTask.GuardSemaphore);        /* We may have to generate an event if a notify function is setup */        if (Tuner_p->OpenParams.NotifyFunction != NULL &&            Event != STTUNER_EV_NO_OPERATION)        {            Tuner_p->OpenParams.NotifyFunction(Tuner_p->Handle, Event, Error);        }        else if (Event != STTUNER_EV_NO_OPERATION)        {            STTUNER_EvtParams_t EventInfo;            /* Use the event handler to notify */            EventInfo.Handle = Tuner_p->Handle;            EventInfo.Error = Error;            Error = STEVT_Notify(Tuner_p->EVTHandle,                                 Tuner_p->EvtId[EventToId(Event)],                                 &EventInfo);#ifdef STTUNER_DEBUG            if (Error != ST_NO_ERROR)            {                STTBX_Report((STTBX_REPORT_LEVEL_ERROR,                              "STEVT error = %u.\n",                              Error));            }#endif        }    }    return;} /* ScanTask() *//*****************************************************************************Name: ProcessNextScan()Description:    This routine encapsulates the tuning strategy.Parameters:    Tuner_p,    pointer to the TUNER device.    Event_p,    pointer to location to store returned event.  May be:                STTUNER_EV_NO_OPERATION,    we failed to achieve tuner lock.                STTUNER_EV_LOCKED,          the tuner is locked on a frequency.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 ProcessNextScan(TUNER_ControlBlock_t *Tuner_p,                                         STTUNER_EventType_t *Event_p){    TUNER_ErrorCode_t Error = TUNER_NO_ERROR;    /* Check to see if we are at the end of the scan list */    if (Tuner_p->ScanInfo.ScanIndex >= Tuner_p->ScanList.NumElements)    {        U32 FrequencyEnd, FrequencyStart;        /* Calculate correct start and end frequencies */        if (Tuner_p->ScanInfo.ScanDirection < 0)        {            FrequencyEnd = Tuner_p->ScanInfo.FrequencyStart;            FrequencyStart = Tuner_p->ScanInfo.FrequencyEnd;        }        else        {            FrequencyEnd = Tuner_p->ScanInfo.FrequencyEnd;            FrequencyStart = Tuner_p->ScanInfo.FrequencyStart;        }        /* Apply next frequency step */        Tuner_p->ScanInfo.NextFrequency +=            (Tuner_p->ScanInfo.ScanDirection *               (S32)Tuner_p->ScanInfo.FrequencyStep);        /* Set frequency step to default - in case we just had a large step */        Tuner_p->ScanInfo.FrequencyStep = (Tuner_p->SymbolWidthMin / 2);        /* If we've reached the limit of our frequency range, then we should try         * and use the next polarization setting -- if there is one.         */        if (Tuner_p->ScanInfo.NextFrequency > FrequencyEnd ||            Tuner_p->ScanInfo.NextFrequency < FrequencyStart)        {            /* Shift the polarization mask along to the next valid             * polarization.             */            do            {                Tuner_p->ScanInfo.PlrMask <<= 1;            }            while (Tuner_p->ScanInfo.PlrMask != 0 &&               (Tuner_p->ScanInfo.PlrMask & Tuner_p->PolarizationMask) == 0);            /* Check there are still polarizations to check */            if (Tuner_p->ScanInfo.PlrMask != 0)            {                Tuner_p->ScanInfo.NextFrequency =                    Tuner_p->ScanInfo.FrequencyStart;            }            else            {                /* No more combinations to try -- scan has failed */                *Event_p = STTUNER_EV_SCAN_FAILED;                return Error;            }        }        /* Set scan list to beginning */        Tuner_p->ScanInfo.Scan_p = Tuner_p->ScanList.ScanList;        Tuner_p->ScanInfo.ScanIndex = 0;    }    /* Process the next frequency scan step */    Error = ProcessScanExact(Tuner_p, Event_p);    return Error;} /* ProcessNextScan() *//*****************************************************************************Name: ProcessScanExact()Description:    This routine scans for a single frequency based on the current    tuner scan parameters.Parameters:    Tuner_p,    pointer to the TUNER device.    Event_p,    pointer to location to store returned event.  May be:        STTUNER_EV_NO_OPERATION,    we failed to achieve tuner lock.        STTUNER_EV_LOCKED,          the tuner is locked on a frequency.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 ProcessScanExact(TUNER_ControlBlock_t *Tuner_p,                                          STTUNER_EventType_t *Event_p){    TUNER_ErrorCode_t Error = TUNER_NO_ERROR;    /* Assume no lock is found */    *Event_p = STTUNER_EV_NO_OPERATION;    /* Setup the current element -- this represents a working copy we can     * modify of the current element in the scan list -- on completion it     * will be made visible to the ST TUNER API.     */    Tuner_p->CurrentTunerInfo.ScanInfo = *Tuner_p->ScanInfo.Scan_p;#if 0    /* Check that the symbol rate is supported */    if (Tuner_p->CurrentTunerInfo.ScanInfo.SymbolRate >=        Tuner_p->Capability.SymbolMin &&        Tuner_p->CurrentTunerInfo.ScanInfo.SymbolRate <=        Tuner_p->Capability.SymbolMax)#endif    {        /* Mask with the capabilties of the device */        Tuner_p->CurrentTunerInfo.ScanInfo.Modulation &=            Tuner_p->Capability.Modulation;        /* Mask with current polarization mask */        Tuner_p->CurrentTunerInfo.ScanInfo.Polarization &=            Tuner_p->ScanInfo.PlrMask;        /* Check the LNB polarization is the current */        if (Tuner_p->CurrentTunerInfo.ScanInfo.Polarization != 0)        {            /* Proceed only if it is a valid band */            if (Tuner_p->CurrentTunerInfo.ScanInfo.Band <                Tuner_p->BandList.NumElements)            {                SAT_Config_t SatConfig;                U32 ScanFrequency;                U32 NewFrequency;                BOOL ScanSuccess = FALSE;                STTUNER_Band_t *Band_p;                DEMOD_FECRate_t Fec;                /* Set requested band */                Band_p = &Tuner_p->BandList.BandList[                         Tuner_p->CurrentTunerInfo.ScanInfo.Band                         ];                /* Ensure current frequency falls inside selected band */                if (Tuner_p->ScanInfo.NextFrequency >= Band_p->BandStart &&                    Tuner_p->ScanInfo.NextFrequency <= Band_p->BandEnd)                {                    /* Set the Satellite Dish LNB power to ON */                    SatConfig.LNBStatus = SAT_LNB_ON;                    /* Setup the Satellite Dish LNB Polarization */                    SatConfig.Polarization =                                            Tuner_p->CurrentTunerInfo.ScanInfo.Polarization;                    /* Setup the require tone state */

⌨️ 快捷键说明

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