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

📄 lstem.c

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



/* ----------------------------------------------------------------------------
Name: lnb_lSTEM_SetConfig()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lSTEM_SetConfig(LNB_Handle_t Handle, LNB_Config_t *Config)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
   const char *identity = "STTUNER lstem.c lnb_lstem_SetConfig()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    LSTEM_InstanceData_t     *Instance;

    Instance = (LSTEM_InstanceData_t *)Handle;


    /* Select LNB band */
    if (Instance->Config.ToneState != Config->ToneState)
    {
        switch (Config->ToneState)
        {
            case STTUNER_LNB_TONE_OFF:      /* No tone */
                LSTEM_SetLnb(Instance->IOHandle, 0);
                break;

            case STTUNER_LNB_TONE_22KHZ:    /* 22KHz tone */
                LSTEM_SetLnb(Instance->IOHandle, 1);
                break;

            case STTUNER_LNB_TONE_DEFAULT:  /* no change */
                break;

            default:
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
                STTBX_Print(("%s fail tone state not default, off or 22KHz\n", identity));
#endif
                return(ST_ERROR_BAD_PARAMETER);
        }
        Instance->Config.ToneState = Config->ToneState;
    }


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

            case STTUNER_PLR_HORIZONTAL:    /* OP_2 controls -- 13V (low) */
                LSTEM_SetPolarization(Instance->IOHandle, HORIZONTAL);
                break;

            default:
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
                STTBX_Print(("%s fail polarity not V or H\n", identity));
#endif
                return(ST_ERROR_BAD_PARAMETER);
        }
       Instance->Config.Polarization = Config->Polarization;
    }


    /* Select power status */
    if (Instance->Config.Status != Config->Status)
    {
        switch (Config->Status)
        {
            case LNB_STATUS_ON:
            case LNB_STATUS_OFF:
                LSTEM_SetPower(Instance->IOHandle, Config->Status);
                break;

            default:
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
                STTBX_Print(("%s fail status not ON or OFF\n", identity));
#endif
                return(ST_ERROR_BAD_PARAMETER);
        }
       Instance->Config.Status = Config->Status;
    }

    LSTEM_UpdateLNB(Instance->IOHandle);

#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
    STTBX_Print(("%s ok\n", identity));
#endif
    return(Error);
}   



/* ----------------------------------------------------------------------------
Name: lnb_lSTEM_ioctl()

Description:
    access device specific low-level functions
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lSTEM_ioctl(LNB_Handle_t Handle, U32 Function, void *InParams, void *OutParams, STTUNER_Da_Status_t *Status)
   
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
   const char *identity = "STTUNER lstem.c lnb_lstem_ioctl()";
#endif
    ST_ErrorCode_t Error;
    LSTEM_InstanceData_t     *Instance;

    Instance = (LSTEM_InstanceData_t *)Handle;

    if(STTUNER_Util_CheckPtrNull(Instance) != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
        STTBX_Print(("%s invalid handle\n", identity));
#endif
        return(ST_ERROR_INVALID_HANDLE);
    }

    switch(Function){

        case STTUNER_IOCTL_RAWIO: /* read/write device register (actual write to STEM) */
            Error =  STTUNER_IOARCH_ReadWrite( Instance->IOHandle, 
                                                 ((SATIOCTL_IOARCH_Params_t *)InParams)->Operation,
                                                 ((SATIOCTL_IOARCH_Params_t *)InParams)->SubAddr,
                                                 ((SATIOCTL_IOARCH_Params_t *)InParams)->Data,
                                                 ((SATIOCTL_IOARCH_Params_t *)InParams)->TransferSize,
                                                 ((SATIOCTL_IOARCH_Params_t *)InParams)->Timeout );
            break;

        case STTUNER_IOCTL_REG_IN: /* read device register */
            *(int *)OutParams = STTUNER_IOREG_GetRegister(&Instance->DeviceMap, Instance->IOHandle, *(int *)InParams);
            break;

        case STTUNER_IOCTL_REG_OUT: /* write device register */
            Error =  STTUNER_IOREG_SetRegister(  &Instance->DeviceMap, 
                                                  Instance->IOHandle,
                  ((SATIOCTL_SETREG_InParams_t *)InParams)->RegIndex,
                  ((SATIOCTL_SETREG_InParams_t *)InParams)->Value );
            break;

        default:
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
            STTBX_Print(("%s function %d not found\n", identity, Function));
