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

📄 d0361.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:









 

    /* indicate instance is closed */
    Instance->TopLevelHandle = STTUNER_MAX_HANDLES;

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
    STTBX_Print(("%s closed\n", identity));
#endif

    SEM_UNLOCK(Lock_InitTermOpenClose);
    return(Error);
}


/* ----------------------------------------------------------------------------
Name: demod_d0361_GetTunerInfo()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0361_GetTunerInfo(DEMOD_Handle_t Handle, STTUNER_TunerInfo_t *TunerInfo_p)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
   const char *identity = "STTUNER d0361.c demod_d0361_GetTunerInfo()";
#endif
    ST_ErrorCode_t       Error = ST_NO_ERROR;
    ST_ErrorCode_t       TunerError ;
    D0361_InstanceData_t *Instance;
    STTUNER_InstanceDbase_t     *Inst;
    U8                   Data;
    U32                  CurFrequency, CurSignalQuality, CurBitErrorRate;
    STTUNER_Modulation_t CurModulation;
    STTUNER_Mode_t       CurMode;
    STTUNER_FECRate_t    CurFECRates;
    STTUNER_Guard_t      CurGuard;
    STTUNER_Spectrum_t   CurSpectrum;
    STTUNER_Hierarchy_t  CurHierMode;
    S32                  CurEchoPos;
      
    
    int offset=0;
    int offsetvar=0;
    char signvalue=0;
    int offset_type=0;
    /* private driver instance data */
    Instance = D0361_GetInstFromHandle(Handle);
    
    /* top level public instance data */
    Inst = STTUNER_GetDrvInst();
  
    /* Read noise estimations for C/N and BER */
   
    FE_361_GetNoiseEstimator(&(Instance->DeviceMap), Instance->IOHandle, &CurSignalQuality, &CurBitErrorRate);

	
  /******The Error field of TunerInfo in Instaneous database is updated ******/
    
    TunerError= ST_NO_ERROR; 
       
    /*************************************************************************/
    /* Get the modulation type */
     #ifndef ST_OSLINUX
    task_lock();
    #ifdef PROCESSOR_C1 /***For C1 core this delay needed otherwise STTUNER_task_lock(); not working fine ****/ 
    task_delay(5);
    #endif
    #endif
     Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_CONST);

        
     #ifndef ST_OSLINUX
    task_unlock();
    #endif
   /* Data = ChipGetFieldImage(FE2CHIP(Instance->FE_360_Handle), TPS_CONST);*/
    switch (Data)
    {
        case 0:  CurModulation = STTUNER_MOD_QPSK;  break;
        case 1:  CurModulation = STTUNER_MOD_16QAM; break;
        case 2:  CurModulation = STTUNER_MOD_64QAM; break;
        default: 
        /*CurModulation = STTUNER_MOD_ALL;*/
        CurModulation = Data ;
        task_delay(5);
         Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_CONST);

        switch (Data)
        {
        case 0:  CurModulation = STTUNER_MOD_QPSK;  break;
        case 1:  CurModulation = STTUNER_MOD_16QAM; break;
        case 2:  CurModulation = STTUNER_MOD_64QAM; break;
        default:
        CurModulation = Data ;
        TunerError=ST_ERROR_BAD_PARAMETER;
        }
        break;
    }

    /* Get the mode */
     #ifndef ST_OSLINUX
     task_lock();
    #ifdef PROCESSOR_C1 /***For C1 core this delay needed otherwise STTUNER_task_lock(); not working fine ****/ 
    task_delay(5);
    #endif
    #endif
    Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_MODE);

    #ifndef ST_OSLINUX
     task_unlock();
    #endif
    /*Data = ChipGetFieldImage(FE2CHIP(Instance->FE_360_Handle), TPS_MODE);*/
    switch (Data)
    {
        case 0:  CurMode = STTUNER_MODE_2K; break;
        case 1:  CurMode = STTUNER_MODE_8K; break;
        default: 
        CurMode =Data;
        task_delay(5);
          Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_MODE);

        switch (Data)
        {
        case 0:  CurMode = STTUNER_MODE_2K; break;
        case 1:  CurMode = STTUNER_MODE_8K; break;
        default:
        CurMode =Data;
        TunerError=ST_ERROR_BAD_PARAMETER;
        }
        break; /* error */
    }

    /* Get the Hierarchical Mode */
        
     #ifndef ST_OSLINUX
     task_lock();
    #ifdef PROCESSOR_C1 /***For C1 core this delay needed otherwise STTUNER_task_lock(); not working fine ****/ 
    task_delay(5);
    #endif
    #endif
    Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_HIERMODE);

     #ifndef ST_OSLINUX
     task_unlock();
    #endif
    switch(Data)
    {
    	case 0 : CurHierMode=STTUNER_HIER_ALPHA_NONE; break;
    	case 1 : CurHierMode=STTUNER_HIER_ALPHA_1; break;
    	case 2 : CurHierMode=STTUNER_HIER_ALPHA_2; break;
    	case 3 : CurHierMode=STTUNER_HIER_ALPHA_4; break;
    	default :
    	CurHierMode=Data;
    	TunerError=ST_ERROR_BAD_PARAMETER;
        break; /* error */
    }
    
     /* Get the FEC Rate */
   
     #ifndef ST_OSLINUX
    task_lock();
    #ifdef PROCESSOR_C1 /***For C1 core this delay needed otherwise STTUNER_task_lock(); not working fine ****/ 
    task_delay(5);
    #endif
    #endif
   if((Instance->Result).hier==STTUNER_HIER_LOW_PRIO)
    {
       
       Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_LPCODE);

    }
    else
    {
    Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_HPCODE);
    }
        
     #ifndef ST_OSLINUX
     task_unlock();
    #endif
    switch (Data)
    {
        case 0:  CurFECRates = STTUNER_FEC_1_2; break;
        case 1:  CurFECRates = STTUNER_FEC_2_3; break;
        case 2:  CurFECRates = STTUNER_FEC_3_4; break;
        case 3:  CurFECRates = STTUNER_FEC_5_6; break;
        case 4:  CurFECRates = STTUNER_FEC_7_8; break;
        default: 
        CurFECRates = Data;
        TunerError=ST_ERROR_BAD_PARAMETER;
        break; /* error */
    }

    /* Get the Guard time */
     #ifndef ST_OSLINUX
    task_lock();
    
    #ifdef PROCESSOR_C1 /***For C1 core this delay needed otherwise STTUNER_task_lock(); not working fine ****/ 
    task_delay(5);
    #endif
    #endif
    Data = STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_GUARD);
     #ifndef ST_OSLINUX
    task_unlock();
    #endif
    switch (Data)
    {
        case 0:  CurGuard = STTUNER_GUARD_1_32; break;
        case 1:  CurGuard = STTUNER_GUARD_1_16; break;
        case 2:  CurGuard = STTUNER_GUARD_1_8;  break;
        case 3:  CurGuard = STTUNER_GUARD_1_4;  break;
        default: 
        CurGuard = Data;
        TunerError=ST_ERROR_BAD_PARAMETER;
        break; /* error */
    }

    /* Get the spectrum sense */
    Data = STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, INV_SPECTR);

    switch (Data)
    {
        case 0:  CurSpectrum = STTUNER_INVERSION;      break;
        default: CurSpectrum = STTUNER_INVERSION_NONE; break;
    }

    /* Get the correct frequency */
    CurFrequency = TunerInfo_p->Frequency;
    
