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

📄 d0288.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
            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 */
                }
            }
            else
            {   /* safe to set value for prev instaance (because there IS one) */
                InstancePrev->InstanceChainNext = InstanceNext;
            }

            /* if there is a next block in the chain */            
            if (InstanceNext != NULL)
            {
                InstanceNext->InstanceChainPrev = InstancePrev;
            }   

            memory_deallocate(Instance->MemoryPartition, Instance);
	    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
            STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
	    #endif
	    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
            STTBX_Print(("%s terminated ok\n", identity));
            #endif
            SEM_UNLOCK(Lock_InitTermOpenClose);
            return(Error);
        }
        else if(Instance->InstanceChainNext == NULL) 
        {       /* error we should have found a matching name before the end of the list */
		#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
                STTBX_Print(("\n%s fail no free handle before end of list\n", identity));
		#endif
                SEM_UNLOCK(Lock_InitTermOpenClose);
                return(STTUNER_ERROR_INITSTATE);
        }
        else
        {
        	Instance = Instance->InstanceChainNext;   /* next block */
        }
        
    }


    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
    STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
    #endif
    SEM_UNLOCK(Lock_InitTermOpenClose);

    return(Error);
}   

/* ----------------------------------------------------------------------------
Name: demod_d0288_Open()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0288_Open(ST_DeviceName_t *DeviceName, DEMOD_OpenParams_t  *OpenParams, DEMOD_Capability_t *Capability, DEMOD_Handle_t *Handle)
{
    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
    const char *identity = "STTUNER d0288.c demod_d0288_Open()";
    #endif		   
    ST_ErrorCode_t Error = ST_NO_ERROR;
    
    U8 ChipID;
    
    D0288_InstanceData_t     *Instance;
    STTUNER_tuner_instance_t *TunerInstance;
    STTUNER_InstanceDbase_t  *Inst;

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

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

    /* ---------- check that at least one init has taken place ---------- */
    if(InstanceChainTop == NULL)
    {
	#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
        STTBX_Print(("%s fail nothing initalized\n", identity));
	#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(STTUNER_ERROR_INITSTATE);
    }
    /* find  handle from name */
    Instance = InstanceChainTop;
    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
    STTBX_Print(("%s looking (%s)", identity, Instance->DeviceName));
    #endif
    while(strcmp((char *)Instance->DeviceName, (char *)DeviceName) != 0)
    {
        /* error, should have found matching DeviceName before end of list */
        if(Instance->InstanceChainNext == NULL) 
        {       
	    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
            STTBX_Print(("\n%s fail no block named '%s' before end of list\n", identity, DeviceName));
            #endif
            SEM_UNLOCK(Lock_InitTermOpenClose);
            return(STTUNER_ERROR_INITSTATE);
        }
        Instance = Instance->InstanceChainNext;   /* next block */
	#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
        STTBX_Print(("(%s)", Instance->DeviceName));
	#endif
    }
    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
    STTBX_Print((" found ok\n"));
    #endif

    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
    STTBX_Print(("%s using block at 0x%08x\n", identity, (U32)Instance));
    #endif
    /* check handle IS actually free */
    if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
    {
        #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
        STTBX_Print(("%s fail driver instance already open\n", identity));
	#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_OPEN_HANDLE);
    }
    /* now got pointer to free (and valid) data block */
    Inst = STTUNER_GetDrvInst();    /* pointer to instance database */
   

    ChipID = STTUNER_IOREG_GetRegister(&Instance->DeviceMap, Instance->IOHandle, R288_ID);
#ifndef STTUNER_DRV_SAT_5188
    if ( (ChipID & 0xF0) !=  0x10)
    {
	#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
        STTBX_Print(("%s fail device not found (0x%02x)\n", identity, ChipID));
	#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_UNKNOWN_DEVICE);
    }
    else
    {
	#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
        STTBX_Print(("%s device found, release/revision=%u\n", identity, ChipID & 0x0F));
	#endif
    }
