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

📄 d0370qam.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
0x00f2,/*REGISTER CTRL_5                - 0xf483 */
0x001b,/*REGISTER MPEG_CTRL             - 0xf491 */
0x000f,/*REGISTER MPEG_SYNC_ACQ         - 0xf492 */
0x003f,/*REGISTER MPEG_SYNC_LOSS        - 0xf493 */
0x000d,/*REGISTER VIT_SYNC_ACQ          - 0xf495 */
0x00dc,/*REGISTER VIT_SYNC_LOSS         - 0xf496 */
0x0008,/*REGISTER VIT_SYNC_GO           - 0xf497 */
0x0008,/*REGISTER VIT_SYNC_STOP         - 0xf498 */
0x00a8,/*REGISTER FS_SYNC               - 0xf499 */
0x0081,/*REGISTER IN_DEPTH              - 0xf49a */
0x00fb,/*REGISTER RS_CTRL               - 0xf49b */
0x0047,/*REGISTER DEINTER_CTRL          - 0xf49c */
0x001e,/*REGISTER SYNC_STAT             - 0xf49d */
0x0007,/*REGISTER VITERBI_I_RATE        - 0xf49e */
0x0005,/*REGISTER VITERBI_Q_RATE        - 0xf49f */
0x003b,/*REGISTER RS_CORR_CNT_LSB       - 0xf4a0 */
0x0001,/*REGISTER RS_CORR_CNT_MSB       - 0xf4a1 */
0x00ff,/*REGISTER RS_UNERR_CNT_LSB      - 0xf4a2 */
0x003f,/*REGISTER RS_UNERR_CNT_MSB      - 0xf4a3 */
0x009d,/*REGISTER RS_UNC_CNT_LSB        - 0xf4a4 */
0x0007,/*REGISTER RS_UNC_CNT_MSB        - 0xf4a5 */
0x0000,/*REGISTER RS_RATE_LSB           - 0xf4a6 */
0x0003,/*REGISTER RS_RATE_MSB           - 0xf4a7 */
0x0001,/*REGISTER TX_IN_DEPTH           - 0xf4a8 */
0x0000,/*REGISTER RS_ERR_CNT_LSB        - 0xf4a9 */
0x000f,/*REGISTER RS_ERR_CNT_MSB        - 0xf4aa */
0x0080,/*REGISTER OUT_FORMAT_0          - 0xf4ac */
0x0022,/*REGISTER OUT_FORMAT_1          - 0xf4ad */
0x0000,/*REGISTER OUT_FORMAT_2          - 0xf4ae */
0x000c/*REGISTER INTERRUPT_STAT        - 0xf4af */
};



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

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

/* API */
ST_ErrorCode_t demod_d0370QAM_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams);
ST_ErrorCode_t demod_d0370QAM_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams);

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


ST_ErrorCode_t demod_d0370QAM_IsAnalogCarrier (DEMOD_Handle_t Handle, BOOL *IsAnalog);
ST_ErrorCode_t demod_d0370QAM_GetSignalQuality(DEMOD_Handle_t Handle, U32  *SignalQuality_p, U32 *Ber_p);
ST_ErrorCode_t demod_d0370QAM_GetModulation   (DEMOD_Handle_t Handle, STTUNER_Modulation_t *Modulation);
ST_ErrorCode_t demod_d0370QAM_GetAGC          (DEMOD_Handle_t Handle, S16                  *Agc);
ST_ErrorCode_t demod_d0370QAM_GetFECRates     (DEMOD_Handle_t Handle, STTUNER_FECRate_t    *FECRates);
ST_ErrorCode_t demod_d0370QAM_IsLocked        (DEMOD_Handle_t Handle, BOOL                 *IsLocked);
ST_ErrorCode_t demod_d0370QAM_SetFECRates     (DEMOD_Handle_t Handle, STTUNER_FECRate_t     FECRates);
ST_ErrorCode_t demod_d0370QAM_Tracking        (DEMOD_Handle_t Handle, BOOL ForceTracking,   U32 *NewFrequency, BOOL *SignalFound);

ST_ErrorCode_t demod_d0370QAM_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);
/* access device specific low-level functions */
ST_ErrorCode_t demod_d0370QAM_ioctl           (DEMOD_Handle_t Handle, U32 Function, void *InParams, void *OutParams,
                                             STTUNER_Da_Status_t *Status);

/* repeater/passthrough port for other drivers to use, type: STTUNER_IOARCH_RedirFn_t */
ST_ErrorCode_t demod_d0370QAM_ioaccess         (DEMOD_Handle_t Handle, IOARCH_Handle_t IOHandle,
                                             STTUNER_IOARCH_Operation_t Operation, U16 SubAddr,
                                             U8 *Data, U32 TransferSize, U32 Timeout);

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

