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

📄 d0299.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ----------------------------------------------------------------------------
File Name: d0299.c

Description: 

    stv0299 demod driver.


Copyright (C) 1999-2001 STMicroelectronics

History:
 
   date: 19-June-2001
version: 3.1.0
 author: GJP from work by LW
comment: write for multi-instance.
    
   date: 17-August-2001
version: 3.1.1
 author: GJP
comment: update SubAddr to U16

   date: 23-Oct-2001
version: 3.2.0
 author: GJP
comment: corrected chip ID bug (A0 instead of F0 mask)
         added SetModulation() function

Reference:

    ST API Definition "TUNER Driver API" DVD-API-06
---------------------------------------------------------------------------- */


/* Includes ---------------------------------------------------------------- */
#ifdef ST_OSLINUX
   #include "stos.h"
#else

/* C libs */
#include <string.h>                     

#include "stlite.h"     /* Standard includes */

/* STAPI */
#include "sttbx.h"

#endif
#include "sttuner.h"                    

/* local to sttuner */
#ifndef STTUNER_MINIDRIVER
#include "stevt.h"
#include "util.h"       /* generic utility functions for sttuner */
#include "dbtypes.h"    /* data types for databases */
#include "sysdbase.h"   /* functions to accesss system data */
#include "ioarch.h"     /* I/O for this driver */
#include "ioreg.h"      /* I/O for this driver */
#include "sioctl.h"     /* data structure typedefs for all the the sat ioctl functions */
#endif
#include "reg0299.h"    /* register mappings for the stv0299 */
#include "drv0299.h"    /* misc driver functions */
#include "d0299.h"      /* header for this file */
#ifdef STTUNER_MINIDRIVER
#include "sysdbase.h"
#include "stcommon.h" 
#endif


/* Global variable to keep track of current running task */
extern task_t *TunerTask1, *TunerTask2; 

/* Global variable which sets to 2 when both task are running and helps
 to differentiate when single tuner is running and when dual tuner is running */
extern U8 ucDualTunerFlag;

#ifdef STTUNER_MINIDRIVER
long D0299_CarrierWidth(long SymbolRate);
#endif
/* Private types/constants ------------------------------------------------ */

#define ANALOG_CARRIER_DETECT_SYMBOL_RATE   5000000
#define ANALOG_CARRIER_DETECT_AGC2_VALUE    25
/* Device capabilities */
#define MAX_AGC                         255
#define MAX_SIGNAL_QUALITY              100
#define MAX_BER                         200000

#ifdef STTUNER_DRV_SAT_SCR
extern ST_ErrorCode_t scr_scrdrv_SetFrequency   (STTUNER_Handle_t Handle, DEMOD_Handle_t DemodHandle, ST_DeviceName_t *DeviceName, U32  InitialFrequency,  U8 LNBIndex, U8 SCRBPF );
#endif

#define STV0299_SYMBOL_RATE_MIN 1000000
#define STV0299_SYMBOL_RATE_MAX 50000000

/* Added by for Debug 19 July 2k2 */
#ifdef USE_TRACE_BUFFER_FOR_DEBUG
#define DMP
extern void DUMP_DATA(char *info) ;
extern char Trace_PrintBuffer[40]; /* global variable to be seen by modules */
#endif
/* private variables ------------------------------------------------------- */
#if defined(ST_OS21) || defined(ST_OSLINUX)
static semaphore_t *Lock_InitTermOpenClose; /* guard calls to the functions */
#else
static semaphore_t Lock_InitTermOpenClose; /* guard calls to the functions */
#endif

#ifndef STTUNER_MINIDRIVER
static BOOL        Installed = false;