#endif

    /* reset all chip registers */
    Error = STTUNER_IOREG_Reset(&Instance->DeviceMap, Instance->IOHandle,Def288Val, Addressarray);
    
    if(((Inst[OpenParams->TopLevelHandle].Sat.Tuner.Driver->ID)==STTUNER_TUNER_STB6000) || ((Inst[OpenParams->TopLevelHandle].Sat.Tuner.Driver->ID)==STTUNER_TUNER_STB6100))
    {
	STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_IAGC,1);
    }
    else
    {
	STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_IAGC,0);	
    }

    /* Set MasterClock Freq */
   
    if (Error != ST_NO_ERROR)
    {
	#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
        STTBX_Print(("%s fail reset device\n", identity));
	#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);           
    } 
    /* Set capabilities */
    Capability->FECAvail         = STTUNER_FEC_1_2 | STTUNER_FEC_2_3 | STTUNER_FEC_3_4 |
                                   STTUNER_FEC_5_6 | STTUNER_FEC_6_7 | STTUNER_FEC_7_8;
    Capability->ModulationAvail  = STTUNER_MOD_ALL;  /* direct mapping to STTUNER_Modulation_t */
    Capability->AGCControl       = FALSE;
    Capability->SymbolMin        = STX0288_SYMBOL_RATE_MIN; /*   1 MegaSymbols/sec */
    Capability->SymbolMax        = STX0288_SYMBOL_RATE_MAX; /*  60 MegaSymbols/sec */
    Capability->BerMax           = MAX_BER; 
    Capability->SignalQualityMax = MAX_SIGNAL_QUALITY;
    Capability->AgcMax           = MAX_AGC;
    
    switch (Instance->TSOutputMode)
    {
        case STTUNER_TS_MODE_SERIAL:
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_OUTRS_PS, 1);
            break;

        default:
        case STTUNER_TS_MODE_PARALLEL:
        case STTUNER_TS_MODE_DEFAULT:
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_OUTRS_PS, 0);
            break;
    }

    /* Set FEC mode */
    switch (Instance->FECMode)
    {
        case STTUNER_FEC_MODE_DIRECTV:
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_FECMODE,0x04);
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_MODE_COEF, 1);/* Nyquist Filter, GNBvd31071*/
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_DESCRAM, 0);/* descrambler, GNBvd31071 */
	    /* Enable 2/3,6/7 and disable 1/2,3/4,5/6,7/8 */
	   STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_1_2,0);
	   STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_2_3,1);
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_3_4,0);
	   STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_5_6,0);
	   STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_6_7,1);
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_7_8,0);
	   
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_SWAP_ENABLE,0);
            break;

        default:
        case STTUNER_FEC_MODE_DEFAULT:
        case STTUNER_FEC_MODE_DVB:
       
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_FECMODE, 0);
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_MODE_COEF, 0);/* Nyquist Filter, GNBvd31071*/
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_DESCRAM, 1);/* descrambler, GNBvd31071 */
	    /* Enable 1/2,2/3,3/4,5/6,7/8 and disable 6/7*/
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_1_2,1);
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_2_3,1);
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_3_4,1);
	   STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_5_6,1);
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_6_7,0);
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_PR_7_8,1);
	    
	    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle,F288_SWAP_ENABLE,1);	/* enable automatic IQ invertion */
            break;
    }

    if (Instance->ClockPolarity == STTUNER_DATA_CLOCK_POLARITY_FALLING)    /* Rising Edge */
    {
        Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F288_CLK_POL, 1);
    }
    else
    {
        Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F288_CLK_POL, 0);
    }
        
    if (Instance->DataClockAtParityBytes == STTUNER_DATACLOCK_NULL_AT_PARITYBYTES)     /* Parity enable changes done for 5528 live decode issue*/
    {
        Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F288_CLK_CFG, 1);
    }
    else
    {
        Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F288_CLK_CFG, 0);
    }
    
    if(Instance->OutputFIFOConfig.OutputRateCompensationMode == STTUNER_COMPENSATE_DATAVALID)
    {
   	Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F288_EN_STBACKEND,    0);
    }
    else if(Instance->OutputFIFOConfig.OutputRateCompensationMode == STTUNER_COMPENSATE_DATACLOCK)
    {
   	Error |= STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F288_EN_STBACKEND,    1);
    }
    
   /* This will control sync byte, 0x47 or 0xb8 after every 8th packet*/
    switch(Instance->BlockSyncMode)
    { case STTUNER_SYNC_NORMAL:
           STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_MPEG, 0);
           break;
      case STTUNER_SYNC_DEFAULT:
      case STTUNER_SYNC_FORCED:
           STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_MPEG, 1);
           break;
       default:
           STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_MPEG, 1);
            break;
     }
         
    /* Set default error count mode i.e., QPSK bit error rate */
    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_ERRMODE,   0);
    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_ERR_SOURCE, 0);
    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_NOE,         3);

    TunerInstance = &Inst[OpenParams->TopLevelHandle].Sat.Tuner; /* pointer to tuner for this instance */

    if(TunerInstance->Driver->ID == STTUNER_TUNER_STB6000)
    {
        STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_IAGC, 1);
	#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
        STTBX_Print(("%s setup for EVALMAX F0288_IAGC=1\n", identity));
	#endif
    }
    else
    {
        STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F288_IAGC, 0);
	#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
        STTBX_Print(("%s no EVALMAX tuner driver, F288_IAGC=0\n", identity));
	#endif
    }

    /* finally (as nor more errors to check for, allocate handle */
    Instance->TopLevelHandle = OpenParams->TopLevelHandle;
    #ifdef STTUNER_LNB_POWER_THRU_DEMODIO
    Inst[OpenParams->TopLevelHandle].Sat.Demod.DeviceMap = &Instance->DeviceMap;
    Inst[OpenParams->TopLevelHandle].Sat.Demod.TEN_FieldIndex = F288_IOP3_CFG;
    Inst[OpenParams->TopLevelHandle].Sat.Demod.VEN_FieldIndex = F288_IOP4_CFG;
    Inst[OpenParams->TopLevelHandle].Sat.Demod.VSEL_FieldIndex= F288_IOP5_CFG;
    #endif
    #ifdef STTUNER_LNB_TONE_THRU_DEMOD_DISEQC_PIN
    Inst[OpenParams->TopLevelHandle].Sat.Demod.DeviceMap = &Instance->DeviceMap;
    Inst[OpenParams->TopLevelHandle].Sat.Demod.TEN_FieldIndex = F288_DISEQC_MODE;
    #endif
    /* in loopthriugh mode the second demod which is connected by loopthrough of first cannot send disecq-st 
       command because of a DC block in the loop-through path. Presently it depends upon toplevelhandle but when tone detection 
       LLA of SatCR will be written "DISECQ_ST_ENABLE" will be initalized automatically depending upon the tone sent*/
    #ifdef STTUNER_DRV_SAT_SCR
		#ifdef STTUNER_DRV_SAT_SCR_LOOPTHROUGH
		    if(OpenParams->TopLevelHandle == 0)
		    Instance->DISECQ_ST_ENABLE = TRUE;
		    if(OpenParams->TopLevelHandle == 1)
		    Instance->DISECQ_ST_ENABLE = FALSE;
	        #endif
	#endif
    
    *Handle = (U32)Instance;
    /*Error |= demod_d0288_DiseqcInit(*Handle);*/
    #ifdef STTUNER_DEBUG_MODULE_SATDRV_D0288
    STTBX_Print(("%s opened ok\n", identity));
    #endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
    /* GNBvd17801-> Error Handling for any error returned during I2C operation inside the driver */
    Error |= Instance->DeviceMap.Error;
    Instance->DeviceMap.Error = ST_NO_ERROR;
    return(Error);
}   

/* ----------------------------------------------------------------------------
Name: demod_d0288_Close()

Description:

⌨️ 快捷键说明

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