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

📄 d0362.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
0xff,/*	 CRL_FREQ3          	0x00a2*/
0x11,/*	 CHC_CTL1           	0x00a3*/
0xee,/*	 CHC_SNR            	0x00a4*/
0x00,/*	 BDI_CTL            	0x00a5*/
0x00,/*	 DMP_CTL            	0x00a6*/
0x33,/*	 TPS_RCVD1          	0x00a7*/
0x02,/*	 TPS_RCVD2          	0x00a8*/
0x02,/*	 TPS_RCVD3          	0x00a9*/
0x30,/*	 TPS_RCVD4          	0x00aa*/
0x00,/*	 TPS_ID_CELL1       	0x00ab*/
0x00,/*	 TPS_ID_CELL2       	0x00ac*/
0x00,/*	 TPS_RCVD5_SET1     	0x00ad*/
0x02,/*	 TPS_SET2           	0x00ae*/
0x02,/*	 TPS_SET3           	0x00af*/
0x00,/*	 TPS_CTL            	0x00b0*/
0x2b,/*	 CTL_FFTOSNUM       	0x00b1*/
0x09,/*	 TESTSELECT         	0x00b2*/
0x0a,/*	 MSC_REV            	0x00b3*/
0x00,/*	 PIR_CTL            	0x00b4*/
0xa9,/*	 SNR_CARRIER1       	0x00b5*/
0x86,/*	 SNR_CARRIER2       	0x00b6*/
0x31,/*	 PPM_CPAMP          	0x00b7*/
0x00,/*	 TSM_AP0            	0x00b8*/
0x00,/*	 TSM_AP1            	0x00b9*/
0x00,/*	 TSM_AP2            	0x00ba*/
0x00,/*	 TSM_AP3            	0x00bb*/
0x00,/*	 TSM_AP4            	0x00bc*/
0x00,/*	 TSM_AP5            	0x00bd*/
0x00,/*	 TSM_AP6            	0x00be*/
0x00,/*	 TSM_AP7            	0x00bf*/
0x00,/*	 TSTRES             	0x00c0*/
0x00,/*	 ANACTRL            	0x00c1*/
0x00,/*	 TSTBUS             	0x00c2*/
0x00,/*	 TSTRATE            	0x00c6*/
0x00,/*	 CONSTMODE          	0x00cb*/
0x00,/*	 CONSTCARR1         	0x00cc*/
0x00,/*	 CONSTCARR2         	0x00cd*/
0x00,/*	 ICONSTEL           	0x00ce*/
0x00,/*	 QCONSTEL           	0x00cf*/
0x02,/*	 TSTBISTRES0        	0x00d0*/
0x00,/*	 TSTBISTRES1        	0x00d1*/
0x00,/*	 TSTBISTRES2        	0x00d2*/
0x00,/*	 TSTBISTRES3        	0x00d3*/
0xe6,/*	 RF_AGC1            	0x00d4*/
0x81,/*	 RF_AGC2            	0x00d5*/
0x01,/*	 ANADIGCTRL         	0x00d7*/
0x00,/*	 PLLMDIV            	0x00d8*/
0x10,/*	 PLLSETUP           	0x00da*/
0x08,/*	 DUAL_AD12          	0x00db*/
0x00,/*	 TSTBIST            	0x00dc*/
0x00,/*	 PAD_COMP_CTRL      	0x00dd*/
0x00,/*	 PAD_COMP_WR        	0x00de*/
0xe0,/*	 PAD_COMP_RD        	0x00df*/
0x40 /*	 GHOSTREG           	0x0000*/
};





       
/* Private types/constants ------------------------------------------------ */



/* Device capabilities */
#define MAX_AGC                         255
#define MAX_SIGNAL_QUALITY              100
#define MAX_BER                         200000

/* 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

static BOOL        Installed = FALSE;

#ifdef ST_OS21
#define WAIT_N_MS_362(X)     task_delay( (signed int)(X * (time_ticks_per_sec() / 1000)) )   /*task_delay(X)*/
#else
#define WAIT_N_MS_362(X)     task_delay( (unsigned int)(X * (ST_GetClocksPerSecond() / 1000)) )   /*task_delay(X)*/
#endif




/* instance chain, the default boot value is invalid, to catch errors */
static D0362_InstanceData_t *InstanceChainTop = (D0362_InstanceData_t *)0x7fffffff;

/* functions --------------------------------------------------------------- */


/* API */
ST_ErrorCode_t demod_d0362_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams);
ST_ErrorCode_t demod_d0362_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams);

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