U16 STV0299_Address[STV0299_NBREGS]={
 0x00,  0x01,   0x02,   0x03,    0x04,    0x05,     0x06,    0x07,    0x08,
 0x09,  0x0A,   0x0B,   0x0C,    0x0D,    0x0E,     0x0F,    0x10,    0x11,
 0x12,  0x13,   0x14,   0x15,    0x16,    0x17,     0x18,    0x19,    0x1A,
 0x1B,  0x1C,   0x1D,   0x1E,    0x1F,    0x20,     0x21,    0x22,    0x23,
 0x24,  0x25,   0x26,   0x28,    0x29,    0x2A,     0x2B,    0x2C,    0x2D,
 0x31,  0x32,   0x33,   0x34,    0x40,    0x41,     0x42,    0x43,    0x44,
 0x45,  0x46,   0x47,   0x48,    0x49,    0x4A,     0x4B,    0x4C,    0x4D,
 0x4E,  0x4F
};

 U8 STV0299_DefVal[STV0299_NBREGS]={
 0xA1,  0x15,  	0x00,   0x00,   0x7D,	  0x05,     0x02,    0x00,     0x40,
 0x00,  0x82,   0x00,   0x00,   0x81,     0x23,     0x15,    0x34,     0x84/*0x99*/,
 0xb9,  0x9b,   0x9e,   0xe3,   0x80,     0x18,     0xff,    0xff,     0x82,
 0x00,  0x7f,   0x00,   0x00,   0x00,     0x00,     0x00,    0x80,     0x0b,
 0x2b,  0x75,   0x1a,   0x00,   0x1E,     0x14,     0x0F,    0x09,     0x05,
 0x1F,  0x19,   0xFc,   0x13,   0x00,     0x00,	    0x00,    0x00,     0x00,
 0x00,  0x00,   0x00,   0x00,   0x00,     0x00,     0x00,    0x00,     0x00,
 0x00,  0x00
};
/* ---------- per instance of driver ---------- */
typedef struct
{
    ST_DeviceName_t            	*DeviceName;           /* unique name for opening under */
    STTUNER_Handle_t          	TopLevelHandle;       /* access tuner, lnb etc. using this */
    IOARCH_Handle_t          	IOHandle;             /* instance access to I/O driver     */
    STTUNER_IOREG_DeviceMap_t 	DeviceMap;            /* stv0299 register map & data table */
    D0299_StateBlock_t          StateBlock;           /* driver search/state information   */
    ST_Partition_t            	*MemoryPartition;     /* which partition this data block belongs to */
    void                      	*InstanceChainPrev;   /* previous data block in chain or NULL if not */
    void                      	*InstanceChainNext;   /* next data block in chain or NULL if last */
    U32                         ExternalClock;  /* External VCO */
    STTUNER_TSOutputMode_t      TSOutputMode;
    STTUNER_SerialDataMode_t    SerialDataMode;
    STTUNER_BlockSyncMode_t     BlockSyncMode;
    STTUNER_SerialClockSource_t SerialClockSource;
    STTUNER_FECMode_t           FECMode;
    STTUNER_DiSEqCConfig_t      DiSEqCConfig; /** Added DiSEqC configuration structure to get the trace of current state**/
    BOOL                        DISECQ_ST_ENABLE;
    
}D0299_InstanceData_t;
#endif
#ifdef STTUNER_MINIDRIVER
typedef struct
{
    IOARCH_Handle_t          	IOHandle;             /* instance access to I/O driver     */
    STTUNER_Handle_t          	TopLevelHandle;
    ST_DeviceName_t            	*DeviceName; 
    ST_Partition_t            	*MemoryPartition;     /* which partition this data block belongs to */
    U32                         ExternalClock;  /* External VCO */
    STTUNER_TSOutputMode_t      TSOutputMode;
    STTUNER_SerialDataMode_t    SerialDataMode;
    STTUNER_BlockSyncMode_t     BlockSyncMode;
    STTUNER_SerialClockSource_t SerialClockSource;
    STTUNER_FECMode_t           FECMode;
    STTUNER_DiSEqCConfig_t      DiSEqCConfig; /** Added DiSEqC configuration structure to get the trace of current state**/
    BOOL                        DISECQ_ST_ENABLE;
 }D0299_InstanceData_t;
#endif
#ifndef STTUNER_MINIDRIVER
/******Externing from Init.c********/
extern U32 TunerHandleOne;
extern U32 TunerHandleTwo;
#endif

/**************extern from  open.c************************/
#ifdef STTUNER_DRV_SAT_SCR
#ifdef STTUNER_DRV_SAT_SCR_LOOPTHROUGH
extern U32 DemodDrvHandleOne;
#endif
#endif
/* instance chain, the default boot value is invalid, to catch errors */
#ifndef STTUNER_MINIDRIVER
static D0299_InstanceData_t *InstanceChainTop = (D0299_InstanceData_t *)0x7fffffff;
#endif
#ifdef STTUNER_MINIDRIVER
static D0299_InstanceData_t *DEMODInstance;
#endif
	   /* NOW FUNCTION DECLARATION is in header file  */
