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

📄 d0299.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
                }
            }
            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_D0299
            STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif

#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
            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_D0299
                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_D0299
    STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
    #endif
/*********************************MINIDRIVER*********************
****************************************************************
**********************************************************************/    
#ifdef STTUNER_MINIDRIVER
    
     /* now safe to lock semaphore */
    SEM_LOCK(Lock_InitTermOpenClose);

    memory_deallocate(DEMODInstance->MemoryPartition, DEMODInstance);

    SEM_UNLOCK(Lock_InitTermOpenClose);
	    #if defined(ST_OS21) || defined(ST_OSLINUX)
	    semaphore_delete(Lock_InitTermOpenClose);
	    #else
	    semaphore_delete(&Lock_InitTermOpenClose);
	    #endif 
    
#endif
    return(Error);
}   



/* ----------------------------------------------------------------------------
Name: demod_d0299_Open()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0299_Open(ST_DeviceName_t *DeviceName, DEMOD_OpenParams_t  *OpenParams, DEMOD_Capability_t *Capability, DEMOD_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
   const char *identity = "STTUNER d0299.c demod_d0299_Open()";
#endif		   
ST_ErrorCode_t Error = ST_NO_ERROR;
    
#ifndef STTUNER_MINIDRIVER
    U8 ChipID;
    unsigned char ResetValue;
    D0299_InstanceData_t     *Instance;
    STTUNER_tuner_instance_t *TunerInstance;
    STTUNER_InstanceDbase_t  *Inst;
     

    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 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);
    }

    /* find  handle from name */
    Instance = InstanceChainTop;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    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_D0299
            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_D0299
        STTBX_Print(("(%s)", Instance->DeviceName));
#endif
    }
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print((" found ok\n"));
#endif

#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
    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_D0299
        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 */

    /* wake up chip if in standby */
    
    Error = STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle, R0299_MCR, 0x00); /*reset value =0x00*/
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        STTBX_Print(("%s fail wake device\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);           
    }

    /* check to see if chip is of the expected type, this is done afer register setup with
    reset values because the standby/sleep mode may have been done and  Reg0299_Reset() wakes
    the device up (depending on the polarity of the STDBY pin - see STV0299 data sheet */
    ChipID = STTUNER_IOREG_GetRegister(&Instance->DeviceMap, Instance->IOHandle, R0299_ID);
    
    if ( (ChipID & 0xF0) !=  0xA0)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        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_D0299
        STTBX_Print(("%s device found, release/revision=%u\n", identity, ChipID & 0x0F));
#endif
    }
    /* reset all chip registers */
    Error!= STTUNER_IOREG_Reset(&Instance->DeviceMap, Instance->IOHandle, STV0299_DefVal, STV0299_Address);

  /* change resetvalues if the board contains DSF8910*/       