ST_ErrorCode_t demod_d0362_GetTunerInfo    (DEMOD_Handle_t Handle, STTUNER_TunerInfo_t *TunerInfo_p);
ST_ErrorCode_t demod_d0362_GetSignalQuality(DEMOD_Handle_t Handle, U32  *SignalQuality_p, U32 *Ber);
ST_ErrorCode_t demod_d0362_GetModulation   (DEMOD_Handle_t Handle, STTUNER_Modulation_t *Modulation);
ST_ErrorCode_t demod_d0362_GetAGC          (DEMOD_Handle_t Handle, S16                  *Agc);
ST_ErrorCode_t demod_d0362_GetFECRates     (DEMOD_Handle_t Handle, STTUNER_FECRate_t    *FECRates);
ST_ErrorCode_t demod_d0362_GetMode         (DEMOD_Handle_t Handle, STTUNER_Mode_t       *Mode);
ST_ErrorCode_t demod_d0362_GetGuard        (DEMOD_Handle_t Handle, STTUNER_Guard_t      *Guard);
ST_ErrorCode_t demod_d0362_IsLocked        (DEMOD_Handle_t Handle, BOOL                 *IsLocked);
ST_ErrorCode_t demod_d0362_Tracking        (DEMOD_Handle_t Handle, BOOL ForceTracking,   U32 *NewFrequency, BOOL *SignalFound);

ST_ErrorCode_t demod_d0362_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);
ST_ErrorCode_t demod_d0362_ioctl           (DEMOD_Handle_t Handle, U32 Function, void *InParams, void *OutParams,
                                             STTUNER_Da_Status_t *Status);

/* I/O API */
ST_ErrorCode_t demod_d0362_ioaccess(DEMOD_Handle_t Handle, IOARCH_Handle_t IOHandle,
                  STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout);
                  
/* For TPS CellID extraction */
ST_ErrorCode_t demod_d0362_GetTPSCellId(DEMOD_Handle_t Handle, U16  *TPSCellId);

/* For STANDBY API mode */ 
ST_ErrorCode_t demod_d0362_StandByMode(DEMOD_Handle_t Handle, STTUNER_StandByMode_t PowerMode);

/* local functions --------------------------------------------------------- */

D0362_InstanceData_t *d0362_GetInstFromHandle(DEMOD_Handle_t Handle);


/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_DEMOD_STV0362_Install()

Description:
    install a terrestrial device driver (362) into the demod database.

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_DEMOD_STV0362_Install(STTUNER_demod_dbase_t *Demod)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
   const char *identity = "STTUNER d0362.c STTUNER_DRV_DEMOD_STV0362_Install()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;

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

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
    STTBX_Print(("%s installing ter:demod:STV0362...", identity));
#endif

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

    /* map API */
    Demod->demod_Init = demod_d0362_Init;
    Demod->demod_Term = demod_d0362_Term;

    Demod->demod_Open  = demod_d0362_Open;
    Demod->demod_Close = demod_d0362_Close;

    Demod->demod_IsAnalogCarrier  = NULL;
    Demod->demod_GetTunerInfo     = demod_d0362_GetTunerInfo;
    Demod->demod_GetSignalQuality = demod_d0362_GetSignalQuality;
    Demod->demod_GetModulation    = demod_d0362_GetModulation;
    Demod->demod_GetAGC           = demod_d0362_GetAGC;
    Demod->demod_GetMode          = demod_d0362_GetMode;
    Demod->demod_GetGuard         = demod_d0362_GetGuard;
    Demod->demod_GetFECRates      = demod_d0362_GetFECRates;
    Demod->demod_IsLocked         = demod_d0362_IsLocked ;
    Demod->demod_SetFECRates      = NULL;
    Demod->demod_Tracking         = demod_d0362_Tracking;
    Demod->demod_ScanFrequency    = demod_d0362_ScanFrequency;

    Demod->demod_ioaccess = demod_d0362_ioaccess;
    Demod->demod_ioctl    = demod_d0362_ioctl;
    Demod->demod_GetRFLevel	  = NULL;
    Demod->demod_GetTPSCellId = demod_d0362_GetTPSCellId;
    Demod->demod_StandByMode = demod_d0362_StandByMode;

    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_TERDRV_D0362
    STTBX_Print(("ok\n"));
#endif

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_DEMOD_STV0362_UnInstall()

Description:
    uninstall a terrestrial device driver(COFDM) into the demod database.

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_DEMOD_STV0362_UnInstall(STTUNER_demod_dbase_t *Demod)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
   const char *identity = "STTUNER d0362.c STTUNER_DRV_DEMOD_STV0362_UnInstall()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;

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

    if(Demod->ID != STTUNER_DEMOD_STV0362)
    {
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s fail incorrect driver type\n", identity));
#endif
        return(STTUNER_ERROR_ID);
    }

    /* has all memory been freed, by Term() */
    if(InstanceChainTop != NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s fail at least one instance not terminated\n", identity));
#endif
        return(ST_ERROR_OPEN_HANDLE);
    }