/***********************/

 /********Frequency offset calculation done here*******************/
    signvalue=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle,SEXT);
    
    offset=STTUNER_IOREG_GetRegister(&(Instance->DeviceMap), Instance->IOHandle, R_CRL_FREQ3);
    offset <<=16;
    
    offsetvar=STTUNER_IOREG_GetRegister(&(Instance->DeviceMap), Instance->IOHandle, R_CRL_FREQ2);
    offsetvar <<=8;
    offset = offset | offsetvar;
    offsetvar=0;
    offsetvar=STTUNER_IOREG_GetRegister(&(Instance->DeviceMap), Instance->IOHandle,R_CRL_FREQ1);
    offset =offset | offsetvar ;
    if(signvalue==1)
    {
       offset |=0xff000000;/*** Here sign extension made for the negative number**/
    }
       offset =offset /16384;/***offset calculation done according to data sheet of STV0360***/
       /*Data = STTUNER_IOREG_FieldGetVal(&(Instance->DeviceMap),TPS_MODE);*/
       Data = STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle,TPS_MODE);
       if(Data==0)
       {
          /*******it is 2k mode***************/
          offset=((offset*4464)/1000);/*** 1 FFT BIN=4.464khz***/
       }
       else
       {
          /*******it is 8k mode***************/
          offset=((offset*11)/10);/*** 1 FFT BIN=1.1khz***/
       }
       offset= offset*2; /*** In 361 actual offset shown is half***/
       /*********** Spectrum Inversion Taken Care**************/
       Data = STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle,INV_SPECTR);
       if((offset>=140) && (offset<=180))
       {
       	 offset -=166;





/***************/

       	 if(Data ==0)
       	 {
       	    offset_type =STTUNER_OFFSET_POSITIVE;   
       	 }
       	 else
       	 {
              offset_type =STTUNER_OFFSET_NEGATIVE;
          }   
       }
        else if((offset<=-140) && (offset>=-180))
       {
       	 offset +=166;


       	 if(Data==0)
       	 {
             offset_type =STTUNER_OFFSET_NEGATIVE;
          }
          else
          {
             offset_type =STTUNER_OFFSET_POSITIVE;
          }
       }
       else
       {
       	 

       	 offset_type=STTUNER_OFFSET_NONE;
       }
       
      


       TunerInfo_p->ScanInfo.FreqOff = offset_type;
       
          if(Data==0)
       {
          TunerInfo_p->ScanInfo.ResidualOffset = offset;
       }
       else
       {
           TunerInfo_p->ScanInfo.ResidualOffset = offset*(-1);
       }

     
    /************************************************/

    /* Get the echo position */
     CurEchoPos=STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, LONG_ECHO);


     #ifndef ST_OSLINUX
     task_lock();
    
    #ifdef PROCESSOR_C1 /***For C1 core this delay needed otherwise STTUNER_task_lock(); not working fine ****/ 
    task_delay(5);
    #endif
    #endif
    TunerInfo_p->FrequencyFound      = CurFrequency;
    TunerInfo_p->SignalQuality       = CurSignalQuality;
    TunerInfo_p->BitErrorRate        = CurBitErrorRate;
    TunerInfo_p->ScanInfo.Modulation = CurModulation;
    TunerInfo_p->ScanInfo.Mode       = CurMode;
    TunerInfo_p->ScanInfo.FECRates   = CurFECRates;
    TunerInfo_p->ScanInfo.Guard      = CurGuard;
    TunerInfo_p->ScanInfo.Spectrum   = CurSpectrum;
    TunerInfo_p->ScanInfo.EchoPos    = CurEchoPos;
    TunerInfo_p->Hierarchy_Alpha     = CurHierMode;
    Inst[Instance->TopLevelHandle].TunerInfoError = TunerError;
     TunerInfo_p->ScanInfo.Hierarchy =    (Instance->Result).hier;
     #ifndef ST_OSLINUX
     task_unlock();
    #endif
  
 #ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
    STTBX_Print(("F=%d SQ=%u BER=%u Modul=%u Mode=%u FR=%u G=%u Sp=%u\n",CurFrequency,CurSignalQuality,CurBitErrorRate,CurModulation,CurMode,CurFECRates,CurGuard,CurSpectrum));
 #endif
    
    


    return(Error);
}