#endif
            return(ST_ERROR_FEATURE_NOT_SUPPORTED);
    }


#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
    STTBX_Print(("%s function %d called\n", identity, Function));
#endif
    return(Error);

}



/* ----------------------------------------------------------------------------
Name: lnb_lSTEM_ioaccess()

Description:
    we get called with the instance of
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lSTEM_ioaccess(LNB_Handle_t Handle, IOARCH_Handle_t IOHandle, STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
   const char *identity = "STTUNER lstem.c lnb_lSTEM_ioaccess()";
#endif
    ST_ErrorCode_t        Error = ST_NO_ERROR;
    IOARCH_Handle_t       LNB_IOHandle;
    LSTEM_InstanceData_t *Instance;
        

    Instance = (LSTEM_InstanceData_t *)Handle;

    /* check handle */
    if(STTUNER_Util_CheckPtrNull(Instance) != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
        STTBX_Print(("%s invalid handle\n", identity));
#endif
        return(ST_ERROR_INVALID_HANDLE);
    }

    LNB_IOHandle = Instance->IOHandle;

    /* if STTUNER_IOARCH_MAX_HANDLES then passthrough function required using our device handle (address) */ 
    if (IOHandle == STTUNER_IOARCH_MAX_HANDLES)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
        STTBX_Print(("%s write passthru\n", identity));
#endif
        Error = STTUNER_IOARCH_ReadWrite(LNB_IOHandle, Operation, SubAddr, Data, TransferSize, Timeout);
    }
    
    else    /* repeater */
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
        STTBX_Print(("%s write repeater\n", identity));
#endif
        

#ifdef STTUNER_DRV_SAT_DUAL_STEM_299
/*********I2C READ WRITE for demod is done here******************/
/*****If more number of demod added YOU have to add up here *****/
        /** The variable PCF8574RegisterValue is a global variable which captures the present data of LNB IoarchReadWrite()**/
                             
        /* New function STTUNER_IOARCH_DirectToI2C()for dual stem 
           added to enable the scanning algorithm work properly when demod
           is in repeater mode , instead of STTUNER_IOARCH_ReadWriteNoRep().
           Here in this function first lnb I2C write is done make the demod switch
           in right direction and demod I2C readwrite is done */
          
        while(1)
        {
            if(AccessFlag==0)
            {
                STTUNER_task_lock();
                AccessFlag=1;
                STTUNER_task_unlock();

                if(IOHandle == DemodHandleOne)
                    PCF8574RegisterValue = PCF8574RegisterValue & 0xFE; /* clear bit 0 - not FE1 */
                else if(IOHandle == DemodHandleTwo)
                    PCF8574RegisterValue = PCF8574RegisterValue | 0x1; /* set bit 0 - not FE1 */

                /* make I2c write for lnb to make demod switch point to right demod.
                   Here Subaddr=0, transfersize=1 and timeout=20 */
                Error = STTUNER_IOARCH_DirectToI2C(LNB_IOHandle, STTUNER_IO_WRITE, 0, &PCF8574RegisterValue, 1, IOREG_DEFAULT_TIMEOUT);
                task_delay(10);
                Error = STTUNER_IOARCH_DirectToI2C(IOHandle, Operation, SubAddr, Data, TransferSize, IOREG_DEFAULT_TIMEOUT);
                
                STTUNER_task_lock();
                AccessFlag=0;
                STTUNER_task_unlock();
                break;
            }
            else
            {
             	task_delay(10);
                continue;
            }
        }/* end of while*/
     
      
/****************************************************************/
#else
        /*****This function is used for single Tuner or Dual tuner with distinct address for demods*/    
        Error = STTUNER_IOARCH_ReadWriteNoRep(IOHandle, Operation, 0, Data, TransferSize, Timeout);
#endif
    }

#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
    STTBX_Print(("%s called\n", identity));
#endif
    
    return(Error);
}



/* ------------------------------------------------------------------------- */
/* /\/\/\/\/\/\/\/\/\/\/\/\/\UTILITY Functions/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
/* ------------------------------------------------------------------------- */