if((Inst[OpenParams->TopLevelHandle].Sat.Tuner.Driver->ID)==STTUNER_TUNER_DSF8910)
{ 
				
	Error != STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle,  R0299_I2CRPT, 0x35);
	Error != STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle,  R0299_RTC, 0x22);
	Error != STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle,  R0299_AGC1R, 0xd9);
	Error != STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle,  R0299_AGC2O, 0x3e);
	Error != STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle,  R0299_ACLC, 0x88);
	Error != STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle,  R0299_BCLC, 0x95);
	
	
} 
 
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
        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       = STV0299_SYMBOL_RATE_MIN; /*   1 MegaSymbols/sec */
    Capability->SymbolMax       = STV0299_SYMBOL_RATE_MAX; /*  50 MegaSymbols/sec */

    Capability->BerMax           = MAX_BER; 
    Capability->SignalQualityMax = MAX_SIGNAL_QUALITY;
    Capability->AgcMax           = MAX_AGC;

    /* Setup stateblock */
    Instance->StateBlock.ScanMode     = DEF0299_CHANNEL;
    Instance->StateBlock.lastAGC2Coef =  1;
    #ifdef STTUNER_LNB_POWER_THRU_DEMODIO
	    Inst[OpenParams->TopLevelHandle].Sat.Demod.DeviceMap = &Instance->DeviceMap;
	    #ifdef STTUNER_LNB_TONE_THRU_DEMOD_DISEQC_PIN
	    Inst[OpenParams->TopLevelHandle].Sat.Demod.TEN_FieldIndex = F0299_DISEQCMODE;
	    #else
	    Inst[OpenParams->TopLevelHandle].Sat.Demod.TEN_FieldIndex = F0299_OP0VALUE;
	    #endif
	    Inst[OpenParams->TopLevelHandle].Sat.Demod.VEN_FieldIndex = F0299_OP1VALUE;
	    Inst[OpenParams->TopLevelHandle].Sat.Demod.VSEL_FieldIndex= F0299_LOCKOUTPUT;
    #endif
    /* make sure trigger facilities are off because it is not used for production and
      is not very nice anyway if you want to actually use the DAC 
     Reg0299_RegSetTrigger(&Instance->DeviceMap, IOREG_NO);*/

    /* TS output mode */
    switch (Instance->TSOutputMode)
    {
        case STTUNER_TS_MODE_SERIAL:
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_OUTPUTTYPE, 1);
            break;

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

    /* Set FEC mode */
    switch (Instance->FECMode)
    {
        case STTUNER_FEC_MODE_DIRECTV:
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_FECMODE, 4);
			STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_NYQUISTFILTER, 1);/* Nyquist Filter, GNBvd31071*/
			STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_DESCRAMBLER, 0);/* descrambler, GNBvd31071 */
            break;

        default:
        case STTUNER_FEC_MODE_DEFAULT:
        case STTUNER_FEC_MODE_DVB:
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_FECMODE, 0);
            break;
    }

    /* Only set serial configuration if serial mode output */
    if (Instance->TSOutputMode == STTUNER_TS_MODE_SERIAL)
    {
        /* Set serial clock source */
        switch(Instance->SerialClockSource)
        {
            case STTUNER_SCLK_VCODIV6:
                STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_SERCLK, 1);
                break;

            default:
            case STTUNER_SCLK_DEFAULT:
            case STTUNER_SCLK_MASTER:
                STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_SERCLK, 0);
                break;
        }

        /* Set serial data mode */
        
        if ( (Instance->SerialDataMode & STTUNER_SDAT_VALID_RISING) != 0)    /* Rising edge according to 299 data sheet*/
        {
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_OUTPUTCLOCKPOLARITY, 0);  
        }
        else
        {
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_OUTPUTCLOCKPOLARITY, 1);
        }

        if ((Instance->SerialDataMode & STTUNER_SDAT_PARITY_ENABLE) != 0)     /* Parity enable according to 299 data sheet */
        {
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_OUTPUTCLOCKCONFIG, 0);
        }
        else
        {
            STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_OUTPUTCLOCKCONFIG, 1);
        }

    } /* if(OpenParams->TSOutputMode) */

   /* This will control sync byte, 0x47 or 0xb8 after every 8th packet*/
   #ifdef STTUNER_BLOCK_SYNC_MODE_SELECT
    switch(Instance->BlockSyncMode)
    { case STTUNER_SYNC_NORMAL:
           STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_BLOCKSYNCHRO, 0);
           break;
      case STTUNER_SYNC_DEFAULT:
      case STTUNER_SYNC_FORCED:
           STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_BLOCKSYNCHRO, 1);
           break;
       default:
           STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_BLOCKSYNCHRO, 1);
            break;
     }
     #endif
   
    
    /* Set default error count mode i.e., QPSK bit error rate */
    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_ERRORMODE,   0);
    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_ERRORSOURCE, 0);
    STTUNER_IOREG_SetField(&Instance->DeviceMap, Instance->IOHandle, F0299_NOE,         3);


    /* if an EVALMAX is connected to this stv0299 then the stv0299 IAGC field needs
     to be set to one else zero it */
    TunerInstance = &Inst[OpenParams->TopLevelHandle].Sat.Tuner; /* pointer to tuner for this instance */

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


⌨️ 快捷键说明

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