D0370QAM_InstanceData_t *D0370QAM_GetInstFromHandle(DEMOD_Handle_t Handle);

/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_DEMOD_STB0370QAM_Install()

Description:
    install a cable device driver into the demod database.

Parameters:

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

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

#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
    STTBX_Print(("%s installing cable:demod:STB0370VSB...", identity));
#endif

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

    /* map API */
    Demod->demod_Init = demod_d0370QAM_Init;
    Demod->demod_Term = demod_d0370QAM_Term;

    Demod->demod_Open  = demod_d0370QAM_Open;
    Demod->demod_Close = demod_d0370QAM_Close;

    Demod->demod_IsAnalogCarrier  = demod_d0370QAM_IsAnalogCarrier;
    Demod->demod_GetSignalQuality = demod_d0370QAM_GetSignalQuality;
    Demod->demod_GetModulation    = demod_d0370QAM_GetModulation;
    Demod->demod_GetAGC           = demod_d0370QAM_GetAGC;
    Demod->demod_GetFECRates      = demod_d0370QAM_GetFECRates;
    Demod->demod_IsLocked         = demod_d0370QAM_IsLocked ;
    Demod->demod_SetFECRates      = demod_d0370QAM_SetFECRates;
    Demod->demod_Tracking         = demod_d0370QAM_Tracking;
    Demod->demod_ScanFrequency    = demod_d0370QAM_ScanFrequency;

    Demod->demod_ioaccess = demod_d0370QAM_ioaccess;
    Demod->demod_ioctl    = demod_d0370QAM_ioctl;

    InstanceChainTop = NULL;
#ifdef ST_OS21
    Lock_InitTermOpenClose = semaphore_create_fifo(1);
#else
    semaphore_init_fifo(&Lock_InitTermOpenClose, 1);
#endif

    Installed = TRUE;

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

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_DEMOD_STB0370QAM_UnInstall()

Description:
    install a cable device driver into the demod database.

Parameters:

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

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

    if(Demod->ID != STTUNER_DEMOD_STB0370QAM)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
        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_CABDRV_D0370QAM
        STTBX_Print(("%s fail at least one instance not terminated\n", identity));
#endif
        return(ST_ERROR_OPEN_HANDLE);
    }


#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
    STTBX_Print(("%s uninstalling cable:demod:STB0370QAM...", 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_GetSignalQuality = NULL;
    Demod->demod_GetModulation    = NULL;
    Demod->demod_GetAGC           = NULL;
    Demod->demod_GetFECRates      = 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;

#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
        STTBX_Print(("<"));
#endif
#ifdef ST_OS21
        semaphore_delete(Lock_InitTermOpenClose);
#else
        semaphore_delete(&Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
        STTBX_Print((">"));
#endif

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

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

    return(Error);
}



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



/* ----------------------------------------------------------------------------
Name: demod_d0370QAM_Init()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0370QAM_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
    const char *identity = "STTUNER d0370QAM.c demod_d0370QAM_Init()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0370QAM_InstanceData_t *InstanceNew, *Instance;

    if(Installed == FALSE)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
        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_CABDRV_D0370QAM
        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_CABDRV_D0370QAM
        STTBX_Print(("%s fail DeviceName not valid\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }

    InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( D0370QAM_InstanceData_t ));
    if (InstanceNew == NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
        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->DeviceMap.Timeout   = IOREG_DEFAULT_TIMEOUT;
    InstanceNew->DeviceMap.Registers = STB0370_QAM_NBREGS;
    InstanceNew->DeviceMap.Fields    = STB0370_QAM_NBFIELDS;
    InstanceNew->DeviceMap.Mode      = IOREG_MODE_SUBADR_16;
    InstanceNew->DeviceMap.MemoryPartition = InitParams->MemoryPartition;
    InstanceNew->InstanceChainNext   = NULL; /* always last in the chain */

    InstanceNew->ExternalClock     = (InitParams->ExternalClock)/1000;          /* Unit KHz */
    InstanceNew->TSOutputMode      = InitParams->TSOutputMode;
    InstanceNew->SerialDataMode    = InitParams->SerialDataMode;
    InstanceNew->SerialClockSource = InitParams->SerialClockSource;
    InstanceNew->FECMode           = InitParams->FECMode;
    InstanceNew->Sti5518           = InitParams->Sti5518;
	
    InstanceNew->DeviceMap.DefVal= (U32*)&STB0370_DefVal_256QAM_TD1336[0];
    /*Used in C/N calculation*/
    InstanceNew->Driv0370QAMCNEstimation = 3000;
    InstanceNew->Driv0370QAMCNEstimatorOffset =0;

    /* reserve memory for register mapping */
    Error = STTUNER_IOREG_Open(&InstanceNew->DeviceMap);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0370QAM
        STTBX_Print(("%s fail setup new register database\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);

⌨️ 快捷键说明

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