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

📄 api.c

📁 这是DVB tuner驱动部分和其它相关的源码和一些技术资料文档.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************File Name   : api.cDescription : TNR interface implementation for "generic" tuner modules.Copyright (C) 2000 STMicroelectronicsRevision History  :     09/04/00    Fixed problem with un-initialized variable in                 routine SetBandwidth().Reference   :ST API Definition "TUNER Driver API" DVD-API-06*****************************************************************************/#define TNR_PROTOTYPE static            /* Local pre-include definitions *//* Includes --------------------------------------------------------------- */#include <string.h>                     /* C lib includes */#include <stdio.h>#include "stlite.h"                     /* Standard includes */#include "stddefs.h"#include "sttuner.h"                    /* STAPI Error codes, etc */#include "i2c.h"#include "demod.h" #include "stv299.h"#include "reg0299.h"#include "tnr.h"                        /* TNR Device API *//* Private types/constants ------------------------------------------------ *//* TNR Device */typedef struct{    void            *MapTable_p;    void            *DeviceAccess_p;    ST_Partition_t  *MemoryPartition;    TNR_TunerType_t TunerType;    TNR_PLLType_t   PLLType;    TNR_Status_t    Status;    U32             FreqFactor;    U8              WriteBuffer[4];    U32             BandWidth[4];    void            *DemodHandle;    BOOL            Repeater; } TNR_ControlBlock_t;/* DEMOD control block */typedef struct{    DEMOD_MapTable_t        *MapTable_p;    /* Maptable */    ST_Partition_t          *MemoryPartition;    STV0299_ControlBlock_t  STV0299ControlBlock;} DEMOD_ControlBlock_t;#define I2C_TIMEOUT                     10/* Private variables ------------------------------------------------------ */extern TNR_MapTable_t __GenericTunerMapTable;/* Private macros --------------------------------------------------------- *//* Obtain control block from handle */#define API_HANDLE(x)           ((TNR_ControlBlock_t *)x)#define STV0299_HANDLE(x)       (&((DEMOD_ControlBlock_t *)x)->STV0299ControlBlock)/* Private function prototypes -------------------------------------------- */static __inline U32 CalculateSteps(TNR_ControlBlock_t *Tnr_p);static __inline U32 CalculateFrequency(TNR_ControlBlock_t *Tnr_p);/* API routines ----------------------------------------------------------- *//*****************************************************************************Name: TNR_ReadWrite()Description:    Sends the commands to the pilot the tuner via the I2C bus. If the I2C    Repeater mode is enabled, the function first set the corresponding     register in the demod.Parameters:    Tnr_p,      Handle of the tuner    Operation,  operation to perform on the tuner (I2C_READ, I2C_WRITE ...)Return Value:    TNR_NO_ERROR,               the operation completed without error.    TNR_ERROR_BAD_PARAMETER,    the I2C handle passed was invalid.See Also:    Nothing.*****************************************************************************/static TNR_ErrorCode_t TNR_ReadWrite(TNR_Handle_t Tnr_p,I2C_Operation_t Operation,U32 Size){    TNR_ErrorCode_t Error = TNR_NO_ERROR;        if(Tnr_p == NULL)    {        Error = TNR_ERROR_BAD_PARAMETER;    }    else    {        if(API_HANDLE(Tnr_p)->Repeater)        {            RegSetField(STV0299_HANDLE(API_HANDLE(Tnr_p)->DemodHandle),I2CT,1);         }                Error = I2C_Transfer(API_HANDLE(Tnr_p)->DeviceAccess_p,Operation,0,API_HANDLE(Tnr_p)->WriteBuffer,Size,I2C_TIMEOUT);        }                                return Error;   }/*****************************************************************************Name: TNR_Init()Description:    Initializes the TNR API level -- makes appropriate calls to reset the    tuner hardware, and fills in tuner device type information.Parameters:    InitParams_p,   pointer to initialization parameters for guiding                    the initialization of this device.Return Value:    TNR_NO_ERROR,               the operation completed without error.    TNR_ERROR_BAD_PARAMETER,    the I2C handle passed was invalid.See Also:    TNR_Term()*****************************************************************************/static TNR_ErrorCode_t TNR_Init(TNR_InitParams_t *InitParams_p,                                TNR_Handle_t *Handle_p){    TNR_ErrorCode_t Error = TNR_NO_ERROR;    TNR_ControlBlock_t *Tnr_p;    /* Allocate memory for the control block */    Tnr_p = memory_allocate(InitParams_p->MemoryPartition,                            sizeof(TNR_ControlBlock_t));    /* Ensure memory was really allocated */    if (Tnr_p == NULL)        return ST_ERROR_NO_MEMORY;    /* Set map table */    Tnr_p->MapTable_p = &__GenericTunerMapTable;    Tnr_p->MemoryPartition = InitParams_p->MemoryPartition;    /* Hardware specific binding */    Tnr_p->DeviceAccess_p = InitParams_p->DeviceAccess_p;    Tnr_p->TunerType = InitParams_p->TunerType;    Tnr_p->DemodHandle = InitParams_p->DemodHandle;    Tnr_p->Repeater = InitParams_p->Repeater;        if(InitParams_p->TunerType == TNR_DEVICE_EVALMAX)    {        RegSetField(InitParams_p->DemodHandle, IAGC, 1);    }    else    {        RegSetField(InitParams_p->DemodHandle, IAGC, 0);    }            /* Default settings for the device */    switch (InitParams_p->TunerType)    {        case TNR_DEVICE_68G21:            Tnr_p->PLLType = TNR_PLL_5522;            Tnr_p->FreqFactor = 1;            Tnr_p->Status.TunerStep = 125000;            Tnr_p->Status.IntermediateFrequency = 479500;            Tnr_p->BandWidth[0] = 36000;            Tnr_p->BandWidth[1] = 0;            Tnr_p->Status.IQSense = -1;            Tnr_p->WriteBuffer[0] = 0x0B;            Tnr_p->WriteBuffer[1] = 0x00;            Tnr_p->WriteBuffer[2] = 0xCE;            Tnr_p->WriteBuffer[3] = 0xA1;            break;        case TNR_DEVICE_VG1011:            Tnr_p->PLLType = TNR_PLL_5655;            Tnr_p->FreqFactor = 1;            Tnr_p->Status.TunerStep = 125000;            Tnr_p->Status.IntermediateFrequency = 479500;            Tnr_p->BandWidth[0] = 36000;            Tnr_p->BandWidth[1] = 0;            Tnr_p->Status.IQSense = 1;            Tnr_p->WriteBuffer[0] = 0x34;            Tnr_p->WriteBuffer[1] = 0x7C;            Tnr_p->WriteBuffer[2] = 0x95;            Tnr_p->WriteBuffer[3] = 0x80;            break;        case TNR_DEVICE_TUA6100:            Tnr_p->PLLType = TNR_PLL_TUA6100;            Tnr_p->FreqFactor = 1;            Tnr_p->Status.TunerStep = 125000;            Tnr_p->Status.IntermediateFrequency = 0;            Tnr_p->BandWidth[0] = 60000;            Tnr_p->BandWidth[1] = 0;            Tnr_p->Status.IQSense = 1;            Tnr_p->WriteBuffer[0] = 0x00;            Tnr_p->WriteBuffer[1] = 0x0B;            TNR_ReadWrite(Tnr_p,I2C_WRITE,2);            Tnr_p->WriteBuffer[0] = 0x02;            Tnr_p->WriteBuffer[1] = 0x1C;            Tnr_p->WriteBuffer[2] = 0x20;            TNR_ReadWrite(Tnr_p,I2C_WRITE,3);            Tnr_p->WriteBuffer[0] = 0x01;            Tnr_p->WriteBuffer[1] = 0x2C;            Tnr_p->WriteBuffer[2] = 0x96;            Tnr_p->WriteBuffer[3] = 0x00;            break;        case TNR_DEVICE_EVALMAX:            Tnr_p->PLLType = TNR_PLL_5655;            Tnr_p->FreqFactor = 1;            Tnr_p->Status.TunerStep = 500000;            Tnr_p->Status.IntermediateFrequency = 479500;            Tnr_p->BandWidth[0] = 16000;            Tnr_p->BandWidth[1] = 60000;            Tnr_p->BandWidth[2] = 0;            Tnr_p->Status.IQSense = 1;            Tnr_p->WriteBuffer[0] = 0x08;            Tnr_p->WriteBuffer[1] = 0xC2;            Tnr_p->WriteBuffer[2] = 0x82;            Tnr_p->WriteBuffer[3] = 0x41;            break;        default:            /* Device type unknown */            Error = TNR_ERROR_BAD_PARAMETER;            break;    }    /* Select default bandwidth */    Tnr_p->Status.Bandwidth = Tnr_p->BandWidth[0];    /* Set device configuration */    Error = TNR_ReadWrite(Tnr_p,I2C_WRITE,4);    /* Allocate handle */    *Handle_p = Tnr_p;    /* Ensure I2C communciation is working */    if (Error != ST_NO_ERROR)    {        /* Deallocate control block */        memory_deallocate(InitParams_p->MemoryPartition,                          Tnr_p);    }    return Error;} /* TNR_Init() *//*****************************************************************************Name: TNR_Term()Description:    Performs any required tidying up in order to cleanly terminate the    TNR device.Parameters:    Tnr_p,          pointer to the TNR device.Return Value:

⌨️ 快捷键说明

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