#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
    STTBX_Print(("%s uninstalling ter:demod:STV0362...", identity));
#endif

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

    /* unmap API */
    Demod->demod_Init = NULL;
    Demod->demod_Term = NULL;

    Demod->demod_Open  = NULL;
    Demod->demod_Close = NULL;

    Demod->demod_IsAnalogCarrier  = NULL;
    Demod->demod_GetTunerInfo     = NULL;
    Demod->demod_GetSignalQuality = NULL;
    Demod->demod_GetModulation    = NULL;
    Demod->demod_GetAGC           = NULL;
    Demod->demod_GetMode          = NULL;
    Demod->demod_GetFECRates      = NULL;
    Demod->demod_GetGuard         = NULL;
    Demod->demod_IsLocked         = NULL;
    Demod->demod_SetFECRates      = NULL;
    Demod->demod_Tracking         = NULL;
    Demod->demod_ScanFrequency    = NULL;

    Demod->demod_ioaccess = NULL;
    Demod->demod_ioctl    = NULL;
    Demod->demod_GetRFLevel	  = NULL;
    Demod->demod_GetTPSCellId = NULL;
    Demod->demod_StandByMode = NULL ;

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("<"));
#endif

#if defined (ST_OS21) || defined (ST_OSLINUX)
  semaphore_delete(Lock_InitTermOpenClose);
#else
        semaphore_delete(&Lock_InitTermOpenClose);
#endif 

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print((">"));
#endif

    InstanceChainTop = (D0362_InstanceData_t *)0x7ffffffe;
    Installed        = FALSE;

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

    return(Error);
}



/* ------------------------------------------------------------------------- */
/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ API /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
/* ------------------------------------------------------------------------- */



/* ----------------------------------------------------------------------------
Name: demod_d0362_Init()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
    const char *identity = "STTUNER d0362.c demod_d0362_Init()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0362_InstanceData_t *InstanceNew, *Instance;
	
    if(Installed == FALSE)
    {
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s fail driver not installed\n", identity));
#endif
        return(STTUNER_ERROR_INITSTATE);
    }

    /* now safe to lock semaphore */
    SEM_LOCK(Lock_InitTermOpenClose);

    /* ---------- check params ---------- */
    Error = STTUNER_Util_CheckPtrNull(InitParams->MemoryPartition);
    if( Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s fail MemoryPartition not valid\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }

    Error = STTUNER_Util_CheckPtrNull(DeviceName);
    if( Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s fail DeviceName not valid\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }

    InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( D0362_InstanceData_t ));
    if (InstanceNew == NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s fail memory allocation InstanceNew\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_NO_MEMORY);
    }

    /* slot into chain */
    if (InstanceChainTop == NULL)
    {
        InstanceNew->InstanceChainPrev = NULL; /* no previous instance */
        InstanceChainTop = InstanceNew;
    }
    else    /* tag onto last data block in chain */
    {
        Instance = InstanceChainTop;

        while(Instance->InstanceChainNext != NULL)
        {
            Instance = Instance->InstanceChainNext;   /* next block */
        }
        Instance->InstanceChainNext     = (void *)InstanceNew;
        InstanceNew->InstanceChainPrev  = (void *)Instance;
    }

    InstanceNew->DeviceName          = DeviceName;
    InstanceNew->TopLevelHandle      = STTUNER_MAX_HANDLES;
    InstanceNew->IOHandle            = InitParams->IOHandle;
    InstanceNew->MemoryPartition     = InitParams->MemoryPartition;
    InstanceNew->InstanceChainNext   = NULL; /* always last in the chain */

    InstanceNew->ExternalClock       = InitParams->ExternalClock;
    InstanceNew->TSOutputMode        = InitParams->TSOutputMode;
    InstanceNew->SerialDataMode      = InitParams->SerialDataMode;
    InstanceNew->SerialClockSource   = InitParams->SerialClockSource;
    InstanceNew->FECMode             = InitParams->FECMode;
    InstanceNew->ClockPolarity       = InitParams->ClockPolarity;
    InstanceNew->DeviceMap.Timeout   = IOREG_DEFAULT_TIMEOUT;
    InstanceNew->DeviceMap.Registers = STV0362_NBREGS;
    InstanceNew->DeviceMap.Fields    = STV0362_NBFIELDS;
    InstanceNew->DeviceMap.Mode      = IOREG_MODE_SUBADR_8; /* i/o addressing mode to use */
    InstanceNew->DeviceMap.MemoryPartition = InitParams->MemoryPartition;
    InstanceNew->DeviceMap.DefVal= (U32 *)&STV0362_DefVal[0];

⌨️ 快捷键说明

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