#ifndef STTUNER_MINIDRIVER

/* API */
ST_ErrorCode_t demod_d0299_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams);
ST_ErrorCode_t demod_d0299_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams);

ST_ErrorCode_t demod_d0299_Open (ST_DeviceName_t *DeviceName, DEMOD_OpenParams_t  *OpenParams, DEMOD_Capability_t *Capability, DEMOD_Handle_t *Handle);
ST_ErrorCode_t demod_d0299_Close(DEMOD_Handle_t  Handle, DEMOD_CloseParams_t *CloseParams);

ST_ErrorCode_t demod_d0299_IsAnalogCarrier (DEMOD_Handle_t Handle, BOOL *IsAnalog);        
ST_ErrorCode_t demod_d0299_GetSignalQuality(DEMOD_Handle_t Handle, U32  *SignalQuality_p, U32 *Ber);
ST_ErrorCode_t demod_d0299_GetModulation   (DEMOD_Handle_t Handle, STTUNER_Modulation_t *Modulation);
ST_ErrorCode_t demod_d0299_SetModulation   (DEMOD_Handle_t Handle, STTUNER_Modulation_t  Modulation);
ST_ErrorCode_t demod_d0299_GetAGC          (DEMOD_Handle_t Handle, S16                  *Agc);
ST_ErrorCode_t demod_d0299_GetFECRates     (DEMOD_Handle_t Handle, STTUNER_FECRate_t    *FECRates);
ST_ErrorCode_t demod_d0299_GetIQMode       (DEMOD_Handle_t Handle, STTUNER_IQMode_t     *IQMode); /*added for GNBvd26107->I2C failure due to direct access to demod device at API level*/
ST_ErrorCode_t demod_d0299_IsLocked        (DEMOD_Handle_t Handle, BOOL                 *IsLocked);
ST_ErrorCode_t demod_d0299_SetFECRates     (DEMOD_Handle_t Handle, STTUNER_FECRate_t     FECRates);
ST_ErrorCode_t demod_d0299_Tracking        (DEMOD_Handle_t Handle, BOOL ForceTracking,   U32 *NewFrequency, BOOL *SignalFound);

ST_ErrorCode_t demod_d0299_ScanFrequency   (DEMOD_Handle_t Handle, U32  InitialFrequency, U32   SymbolRate,    U32   MaxOffset, 
                                                                   U32  TunerStep,        U8    DerotatorStep, BOOL *ScanSuccess,
                                                                   U32 *NewFrequency,     U32   Mode,          U32   Guard,
                                                                   U32  Force,            U32   Hierarchy,     U32   Spectrum,
                                                                   U32  FreqOff,          U32   ChannelBW,     S32   EchoPos);

/* added for DiSEqC API support*/
ST_ErrorCode_t demod_d0299_DiSEqC       (	DEMOD_Handle_t Handle, 
									    STTUNER_DiSEqCSendPacket_t *pDiSEqCSendPacket,
									    STTUNER_DiSEqCResponsePacket_t *pDiSEqCResponsePacket
									   );

ST_ErrorCode_t demod_d0299_DiSEqCGetConfig ( DEMOD_Handle_t Handle ,STTUNER_DiSEqCConfig_t * DiSEqCConfig);
ST_ErrorCode_t demod_d0299_DiSEqCBurstOFF ( DEMOD_Handle_t Handle );

/***************************************/

ST_ErrorCode_t demod_d0299_ioctl           (DEMOD_Handle_t Handle, U32 Function, void *InParams, void *OutParams,
                                             STTUNER_Da_Status_t *Status);

/* I/O API */
ST_ErrorCode_t demod_d0299_ioaccess(DEMOD_Handle_t Handle, IOARCH_Handle_t IOHandle,
                  STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout);

/* local functions --------------------------------------------------------- */
#ifdef STTUNER_DRV_SAT_SCR
ST_ErrorCode_t demod_d0299_tonedetection(DEMOD_Handle_t Handle,U32 StartFreq, U32 StopFreq, U8  *NbTones,U32 *ToneList, U8 mode,int* power_detection_level);
#endif
D0299_InstanceData_t *D0299_GetInstFromHandle(DEMOD_Handle_t Handle);
#endif

