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

📄 d0299.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
   
    if(Demod->ID != STTUNER_DEMOD_STV0299)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        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_SATDRV_D0299
        STTBX_Print(("%s fail at least one instance not terminated\n", identity));
#endif
        return(ST_ERROR_OPEN_HANDLE);
    }


#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    STTBX_Print(("%s uninstalling sat:demod:STV0299...", 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_SetModulation    = NULL;   
    Demod->demod_GetAGC           = NULL;          
    Demod->demod_GetFECRates      = NULL;      
    Demod->demod_GetIQMode        = NULL; /*added for GNBvd26107->I2C failure due to direct access to demod device at API level*/
    Demod->demod_IsLocked         = NULL;       
    Demod->demod_SetFECRates      = NULL;     
    Demod->demod_Tracking         = NULL;        
    Demod->demod_ScanFrequency    = NULL;
	Demod->demod_DiSEqC			  = NULL;
	Demod->demod_GetConfigDiSEqC  = NULL;  
	Demod->demod_SetDiSEqCBurstOFF = NULL; 
    Demod->demod_ioaccess		  = NULL;
    Demod->demod_ioctl			  = NULL;
    Demod->demod_tonedetection = NULL;

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

#if defined(ST_OS21) || defined(ST_OSLINUX)
    semaphore_delete(Lock_InitTermOpenClose);
#else
    semaphore_delete(&Lock_InitTermOpenClose);
#endif    
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    STTBX_Print((">"));
#endif

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

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

    return(Error);
}

#endif

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

/* ----------------------------------------------------------------------------
Name: demod_d0299_Init()

Description:
    
Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0299_Init(ST_DeviceName_t *DeviceName, DEMOD_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    const char *identity = "STTUNER d0299.c demod_d0299_Init()";
#endif   
ST_ErrorCode_t Error = ST_NO_ERROR;
  #ifndef STTUNER_MINIDRIVER
    D0299_InstanceData_t *InstanceNew, *Instance;

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

    InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( D0299_InstanceData_t ));
    if (InstanceNew == NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        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 = DEF0299_NBREG;
    InstanceNew->DeviceMap.Fields    = DEF0299_NBFIELD;
    InstanceNew->DeviceMap.Error   = ST_NO_ERROR;
    /* depreciated:    InstanceNew->DeviceMap.RegSize   = REGSIZE_8BITS; */
    InstanceNew->DeviceMap.Mode      = IOREG_MODE_SUBADR_8; /* NEW as of 3.4.0: i/o addressing mode to use */
    InstanceNew->DeviceMap.MemoryPartition = InitParams->MemoryPartition;
    InstanceNew->InstanceChainNext   = NULL; /* always last in the chain */
    InstanceNew->ExternalClock     = InitParams->ExternalClock;  
    InstanceNew->TSOutputMode      = InitParams->TSOutputMode;
    InstanceNew->SerialDataMode    = InitParams->SerialDataMode;
    #ifdef STTUNER_BLOCK_SYNC_MODE_SELECT
    InstanceNew->BlockSyncMode     = InitParams->BlockSyncMode;/* add block sync bit control for bug GNBvd27452*/
    #endif
    InstanceNew->SerialClockSource = InitParams->SerialClockSource;
    InstanceNew->FECMode           = InitParams->FECMode;
	/********Added for Diseqc***************************/
	InstanceNew->DiSEqCConfig.Command=STTUNER_DiSEqC_COMMAND;
    InstanceNew->DiSEqCConfig.ToneState=STTUNER_DiSEqC_TONE_CONTINUOUS_OFF;
	/**************************************************/
    
    /* reserve memory for register mapping */
    Error = STTUNER_IOREG_Open(&InstanceNew->DeviceMap);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("%s fail setup new register database\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);           
    }

    /* install a mapping */
    /*Error = Reg0299_Install(&InstanceNew->DeviceMap);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("%s fail install mapping\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);           
    }*/

    /*  DTV needs this (see TunerFecMode() in sttuner/tests/sat/sat_test.c) without this
       for an EVAL board we would have to hack the cable & for the 299 stem it would not work at all.
        Note also that for DTV decode using STPTI and STTUNER set STPTI_InitParams.DiscardSyncByte = TRUE
       and for packet injector (we have found, although YMMV) set STPTI_InitParams.DiscardSyncByte = 0 
       If you have a hacked cable (or PCB) then you can use STTUNER_Ioctl() to reset the register,
       directly after a call to STTUNER_Open() would be best.
    */
   

    /* set misc params for mapping */
    Error = Reg0299_Open(&InstanceNew->DeviceMap, InstanceNew->ExternalClock);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("%s fail setup register database params\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);           
    }