/* ----------------------------------------------------------------------------
Name: demod_d0361_GetSignalQuality()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0361_GetSignalQuality(DEMOD_Handle_t Handle, U32  *SignalQuality_p, U32 *Ber)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
   const char *identity = "STTUNER d0361.c demod_d0361_GetSignalQuality()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0361_InstanceData_t *Instance;

    /* private driver instance data */
    Instance = D0361_GetInstFromHandle(Handle);

    /* Read noise estimations for C/N and BER */
     FE_361_GetNoiseEstimator(&(Instance->DeviceMap), Instance->IOHandle, SignalQuality_p, Ber);


#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
    STTBX_Print(("%s SignalQuality=%u Ber=%u\n", identity, *SignalQuality_p, *Ber));
#endif
     Error = Instance->DeviceMap.Error;

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: demod_d0361_GetModulation()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0361_GetModulation(DEMOD_Handle_t Handle, STTUNER_Modulation_t *Modulation)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
   const char *identity = "STTUNER d0361.c demod_d0361_GetModulation()";
#endif
    U32 Data;
    STTUNER_Modulation_t CurModulation;
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0361_InstanceData_t *Instance;

    /* private driver instance data */
    Instance = D0361_GetInstFromHandle(Handle);

    /* Get the modulation type */
   /*Use IOREG Call instead of chip call */
    STTUNER_IOREG_GetField(&(Instance->DeviceMap), Instance->IOHandle, TPS_CONST);
   
Data = STTUNER_IOREG_GetField(&(Instance->DeviceMap),Instance->IOHandle, TPS_CONST);

    switch (Data)
    {
        case 0:
            CurModulation = STTUNER_MOD_QPSK;
            break;

        case 1:
            CurModulation = STTUNER_MOD_16QAM;
            break;

        case 2:
            CurModulation = STTUNER_MOD_64QAM;
            break;

        default:
            CurModulation = STTUNER_MOD_ALL;
            break;
    }

    *Modulation = CurModulation;

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
    STTBX_Print(("%s Modulation=%u\n", identity, *Modulation));
#endif
   


    return(Error);
}



/* ----------------------------------------------------------------------------
Name: demod_d0361_GetMode()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0361_GetMode(DEMOD_Handle_t Handle, STTUNER_Mode_t *Mode)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
   const char *identity = "STTUNER d0361.c demod_d0361_GetMode()";
#endif
    U8 Data;
    STTUNER_Mode_t CurMode;
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0361_InstanceData_t *Instance;

    /* private driver instance data */
    Instance = D0361_GetInstFromHandle(Handle);

    /* Get the mode type */
    
      Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap),Instance->IOHandle,TPS_MODE);
   

    switch (Data)
    {
        case 0:
            CurMode = STTUNER_MODE_2K;
            break;

        case 1:
            CurMode = STTUNER_MODE_8K;
            break;

        default:
            CurMode = 0xff; /* error */
            break;
    }

    *Mode = CurMode;

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0361
    STTBX_Print(("%s Mode=%

⌨️ 快捷键说明

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