void LSTEM_UpdateLNB(IOARCH_Handle_t LNBHandle)
{
    STTBX_Print(("Update lnb "));
    if(LNBHandle==LnbHandleOne)
    {
        STTBX_Print(("1 = %02x", PCF8574RegisterValue));
        PCF8574RegisterValue = PCF8574RegisterValue & ~(0x1<<FSTEM_FE_SELECT); /* clear bit */
        STTBX_Print((" -> %02x\n", PCF8574RegisterValue));
    }
    else if(LNBHandle==LnbHandleTwo)
    {
        STTBX_Print(("2 = %02x", PCF8574RegisterValue));
        PCF8574RegisterValue = PCF8574RegisterValue | (0x1<<FSTEM_FE_SELECT); /* set bit */
        STTBX_Print((" -> %02x\n", PCF8574RegisterValue));
    }

    (void) STTUNER_IOARCH_DirectToI2C(LNBHandle, STTUNER_IO_WRITE, 0, &PCF8574RegisterValue, 1, 20);
    task_delay(10);
}


/*----------------------------------------------------
 FUNCTION      LSTEM_SetLnb
 ACTION        set the Lnb tone state (band selection: hi/lo band)
 PARAMS IN     Lnb -> true for High band, false for Low band.
 PARAMS OUT    NONE
 RETURN        NONE
------------------------------------------------------*/
void LSTEM_SetLnb(IOARCH_Handle_t IOHandle, int Lnb)
{
    /* Low band -> no 22KHz tone */
    /* High band -> 22KHz tone */

    U8 Bit;
    if(IOHandle==LnbHandleOne)
        Bit = 0x1 << FSTEM_FE1_TONE;
    else if(IOHandle==LnbHandleTwo)
        Bit = 0x1 << FSTEM_FE2_TONE;

    if ( Lnb == 1 )
        PCF8574RegisterValue = PCF8574RegisterValue | Bit; /* set bit */
    else if ( Lnb == 0 )
        PCF8574RegisterValue = PCF8574RegisterValue & ~(Bit); /* clear bit */
}

/*----------------------------------------------------
 FUNCTION      LSTEM_SetPolarization
 ACTION        set the polarization
 PARAMS IN     Polarization -> Polarization
 PARAMS OUT    NONE
 RETURN        NONE
------------------------------------------------------*/
void LSTEM_SetPolarization(IOARCH_Handle_t IOHandle, LNB_Polarization_t Polarization)
{
    U8 Bit;
    if(IOHandle==LnbHandleOne)
        Bit = 0x1 << FSTEM_FE1_VOLTAGE;
    else if(IOHandle==LnbHandleTwo)
        Bit = 0x1 << FSTEM_FE2_VOLTAGE;

    if ( Polarization == HORIZONTAL )
        PCF8574RegisterValue = PCF8574RegisterValue | Bit; /* set bit */
    else if ( Polarization == VERTICAL )
        PCF8574RegisterValue = PCF8574RegisterValue & ~(Bit); /* clear bit */
}

/*----------------------------------------------------
 FUNCTION      LSTEM_GetPower
 ACTION        get lnb power status
 PARAMS IN     
 PARAMS OUT    
 RETURN        
------------------------------------------------------*/
ST_ErrorCode_t LSTEM_GetPower(IOARCH_Handle_t IOHandle, LNB_Status_t *Status)
{
    U8 Bit;
    if(IOHandle==LnbHandleOne)
        Bit = 0x1 << FSTEM_FE1_LNB;
    else if(IOHandle==LnbHandleTwo)
        Bit = 0x1 << FSTEM_FE2_LNB;

    if (( PCF8574RegisterValue & Bit ) == 1 )
        *Status = LNB_STATUS_ON;
    else
        *Status = LNB_STATUS_OFF;
    
    return( ST_NO_ERROR );
}

/*----------------------------------------------------
 FUNCTION     LSTEM_SetPower
 ACTION        set lnb power
 PARAMS IN     
 PARAMS OUT    
 RETURN        
------------------------------------------------------*/
ST_ErrorCode_t LSTEM_SetPower(IOARCH_Handle_t IOHandle, LNB_Status_t Status)
{
    U8 Bit;
    if(IOHandle==LnbHandleOne)
        Bit = 0x1 << FSTEM_FE1_LNB;
    else if(IOHandle==LnbHandleTwo)
        Bit = 0x1 << FSTEM_FE2_LNB;

    if ( Status == LNB_STATUS_ON )
        PCF8574RegisterValue = PCF8574RegisterValue | Bit; /* set bit */
    else if ( Status == LNB_STATUS_OFF )
        PCF8574RegisterValue = PCF8574RegisterValue & ~(Bit); /* clear bit */

    return(ST_NO_ERROR);
}

/* End of l0299.c */

⌨️ 快捷键说明

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