#ifdef STTUNER_MINIDRIVER
	extern ST_ErrorCode_t tuner_tunsdrv_SetBandWidth (U32 Bandwidth);
	
	U8 DEFAULT_Register_0299[] = {0xa1,0x15,0x00,0x00,0x7d,0x05,0x02,0x00,0x40,0x00,0x82,0x00,0x40,0x81,0x23,0x15,
	                              0x34,0x84,0xb9,0x9b,0x9e,0xe3,0x80,0x18,0xff,0xff,0x82,0x00,0x7f,0x00,0x00,0x00,
	                              0x00,0x00,0x80,0x0b,0x2b,0x75,0x1a,0x00,0x00,0x1e,0x14,0x0f,0x09,0x05,0x00,0x00,
	                              0x00,0x1f,0x19,0xfc,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	                              0x00,0x00,0x00,0x00,0xa0
	                              };
#endif
/***************************************

Name: STTUNER_DRV_DEMOD_STV0299_Install()

Description:
    install a satellite device driver into the demod database.
    
Parameters:

Return Value:
---------------------------------------------------------------------------- */
#ifndef STTUNER_MINIDRIVER
ST_ErrorCode_t STTUNER_DRV_DEMOD_STV0299_Install(STTUNER_demod_dbase_t *Demod)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
   const char *identity = "STTUNER d0299.c STTUNER_DRV_DEMOD_STV0299_Install()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;

    if(Installed == TRUE)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("%s fail driver already installed\n", identity));
#endif
        return(STTUNER_ERROR_INITSTATE);
    }
   
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    STTBX_Print(("%s installing sat:demod:STV0299...", identity));
#endif

    /* mark ID in database */
    Demod->ID = STTUNER_DEMOD_STV0299;

    /* map API */
    Demod->demod_Init = demod_d0299_Init;
    Demod->demod_Term = demod_d0299_Term;

    Demod->demod_Open  = demod_d0299_Open;
    Demod->demod_Close = demod_d0299_Close;

    Demod->demod_IsAnalogCarrier  = demod_d0299_IsAnalogCarrier; 
    Demod->demod_GetSignalQuality = demod_d0299_GetSignalQuality;
    Demod->demod_GetModulation    = demod_d0299_GetModulation;   
    Demod->demod_SetModulation    = demod_d0299_SetModulation;   
    Demod->demod_GetAGC           = demod_d0299_GetAGC;          
    Demod->demod_GetFECRates      = demod_d0299_GetFECRates;  
    Demod->demod_GetIQMode        = demod_d0299_GetIQMode; /*added for GNBvd26107->I2C failure due to direct access to demod device at API level*/
    Demod->demod_IsLocked         = demod_d0299_IsLocked ;       
    Demod->demod_SetFECRates      = demod_d0299_SetFECRates;     
    Demod->demod_Tracking         = demod_d0299_Tracking;        
    Demod->demod_ScanFrequency    = demod_d0299_ScanFrequency;
	Demod->demod_DiSEqC	  = demod_d0299_DiSEqC;
	Demod->demod_GetConfigDiSEqC   = demod_d0299_DiSEqCGetConfig;  
	Demod->demod_SetDiSEqCBurstOFF   = demod_d0299_DiSEqCBurstOFF; 
    Demod->demod_ioaccess = demod_d0299_ioaccess;
    Demod->demod_ioctl    = demod_d0299_ioctl;
    #ifdef STTUNER_DRV_SAT_SCR
    Demod->demod_tonedetection = demod_d0299_tonedetection;
    #endif
    InstanceChainTop = NULL;
#if defined(ST_OS21) || defined(ST_OSLINUX)  
    Lock_InitTermOpenClose = semaphore_create_fifo(1);
#else
    semaphore_init_fifo(&Lock_InitTermOpenClose, 1);
#endif    

    Installed = TRUE;

#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    STTBX_Print(("ok\n"));
#endif

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_DEMOD_STV0299_UnInstall()

Description:
    install a satellite device driver into the demod database.
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_DEMOD_STV0299_UnInstall(STTUNER_demod_dbase_t *Demod)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
   const char *identity = "STTUNER d0299.c STTUNER_DRV_DEMOD_STV0299_UnInstall()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;

    if(Installed == FALSE)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("%s fail driver not installed\n", identity));
#endif
        return(STTUNER_ERROR_INITSTATE);
    }

⌨️ 快捷键说明

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