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

📄 tuner.c

📁 这是DVB tuner驱动部分和其它相关的源码和一些技术资料文档.
💻 C
📖 第 1 页 / 共 4 页
字号:
/*****************************************************************************File Name   : tuner.cDescription : Wrapper API for interfacing with the low-level tuner modules.Copyright (C) 1999 STMicroelectronicsRevision History :    21/01/00    Search algorithm updated to allow direct setting of LNB                tone state in scan params.    24/01/00    FEC rates are now setting during ScanExact() i.e., per                scan list element rather than a global OR of all                FEC rates for all scan list elements.Reference        :ST API Definition "TUNER Driver API" DVD-API-06*****************************************************************************//* Includes --------------------------------------------------------------- */#include <string.h>                     /* C libs */#include <stdio.h>#include <stdlib.h>#include "stlite.h"                     /* Standard includes */#include "sttuner.h"                    /* STAPI includes */#include "sti2c.h"#include "stcommon.h"#include "sttbx.h"#include "demod.h"                      /* DEMOD Device API */#include "tnr.h"                        /* TNR Device API */#include "sat.h"                        /* SAT Device API */#include "tuner.h"                      /* Core Tuner API *//* Private types/constants ------------------------------------------------ *//* Digital bandwidth roll-off */#define DIG_ROLL_OFF_SCALING            100#define SCALED_DIG_ROLL_OFF             135 /* Actual 1.35 *//* Analog carrier bandwidth -- big step speeds up scan process */#define ANALOG_CARRIER_BANDWIDTH_KHZ    29000#define NUMBER_LOST_BEFORE_UNLOCK       3/* Delay required for the scan task */#ifndef STTUNER_SCAN_TASK_DELAY_MS#define STTUNER_SCAN_TASK_DELAY_MS      500  /* Millisecond delay */#endif /* STTUNER_SCAN_TASK_DELAY_MS *//* Device capabilities */#define MAX_AGC                         255#define MAX_SIGNAL_QUALITY              100#define MAX_BER                         200000/* Private variables ------------------------------------------------------ *//* Private macros --------------------------------------------------------- *//* Private function prototypes -------------------------------------------- */static void GetCapability(TUNER_ControlBlock_t *Tuner_p);static void ScanTask(TUNER_ControlBlock_t *Tuner_p);static TUNER_ErrorCode_t ProcessScanExact(TUNER_ControlBlock_t *Tuner_p,                                          STTUNER_EventType_t *Event_p);static TUNER_ErrorCode_t ProcessNextScan(TUNER_ControlBlock_t *Tuner_p,                                         STTUNER_EventType_t *Event_p);static TUNER_ErrorCode_t ProcessTracking(TUNER_ControlBlock_t *Tuner_p,                                         STTUNER_EventType_t *Event_p);static TUNER_ErrorCode_t ProcessThresholds(TUNER_ControlBlock_t *Tuner_p,                                           STTUNER_EventType_t *Event_p);static TUNER_ErrorCode_t GetTunerInfo(TUNER_ControlBlock_t *Tuner_p);static void LNBPowerDown(TUNER_ControlBlock_t *Tuner_p);/* API routines ----------------------------------------------------------- *//*****************************************************************************Name: TUNER_Init()Description:    Initializes each tuner component and then interrogates for each    device's capabilities.  The tuner control block is initialized    with all appropriate settings allowing the STAPI layer to    access this information directly.Parameters:    Tuner_p,    pointer to a tuner control block.Return Value:    TUNER_NO_ERROR,     the operation completed without error.    TUNER_ERROR_LNB_HW, a hardware error in the LNB circuit.See Also:    TUNER_Term()*****************************************************************************/TUNER_ErrorCode_t TUNER_Init(TUNER_ControlBlock_t *Tuner_p,                             STTUNER_InitParams_t *InitParams_p){    TUNER_ErrorCode_t Error = TUNER_NO_ERROR;    TNR_InitParams_t TNRInitParams;    DEMOD_InitParams_t DEMODInitParams;    SAT_InitParams_t SATInitParams;    int rc;    /* Clear out the tuner handle */    Tuner_p->Handle = 0;    /* In order to support the I2C Repeater mode, the demod is first     *  initialized. Then, the tuner is initialized and then, the tuner handle     *  is set in the demod structure via the function DEMOD_InitTunerHandle()     */    DEMODInitParams.DeviceAccess_p = &Tuner_p->I2CDemodHandle; /* I2C handle */    DEMODInitParams.TunerHandle = Tuner_p->TunerHandle; /* Depends on TNR */    DEMODInitParams.ExternalClock = InitParams_p->ExternalClock;    DEMODInitParams.DemodType = InitParams_p->DemodType;    DEMODInitParams.TSOutputMode = InitParams_p->TSOutputMode;    DEMODInitParams.SerialDataMode = InitParams_p->SerialDataMode;    DEMODInitParams.SerialClockSource = InitParams_p->SerialClockSource;    DEMODInitParams.FECMode = InitParams_p->FECMode;    DEMODInitParams.MemoryPartition = InitParams_p->DriverPartition;    Error = DEMOD_Init(&DEMODInitParams,                       &Tuner_p->DemodHandle,                       &Tuner_p->DEMODCapability                      );    if (Error == DEMOD_NO_ERROR)    {        /* Setup the initialization parameters */        TNRInitParams.DeviceAccess_p = &Tuner_p->I2CTunerHandle; /* I2C handle */        TNRInitParams.TunerType = InitParams_p->TunerType;        TNRInitParams.MemoryPartition = InitParams_p->DriverPartition;        /* the Repeater mode concerns only the STV0299 demod */        if(DEMODInitParams.DemodType == DEMOD_DEVICE_STV0299)        {            TNRInitParams.Repeater = InitParams_p -> Repeater;        }        else        {            TNRInitParams.Repeater = FALSE;        }        TNRInitParams.DemodHandle = Tuner_p->DemodHandle;        /* Initialize each tuner component -- the ordering is crucial, as DEMOD         * depends on TNR and SAT depends on DEMOD, in this implementation.         */        Error = TNR_Init(&TNRInitParams, &Tuner_p->TunerHandle);        if (Error == TNR_NO_ERROR)          /* TNR Init succeeded? */        {            /* To support I2C Repeater mode, we need to initialize the tuner             * handle of the DEmod structure.             */            Error = DEMOD_InitTunerHandle(Tuner_p->DemodHandle, Tuner_p->TunerHandle);            if(Error == DEMOD_NO_ERROR)            {                /* Select appropriate SAT driver */                SATInitParams.SatType = InitParams_p->DemodType;                SATInitParams.DeviceAccess_p = &Tuner_p->I2CDemodHandle;                SATInitParams.MemoryPartition = InitParams_p->DriverPartition;                /* needed to initialize the STV0299_ControlBlock_t struct of the                   SAT_ControlBlock_t struct */                SATInitParams.DemodHandle_p = Tuner_p->DemodHandle;                /* Initialize the SAT device */                Error = SAT_Init(&SATInitParams,                                 &Tuner_p->SatHandle,                                 &Tuner_p->SatCapability);                if (Error == SAT_NO_ERROR)                {                    /* Obtain device capabilties */                    GetCapability(Tuner_p);                    /* Allocate memory for various lists used */                    Tuner_p->ScanList.ScanList = memory_allocate(                        (partition_t *)InitParams_p->DriverPartition,                        (InitParams_p->ScanListMax * sizeof(STTUNER_Scan_t)));                    Tuner_p->BandList.BandList = memory_allocate(                        (partition_t *)InitParams_p->DriverPartition,                        (InitParams_p->BandListMax * sizeof(STTUNER_Band_t)));                    Tuner_p->ThresholdList.ThresholdList = memory_allocate(                        (partition_t *)InitParams_p->DriverPartition,                        (InitParams_p->SignalListMax * sizeof(STTUNER_SignalThreshold_t)));                    Tuner_p->ThresholdHits = memory_allocate(                        (partition_t *)InitParams_p->DriverPartition,                        (InitParams_p->SignalListMax * sizeof(U32)));                    if (Tuner_p->ScanList.ScanList != NULL &&                        Tuner_p->BandList.BandList != NULL &&                        Tuner_p->ThresholdList.ThresholdList != NULL &&                        Tuner_p->ThresholdHits != NULL)                    {                        /* Create the scan busy semaphore required to synchronize access to                         * the scan status, etc -- can't fail.                         */                        semaphore_init_fifo(&Tuner_p->ScanTask.GuardSemaphore, 1);                        /* Create the timeout semaphore -- this allows us to periodically                         * wakeup the scan task to perform background processing e.g.,                         * tracking the locked frequency.                         */                        semaphore_init_fifo_timeout(&Tuner_p->ScanTask.TimeoutSemaphore,                                                    0);                        /* Reset the delete flag to ensure that the task doesn't exit                         * prematurely -- can't fail.                         */                        Tuner_p->ScanTask.DeleteTask = FALSE;                        /* Sets the scan task timer delay -- this controls how often the scan                         * task awakes to perform background processing.                         */                        Tuner_p->ScanTask.TimeoutDelayMs = STTUNER_SCAN_TASK_DELAY_MS;                        /* Initialize the scan task status to startup defaults */                        Tuner_p->ScanInfo.Scan_p = NULL;                        Tuner_p->ScanInfo.ScanIndex = 0;                        Tuner_p->ScanInfo.NextFrequency = 0;                        Tuner_p->ScanInfo.LockCount = 0;    /* For monitoring tracking */                        Tuner_p->ScanInfo.PlrMask = 0;      /* Current polarizations */                        /* Assume that the scan status is "unlocked" to begin with */                        Tuner_p->TunerInfo.Status =                            STTUNER_STATUS_UNLOCKED;                        /* Reset all list sizes to zero */                        Tuner_p->ScanList.NumElements = 0;                        Tuner_p->BandList.NumElements = 0;                        Tuner_p->ThresholdList.NumElements = 0;                        /* Create and start the scan task */                        rc = task_init((void(*)(void *))ScanTask,                                       Tuner_p,                                       Tuner_p->ScanTask.ScanTaskStack,                                       SCAN_TASK_STACK_SIZE,                                       &Tuner_p->ScanTask.ScanTask,                                       &Tuner_p->ScanTask.ScanTaskDescriptor,                                       3,                                       "ScanTask",                                       0);                        /* Task creation may fail, so we check the error code */                        if (rc != 0)                        {                            /* Task creation failed */                            Error = TUNER_ERROR_NO_MEMORY;                        }                    }                    else                    {                        /* Free up any allocated resources */                        if (Tuner_p->ScanList.ScanList != NULL)                            memory_deallocate((partition_t *)InitParams_p->DriverPartition,                                              Tuner_p->ScanList.ScanList                                              );                        if (Tuner_p->BandList.BandList != NULL)                            memory_deallocate((partition_t *)InitParams_p->DriverPartition,                                              Tuner_p->BandList.BandList                                              );                        if (Tuner_p->ThresholdList.ThresholdList != NULL)                            memory_deallocate((partition_t *)InitParams_p->DriverPartition,                                              Tuner_p->ThresholdList.ThresholdList                                             );                        if (Tuner_p->ThresholdHits != NULL)                            memory_deallocate((partition_t *)InitParams_p->DriverPartition,                                              Tuner_p->ThresholdHits                                             );                        /* Memory allocate error */                        Error = TUNER_ERROR_NO_MEMORY;                    }                }            }        }    }    return Error;} /* TUNER_Init() *//*****************************************************************************Name: TUNER_Term()Description:    Performs any necessary task in order to cleanly terminate the tuner    device -- each tuner component is terminated appropriately.Parameters:    Tuner_p,        pointer to a tuner control block.    TermParams_p,   additional parameters to guide the termination process.Return Value:    TUNER_NO_ERROR,     the operation completed without error.See Also:    TUNER_Initialize()*****************************************************************************/TUNER_ErrorCode_t TUNER_Term(TUNER_ControlBlock_t *Tuner_p){    TUNER_ErrorCode_t Error;    task_t *Task_p = &Tuner_p->ScanTask.ScanTask;    /* Wakeup the scan task and lock out the scan task whilst     * we modify the delete task flag.     */    semaphore_wait(&Tuner_p->ScanTask.GuardSemaphore);    semaphore_signal(&Tuner_p->ScanTask.TimeoutSemaphore);    /* Flag the timer as waiting to be deleted */    Tuner_p->ScanTask.DeleteTask = TRUE;    semaphore_signal(&Tuner_p->ScanTask.GuardSemaphore);    /* The task should be in the process of returning, but wait for     * it first before deleting it. */    if (task_wait(&Task_p,1,TIMEOUT_INFINITY) == 0)    {        /* Now it should be safe to delete the task */        if (task_delete(&Tuner_p->ScanTask.ScanTask) == 0)        {            /* Delete all semaphores associated with the timer */            semaphore_delete(&Tuner_p->ScanTask.GuardSemaphore);            semaphore_delete(&Tuner_p->ScanTask.TimeoutSemaphore);        }    }    /* Free up any allocated resources */    if (Tuner_p->ScanList.ScanList != NULL)        memory_deallocate((partition_t *)Tuner_p->InitParams.DriverPartition,                          Tuner_p->ScanList.ScanList                         );

⌨️ 快捷键说明

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