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

📄 stv299_i.c

📁 这是DVB tuner驱动部分和其它相关的源码和一些技术资料文档.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************File Name   : stv299_i.cDescription : STV0299 implementation of the DEMOD API.Copyright (C) 1999 STMicroelectronicsRevision History    :24/01/00    Started to work towards a multiple instance model with            introduction of the function map table.  Further work            required to convert CBB code to use non-global data            throughout code.02/02/00    Added support for FEC mode, serial clock control,            serial data mode and TS output mode.Reference           :ST API Definition "TUNER Driver API" DVD-API-06*****************************************************************************/#define DEMOD_PROTOTYPE static          /* Local pre-include defs *//* Includes --------------------------------------------------------------- */#include <string.h>                     /* C libs */ #include <stdio.h>#include "stlite.h"                     /* Standard includes */#include "stddefs.h"#include "sttuner.h"                    /* STAPI Error codes, etc */#include "stcommon.h"#include "demod.h"                      /* DEMOD Device API */#include "tnr.h"                        /* TNR Device API */#include "stv299.h"                     /* Low-level device access */#include "reg0299.h"#include "driv0299.h"/* Private types/constants ------------------------------------------------ */#define ANALOG_CARRIER_DETECT_SYMBOL_RATE   5000000#define ANALOG_CARRIER_DETECT_AGC2_VALUE    25/* DEMOD control block */typedef struct{    DEMOD_MapTable_t        *MapTable_p;    /* Maptable */    ST_Partition_t          *MemoryPartition;    STV0299_ControlBlock_t  STV0299ControlBlock;} DEMOD_ControlBlock_t;/* Private variables ------------------------------------------------------ */extern DEMOD_MapTable_t __STV0299MapTable;/* Private macros --------------------------------------------------------- *//* Extracts a 299 control block from a DEMOD handle */#define STV0299_HANDLE(x)   (&((DEMOD_ControlBlock_t *)x)->STV0299ControlBlock)/* Private function prototypes -------------------------------------------- *//* API routines ----------------------------------------------------------- *//*****************************************************************************Name: DEMOD_Init()Description:    Initializes the DEMOD device.Parameters:    InitParams_p,   pointer to init params to for guiding the initialization                    process for this device.Return Value:    DEMOD_NO_ERROR,             the operation completed without error.    STI2C_xxx,                  there was a problem accessing the device.    DEMOD_ERROR_BAD_PARAMETER,  one or more params were invalid.See Also:    Nothing.*****************************************************************************/static DEMOD_ErrorCode_t DEMOD_Init(DEMOD_InitParams_t *InitParams_p,                                    DEMOD_Handle_t *Handle_p,                                    DEMOD_Capability_t *Capability_p){    DEMOD_ErrorCode_t Error = DEMOD_NO_ERROR;    DEMOD_ControlBlock_t *Demod_p;    /* Allocate control block memory */    Demod_p = memory_allocate(InitParams_p->MemoryPartition,                              sizeof(DEMOD_ControlBlock_t));    /* Ensure allocation succeeded */    if (Demod_p == NULL)        return ST_ERROR_NO_MEMORY;    /* Store away internal maptable */    Demod_p->MapTable_p = &__STV0299MapTable;    Demod_p->MemoryPartition = InitParams_p->MemoryPartition;    /* Set capabilties */    Capability_p->FECAvail = DEMOD_FEC_ALL;    Capability_p->ModulationAvail = DEMOD_MOD_ALL;    Capability_p->AGCControl = FALSE;    Capability_p->SymbolMin = 0;    /* !!TBD!! */    Capability_p->SymbolMax = ((U32)-1); /* !!TBD!! */    /* Set handles */    STV0299_HANDLE(Demod_p)->I2CHandle = InitParams_p->DeviceAccess_p;    STV0299_HANDLE(Demod_p)->TunerHandle = InitParams_p->TunerHandle;    STV0299_HANDLE(Demod_p)->ScanMode = CHANNEL;    /* Initialize 299 registers */    Error = RegInit(STV0299_HANDLE(Demod_p));    /* Check DEMOD initialization options */    /* TS output mode */    switch (InitParams_p->TSOutputMode)    {        case DEMOD_TS_SERIAL:            RegSetField(STV0299_HANDLE(Demod_p), OUTPUTTYPE, 1);            break;        default:        case DEMOD_TS_PARALLEL:        case DEMOD_TS_DEFAULT:            RegSetField(STV0299_HANDLE(Demod_p), OUTPUTTYPE, 0);            break;    }    /* Set FEC mode */    switch (InitParams_p->FECMode)    {        case DEMOD_FEC_MODE_DIRECTV:            RegSetField(STV0299_HANDLE(Demod_p), FECMODE, 4);            break;        default:        case DEMOD_FEC_MODE_DEFAULT:        case DEMOD_FEC_MODE_DVB:            RegSetField(STV0299_HANDLE(Demod_p), FECMODE, 0);            break;    }    /* Only set serial configuration if serial mode output */    if (InitParams_p->TSOutputMode == DEMOD_TS_SERIAL)    {        /* Set serial clock source */        switch(InitParams_p->SerialClockSource)        {            case DEMOD_SCLK_VCODIV6:                RegSetField(STV0299_HANDLE(Demod_p), SERCLK, 1);                break;            default:            case DEMOD_SCLK_DEFAULT:            case DEMOD_SCLK_MASTER:                RegSetField(STV0299_HANDLE(Demod_p), SERCLK, 0);                break;        }        /* Set serial data mode */        if ((InitParams_p->SerialDataMode /* Rising edge */             & DEMOD_SDAT_VALID_RISING) != 0)            RegSetField(STV0299_HANDLE(Demod_p), OUTPUTCLOCKPOLARITY,1);        else            RegSetField(STV0299_HANDLE(Demod_p), OUTPUTCLOCKPOLARITY,0);        if ((InitParams_p->SerialDataMode /* Parity enable */             & DEMOD_SDAT_PARITY_ENABLE) != 0)            RegSetField(STV0299_HANDLE(Demod_p), OUTPUTCLOCKCONFIG, 1);        else            RegSetField(STV0299_HANDLE(Demod_p), OUTPUTCLOCKCONFIG,0);    }    /* Set default error count mode i.e., QPSK bit error rate */    RegSetField(STV0299_HANDLE(Demod_p), ERRORMODE, 0);    RegSetField(STV0299_HANDLE(Demod_p), ERRORSOURCE, 0);    RegSetField(STV0299_HANDLE(Demod_p), NOE, 3);    /* Set caller's handle */    *Handle_p = Demod_p;    /* Ensure device communications is working */    if (Error != DEMOD_NO_ERROR)    {        /* Deallocate control block */        memory_deallocate(InitParams_p->MemoryPartition,                          Demod_p);    }        return Error;} /* DEMOD_Init() */DEMOD_ErrorCode_t DEMOD_InitTunerHandle(DEMOD_Handle_t Handle, TNR_Handle_t TunerHandle){	DEMOD_ErrorCode_t Error = DEMOD_NO_ERROR;		if((Handle == NULL) || (TunerHandle == NULL))	{		Error = DEMOD_ERROR_BAD_PARAMETER;	}	else	{		(STV0299_HANDLE(Handle))->TunerHandle = TunerHandle;	}		return Error;}/*****************************************************************************Name: DEMOD_Term()Description:    Performs any necessary operations that are required to cleanup after    the DEMOD device.Parameters:    Demod_p,        pointer to the DEMOD device.Return Value:    DEMOD_NO_ERROR, the operation completed without error.    Other error codes TBD.See Also:    Nothing.*****************************************************************************/static DEMOD_ErrorCode_t DEMOD_Term(DEMOD_Handle_t Handle){    memory_deallocate(((DEMOD_ControlBlock_t *)Handle)->MemoryPartition,                      Handle);    return DEMOD_NO_ERROR;} /* DEMOD_Term() *//*****************************************************************************Name: DEMOD_IsAnalogCarrier()Description:    This routine checks for an analog carrier on the current frequency    by setting the symbol rate to 5M (never a digital signal).Parameters:    Demod_p,        pointer to the DEMOD device.    IsAnalog_p,     pointer to area to store result:                    TRUE - is analog                    FALSE - is not analogReturn Value:    DEMOD_NO_ERROR,     the operation completed without error.    STI2C_xxx,          there was a problem accessing the device.See Also:    Nothing.*****************************************************************************/static DEMOD_ErrorCode_t DEMOD_IsAnalogCarrier(DEMOD_Handle_t Handle,                                               BOOL *IsAnalog_p){    U8 i;    U16 Agc2 = 0;    /* Assume no analog carrier */    *IsAnalog_p = FALSE;    /* Set the symbol rate to analog carrier rate */    RegSetSymbolRate(STV0299_HANDLE(Handle), ANALOG_CARRIER_DETECT_SYMBOL_RATE);    /* Take four AGC2 samples */    for (i = 0; i < 4; i++)    {        /* Read AGC2I1 and AGC2I2 registers */        RegGetRegisters(STV0299_HANDLE(Handle), R_AGC2I1,2);        Agc2 += (FieldGetVal(STV0299_HANDLE(Handle), AGC2INTEGRATORMSB)<<8) +                FieldGetVal(STV0299_HANDLE(Handle), AGC2INTEGRATORLSB);    }    Agc2 /= 4;                          /* Average AGC2 values */    /* Test for good signal strength -- centre of analog carrier */    *IsAnalog_p = (Agc2 < ANALOG_CARRIER_DETECT_AGC2_VALUE) ? TRUE : FALSE;    return DEMOD_NO_ERROR;} /* DEMOD_IsAnalogCarrier() *//*****************************************************************************Name: DEMOD_GetSignalQuality()Description:    Obtains a signal quality setting for the current lock.Parameters:    Demod_p,            pointer to the DEMOD device.    SignalQuality_p,    pointer to area to store the signal quality value.    Ber_p,              pointer to area to store the bit error rate.Return Value:    DEMOD_NO_ERROR,     the operation completed without error.    STI2C_xxx,          there was a problem accessing the device.See Also:

⌨️ 快捷键说明

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