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

📄 lnbio.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb_demodIO_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;
    #ifndef STTUNER_MINIDRIVER
    LNB_DemodIO_InstanceData_t     *Instance;
    STTUNER_demod_instance_t *DemodInstance;
    STTUNER_InstanceDbase_t  *Inst;
    
    if(Installed == FALSE)
    {
	return(STTUNER_ERROR_INITSTATE);
    }
    Inst = STTUNER_GetDrvInst();
    /* now safe to lock semaphore */
    SEM_LOCK(Lock_InitTermOpenClose);
    /* ---------- check that at least one init has taken place ---------- */
    if(InstanceChainTop == NULL)
    {
	SEM_UNLOCK(Lock_InitTermOpenClose);
        return(STTUNER_ERROR_INITSTATE);
    }
    /* find  handle from name */
    Instance = InstanceChainTop;

    while(strcmp((char *)Instance->DeviceName, (char *)DeviceName) != 0)
    {
        /* error, should have found matching DeviceName before end of list */
        if(Instance->InstanceChainNext == NULL)
        {
	    SEM_UNLOCK(Lock_InitTermOpenClose);
            return(STTUNER_ERROR_INITSTATE);
        }
        Instance = Instance->InstanceChainNext;   /* next block */

    }
    if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
    {
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_OPEN_HANDLE);
    }
    /* this LNB driver is only for use with an STV0299 demod */
    Inst = STTUNER_GetDrvInst();    /* pointer to instance database */
    /* pointer to **OPENED** demod for this instance */
    DemodInstance = &Inst[OpenParams->TopLevelHandle].Sat.Demod;
    
    /* Set LNB capabilties */
    Capability->ShortCircuitDetect = FALSE;  /* lie (rewrite to get pwr status using stv0299 i/o pin etc.) */
    Capability->PowerAvailable     = TRUE;
    Capability->PolarizationSelect = STTUNER_PLR_ALL;
    
    /* Set latest configuration */
    Instance->Config.Status    = LNB_STATUS_OFF;
    Instance->Config.Polarization = STTUNER_LNB_OFF;
    
    Instance->Config.ToneState = STTUNER_LNB_TONE_OFF;
    #ifdef STTUNER_BASIC
    if((Inst[OpenParams->TopLevelHandle].Sat.Tuner.Driver->ID)==STTUNER_TUNER_DSF8910)
    {
      Instance->Config.LNBPowerControl  = STTUNER_LNB_POWER_DemodDACPin;
      Instance->Config.ToneSourceControl  = STTUNER_22KHz_TONE_DemodDiseqcPin;
      LNB_DemodIO_SetTone_Demod(DemodInstance, 0);  /*LNB Tone OFF*/
      LNB_DemodIO_Set_DACPower(DemodInstance, Instance->Config.Status);/*set LNB power 18V*/
    }
    else
    {
    #endif
	    Instance->Config.ToneSourceControl  = STTUNER_22KHz_TONE_DemodOP0Pin;
	    Instance->Config.LNBPowerControl    = STTUNER_LNB_POWER_LNBPDefault;
	    LNB_DemodIO_SetLnb(DemodInstance, 0);/* LNB tone off */
	    LNB_DemodIO_SetPower(DemodInstance, Instance->Config.Status);/*LNB power on*/
    #ifdef STTUNER_BASIC
    }
    #endif
    /* wait 500uS (0.5mS) then get power status */
    UTIL_Delay(500);
    Error = LNB_DemodIO_GetPower(DemodInstance, &Instance->Config.Status);

    if (Error == ST_NO_ERROR)   /* last i/o (above) operation was good */
    {
        if (Instance->Config.Status == LNB_STATUS_SHORT_CIRCUIT)
        {
            SEM_UNLOCK(Lock_InitTermOpenClose);
            return(STTUNER_ERROR_HWFAIL);
        }
    }
    else
    {
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }


    Instance->TopLevelHandle = OpenParams->TopLevelHandle;  /* mark as valid */
     /* In loopthrough mode 13 to 18V transition for DiSEQC-ST command should be on first demod */
    #ifdef STTUNER_BASIC
    #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
    #endif
    *Handle = (U32)Instance;

    SEM_UNLOCK(Lock_InitTermOpenClose);
    #endif
    
    #ifdef STTUNER_MINIDRIVER
     /* Set latest configuration */
    LNBInstance->Config.Status    = LNB_STATUS_ON;
    LNBInstance->Config.ToneState = STTUNER_LNB_TONE_OFF;
    LNBInstance->Config.Polarization = STTUNER_PLR_HORIZONTAL;/* set default pol->Horizontal*/
    
    LNBInstance->Config.ToneSourceControl  = STTUNER_22KHz_TONE_DemodOP0Pin;
    LNBInstance->Config.LNBPowerControl    = STTUNER_LNB_POWER_LNBPDefault;
    LNB_DemodIO_SetLnb(0);/* LNB tone off */
    LNB_DemodIO_SetPower(LNBInstance->Config.Status);/*LNB power on*/
    LNB_DemodIO_SetPolarization(STTUNER_PLR_HORIZONTAL);
    *Handle = (U32)LNBInstance;
    #endif
    return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_lnb_demodIO_Close()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb_demodIO_Close(LNB_Handle_t Handle, LNB_CloseParams_t *CloseParams)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;
    #ifndef STTUNER_MINIDRIVER
    LNB_DemodIO_InstanceData_t     *Instance;
    Instance = (LNB_DemodIO_InstanceData_t *)Handle;

    if(Installed == FALSE)
    {
        return(STTUNER_ERROR_INITSTATE);
    }

    SEM_LOCK(Lock_InitTermOpenClose);

    /* ---------- check that at least one init has taken place ---------- */
    if(InstanceChainTop == NULL)
    {
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(STTUNER_ERROR_INITSTATE);
    }

    if(Instance->TopLevelHandle == STTUNER_MAX_HANDLES)
    {
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_OPEN_HANDLE);
    }

    Instance->TopLevelHandle = STTUNER_MAX_HANDLES;

    SEM_UNLOCK(Lock_InitTermOpenClose);
    #endif
    #ifdef STTUNER_MINIDRIVER
    LNBInstance->TopLevelHandle = STTUNER_MAX_HANDLES;
    #endif
    return(Error);
}