#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( D0299_InstanceData_t ) ));
#endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
/*********************************************MINIDRIVER*********************
*******************************************************************************
**********************************************************************************/    
#ifdef STTUNER_MINIDRIVER
	#if defined(ST_OS21) || defined(ST_OSLINUX)
	    Lock_InitTermOpenClose = semaphore_create_fifo(1);
	#else
	    semaphore_init_fifo(&Lock_InitTermOpenClose, 1);
	#endif   
/* now safe to lock semaphore */
    SEM_LOCK(Lock_InitTermOpenClose);
    DEMODInstance = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( D0299_InstanceData_t ));
    if (DEMODInstance == NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("%s fail memory allocation InstanceNew\n", identity));
#endif    
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_NO_MEMORY);           
    }
    DEMODInstance->DeviceName          = DeviceName;
    DEMODInstance->ExternalClock     = InitParams->ExternalClock;  
    DEMODInstance->TSOutputMode      = InitParams->TSOutputMode;
    DEMODInstance->SerialDataMode    = InitParams->SerialDataMode;
    DEMODInstance->MemoryPartition   = InitParams->MemoryPartition;
    #ifdef STTUNER_BLOCK_SYNC_MODE_SELECT
    DEMODInstance->BlockSyncMode     = InitParams->BlockSyncMode;/* add block sync bit control for bug GNBvd27452*/
    #endif
    DEMODInstance->SerialClockSource = InitParams->SerialClockSource;
    DEMODInstance->FECMode           = InitParams->FECMode;
    /********Added for Diseqc***************************/
    DEMODInstance->DiSEqCConfig.Command=STTUNER_DiSEqC_COMMAND;
    DEMODInstance->DiSEqCConfig.ToneState=STTUNER_DiSEqC_TONE_CONTINUOUS_OFF;
    /**************************************************/
    SEM_UNLOCK(Lock_InitTermOpenClose);
        
    #endif
    return(Error);
}   

/* ----------------------------------------------------------------------------
Name: demod_d0299_Term()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0299_Term(ST_DeviceName_t *DeviceName, DEMOD_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
   const char *identity = "STTUNER d0299.c demod_d0299_Term()";
#endif	 
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
    D0299_InstanceData_t *Instance, *InstancePrev, *InstanceNext;

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

    /* ---------- check that at least one init has taken place ---------- */
    if(InstanceChainTop == NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("%s fail nothing initalized\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(STTUNER_ERROR_INITSTATE);
    }

    /* reap next matching DeviceName */
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    STTBX_Print(("%s looking for first free handle[\n", identity));
#endif

    Instance = InstanceChainTop;
    while(1)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("(%s)", Instance->DeviceName));
#endif
        if ( strcmp( (char *)Instance->DeviceName, (char *)DeviceName) == 0)
        {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
            STTBX_Print(("]\n"));
#endif
            Error = STTUNER_IOREG_Close(&Instance->DeviceMap);
            if (Error != ST_NO_ERROR)
            {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
                STTBX_Print(("%s fail close register database\n", identity));
#endif
            }
            /* found so now xlink prev and next(if applicable) and deallocate memory */
            InstancePrev = Instance->InstanceChainPrev;
            InstanceNext = Instance->InstanceChainNext;

            /* if instance to delete is first in chain */
            if (Instance->InstanceChainPrev == NULL)
            {
                InstanceChainTop = InstanceNext;        /* which would be NULL if last block to be term'd */
                if (InstanceNext != NULL)
                {
                InstanceNext->InstanceChainPrev = NULL; /* now top of chain, no previous instance */

⌨️ 快捷键说明

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