/* ----------------------------------------------------------------------------
Name: lnb_lnb_demodIO_overloadcheck()

Description:
    Dummy Function
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */

ST_ErrorCode_t lnb_lnb_demodIO_overloadcheck(LNB_Handle_t Handle, BOOL  *IsOverTemp, BOOL *IsCurrentOvrLoad)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;
    return(Error);
}

/* ----------------------------------------------------------------------------
Name: lnb_lnb_demodIO_setttxmode()

Description:
    Dummy Function
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */

ST_ErrorCode_t lnb_lnb_demodIO_setttxmode(LNB_Handle_t Handle, STTUNER_LnbTTxMode_t Ttxmode)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;
    return(Error);
}

/* ----------------------------------------------------------------------------
Name: lnb_lnb_demodIO_GetConfig()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb_demodIO_GetConfig(LNB_Handle_t Handle, LNB_Config_t *Config)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;
    #ifndef STTUNER_MINIDRIVER
    LNB_DemodIO_InstanceData_t     *Instance;

    Instance = (LNB_DemodIO_InstanceData_t *)Handle;

    Config->Status       = Instance->Config.Status;
    Config->Polarization = Instance->Config.Polarization;
    Config->ToneState    = Instance->Config.ToneState;

    #endif
    
    #ifdef STTUNER_MINIDRIVER
	    Config->Status       = LNBInstance->Config.Status;
	    Config->Polarization = LNBInstance->Config.Polarization;
	    Config->ToneState    = LNBInstance->Config.ToneState;
    #endif
    return(Error);
}

/* ----------------------------------------------------------------------------
Name: lnb_lnb_demodIO_SetConfig()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb_demodIO_SetConfig(LNB_Handle_t Handle, LNB_Config_t *Config)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;
    #ifndef STTUNER_MINIDRIVER
    LNB_DemodIO_InstanceData_t     *Instance;
    STTUNER_demod_instance_t *DemodInstance;
    STTUNER_InstanceDbase_t  *Inst;
    Instance = (LNB_DemodIO_InstanceData_t *)Handle;
    Inst = STTUNER_GetDrvInst(); 
    DemodInstance = &Inst[Instance->TopLevelHandle].Sat.Demod;
    #ifdef STTUNER_BASIC
    #ifdef STTUNER_DRV_SAT_SCR
		#ifdef STTUNER_DRV_SAT_SCR_LOOPTHROUGH
		    if(Instance->DISECQ_ST_ENABLE == FALSE)
		    {
			    /*Error = FE_399_SetPower(Instance->FE_399_Handle, LNB_STATUS_OFF);*/  /* Make LNB power off of second NIM because of no use */
			    Handle = LnbDrvHandleOne;
			    Instance = (LNB_DemodIO_InstanceData_t *)Handle;
		    }
		#endif
	#endif
	#endif
    /* Select LNB band */
    
    if(Instance->Config.ToneState != Config->ToneState)
      {
	    switch(Instance->Config.ToneSourceControl)
        {
	    case STTUNER_22KHz_TONE_DemodOP0Pin:
          
	    switch (Config->ToneState)
        
	    {
			case STTUNER_LNB_TONE_OFF:      /* No tone */
			LNB_DemodIO_SetLnb(DemodInstance, 0);
			break;

			case STTUNER_LNB_TONE_22KHZ:    /* 22KHz tone */
			LNB_DemodIO_SetLnb(DemodInstance, 1);
			break;

			case STTUNER_LNB_TONE_DEFAULT:  /* no change */
			break;

			default:
			return(ST_ERROR_BAD_PARAMETER);
        }
        break;
        
        case STTUNER_22KHz_TONE_DemodDiseqcPin:
        switch (Config->ToneState)
        
	    {
			case STTUNER_LNB_TONE_OFF:      /* No tone */
			LNB_DemodIO_SetTone_Demod(DemodInstance, 0);
			break;

			case STTUNER_LNB_TONE_22KHZ:    /* 22KHz tone */
			LNB_DemodIO_SetTone_Demod(DemodInstance, 1);
			break;

			case STTUNER_LNB_TONE_DEFAULT:  /* no change */
			break;

			default:
			return(ST_ERROR_BAD_PARAMETER);
        }
             
        break; 
        default:
        break;    

      }
        
        Instance->Config.ToneState = Config->ToneState;
    }


    /* Select polarization */
    if (Instance->Config.Polarization != Config->Polarization)
    {
        switch(Instance->Config.LNBPowerControl)
        {
	        case  STTUNER_LNB_POWER_LNBPDefault:
	        
	    	switch (Config->Polarization)
			{
				case STTUNER_PLR_VERTICAL:      /* OP_2 controls -- 18V (high) */
				LNB_DemodIO_SetPolarization(DemodInstance, VERTICAL);
				break;

				case STTUNER_PLR_HORIZONTAL:    /* OP_2 controls -- 13V (low) */
				LNB_DemodIO_SetPolarization(DemodInstance, HORIZONTAL);
				break;
				
				case STTUNER_LNB_OFF:
				LNB_DemodIO_SetPolarization(DemodInstance, NOPOLARIZATION);
				break;

				default:
				
				return(ST_ERROR_BAD_PARAMETER);
			}
          
         break;
       
      	case STTUNER_LNB_POWER_DemodDACPin:
      
	    switch (Config->Polarization)
	    {
			case STTUNER_PLR_VERTICAL:      /* set DAC for 13V */
			LNB_DemodIO_SetDACPolarization(DemodInstance, VERTICAL);
			break;

			case STTUNER_PLR_HORIZONTAL:    /* set DAC for 18V */
			LNB_DemodIO_SetDACPolarization(DemodInstance, HORIZONTAL);
			break;
			
			case STTUNER_LNB_OFF:
			LNB_DemodIO_SetDACPolarization(DemodInstance, NOPOLARIZATION);
			break;

			default:
			return(ST_ERROR_BAD_PARAMETER);
        }
       
       break;
       
       default:
       break;
      }
      Instance->Config.Polarization = Config->Polarization;
    }


    /* Select power status */
    if (Instance->Config.Status != Config->Status)
    {
	    switch(Instance->Config.LNBPowerControl)
        {
	        case  STTUNER_LNB_POWER_LNBPDefault:
	    
			switch (Config->Status)
			{
				case LNB_STATUS_ON:
				case LNB_STATUS_OFF:
				LNB_DemodIO_SetPower(DemodInstance, Config->Status);
				break;
				default:
				
				return(ST_ERROR_BAD_PARAMETER);
			}
	       
	       break;
       
          case STTUNER_LNB_POWER_DemodDACPin:
	      
          switch (Config->Status)
	      {
			case LNB_STATUS_ON:
			case LNB_STATUS_OFF:
			LNB_DemodIO_Set_DACPower(DemodInstance, Config->Status);
			break;

			default:
			return(ST_ERROR_BAD_PARAMETER);
          }
	       
	       break;
       
       default:
       break;
     }
     Instance->Config.Status = Config->Status;  
    }

    UTIL_Delay(1000);

    #endif
    
#ifdef STTUNER_MINIDRIVER

⌨️ 快捷键说明

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