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

📄 d0362.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
    Data=STTUNER_IOREG_GetField(&(Instance->DeviceMap),Instance->IOHandle,F0362_TPS_MODE /*R_TPS_RCVD1*/);
   /* 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 = 0xff; /* error */
            break;
    }

    *Mode = CurMode;

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
    STTBX_Print(("%s Mode=%u\n", identity, *Mode));
#endif
     /*Add error handling from device map*/
    return(Error);
}

/* ----------------------------------------------------------------------------
Name: demod_d0362_GetGuard()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_GetGuard(DEMOD_Handle_t Handle, STTUNER_Guard_t *Guard)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
   const char *identity = "STTUNER d0362.c demod_d0362_GetGuard()";
#endif
    U8 Data;
    STTUNER_Guard_t CurGuard;
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0362_InstanceData_t *Instance;

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

    CurGuard = 0;
    Data = STTUNER_IOREG_GetField(&(Instance->DeviceMap),Instance->IOHandle, F0362_TPS_GUARD);

    /* Convert venrate value to a STTUNER fecrate */
    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 = 0xff; /* error */
            break;
    }

    *Guard = CurGuard;  /* Copy back for caller */

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
    STTBX_Print(("%s Guard=%u\n", identity, CurGuard));
#endif

    /*Resolve Bug GNBvd17801 - For proper I2C error handling inside the driver*/
    /*Add error handling from device map*/
    return(Error);
}
/* ----------------------------------------------------------------------------
Name: demod_d0362_IsLocked()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_IsLocked(DEMOD_Handle_t Handle, BOOL *IsLocked)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
   const char *identity = "STTUNER d0362.c demod_d0362_IsLocked()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0362_InstanceData_t *Instance;

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

    *IsLocked = STTUNER_IOREG_GetField(&(Instance->DeviceMap),Instance->IOHandle, F0362_LK) ? TRUE : FALSE;
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
    STTBX_Print(("%s IsLocked=%u\n", identity, *IsLocked));
#endif

    /*Resolve Bug GNBvd17801 - For proper I2C error handling inside the driver*/

    return(Error);
}




/* ----------------------------------------------------------------------------
Name: demod_d0362_ScanFrequency()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_ScanFrequency   (DEMOD_Handle_t Handle,
                                            U32  InitialFrequency,
                                            U32  SymbolRate,
                                            U32  MaxOffset,
                                            U32  TunerStep,
                                            U8   DerotatorStep,
                                            BOOL *ScanSuccess,
                                            U32  *NewFrequency,
                                            U32  Mode,
                                            U32  Guard,
                                            U32  Force,
                                            U32  Hierarchy,
                                            U32  Spectrum,
                                            U32  FreqOff,
                                            U32  ChannelBW,
                                            S32  EchoPos)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
   const char *identity = "STTUNER d0362.c demod_d0362_ScanFrequency()";
#endif
   
    ST_ErrorCode_t              Error = ST_NO_ERROR;
    FE_362_Error_t error = FE_362_NO_ERROR;
    STTUNER_tuner_instance_t    *TunerInstance;
    STTUNER_InstanceDbase_t     *Inst;
    D0362_InstanceData_t        *Instance;
   
    FE_362_SearchParams_t       Search;
    FE_362_SearchResult_t       Result;
    /* private driver instance data */
    Instance = d0362_GetInstFromHandle(Handle);

    /* top level public instance data */
    Inst = STTUNER_GetDrvInst();

    /* get the tuner instance for this driver from the top level handle */
    TunerInstance = &Inst[Instance->TopLevelHandle].Terr.Tuner;

      
    Search.Frequency = (U32)(InitialFrequency);
    Search.Mode      = (STTUNER_Mode_t)Mode;
    Search.Guard     = (STTUNER_Guard_t)Guard;
    Search.Force     = (STTUNER_Force_t)Force;
    Search.Inv       = (STTUNER_Spectrum_t)Spectrum;
    Search.Offset    = (STTUNER_FreqOff_t)FreqOff;
    Search.ChannelBW = ChannelBW;
    Search.EchoPos   = EchoPos;
    Search.Hierarchy= (STTUNER_Hierarchy_t)Hierarchy;
    if (TunerInstance->Driver->ID == STTUNER_TUNER_RF4000)
   {
    Search.IF_IQ_Mode =FE_362_NORMAL_IF_TUNER;/*This should come from application*/
   }
   else
   {
     Search.IF_IQ_Mode = FE_362_NORMAL_IF_TUNER; /*This should come from application*/
   }

   error = FE_362_LookFor(Handle,&(Instance->DeviceMap),Instance->IOHandle, &Search, &Result,Instance->TopLevelHandle);
   
   if(error == FE_362_BAD_PARAMETER)
    {
       Error= ST_ERROR_BAD_PARAMETER;
 	 #ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
           STTBX_Print(("%s fail, scan not done: bad parameter(s) to FE_362_Search() == FE_BAD_PARAMETER\n", identity ));
	 #endif      
       return Error;
    }
    
    else if (error == FE_362_SEARCH_FAILED)
    {
    	Error= ST_NO_ERROR;  
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
           STTBX_Print(("%s  FE_362_Search() == FE_362_SEARCH_FAILED\n", identity ));
#endif
	return Error;
    	
    }

    
     *ScanSuccess = Result.Locked;
     if (*ScanSuccess == TRUE)
     {
     	*NewFrequency = Result.Frequency;
		
		
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s NewFrequency=%u\t", identity, *NewFrequency));
    STTBX_Print(("%s ScanSuccess=%u\n", identity, *ScanSuccess));
#endif
     	
     	 
     }
     	 return(ST_NO_ERROR);

   
}



/* ----------------------------------------------------------------------------
Name: demod_d0362_ioctl()

Description:
    access device specific low-level functions

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_ioctl(DEMOD_Handle_t Handle, U32 Function, void *InParams, void *OutParams, STTUNER_Da_Status_t *Status)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
   const char *identity = "STTUNER d0362.c demod_d0362_ioctl()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0362_InstanceData_t *Instance;

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

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

#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s demod driver instance handle=%d\n", identity, Handle));
        STTBX_Print(("%s                     function=%d\n", identity, Function));
        STTBX_Print(("%s                   I/O handle=%d\n", identity, Instance->IOHandle));
#endif

    /* ---------- select what to do ---------- */
    switch(Function){

        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,
                  ((TERIOCTL_SETREG_InParams_t *)InParams)->RegIndex,
                  ((TERIOCTL_SETREG_InParams_t *)InParams)->Value );
            break;

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


#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
    STTBX_Print(("%s called ok\n", identity, Function));    /* signal that function came back */
#endif
 
    return(Error);

}



/* ----------------------------------------------------------------------------
Name: demod_d0362_ioaccess()

Description:
    called from ioarch.c when some driver does I/O but with the repeater/passthru
    set to point to this function.
Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_ioaccess(DEMOD_Handle_t Handle, IOARCH_Handle_t IOHandle, STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout)

{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
   const char *identity = "STTUNER d0362.c demod_d0362_ioaccess()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    IOARCH_Handle_t ThisIOHandle;
    D0362_InstanceData_t *Instance;
     STTUNER_tuner_instance_t    *TunerInstance;
    STTUNER_InstanceDbase_t     *Inst;
    Instance = d0362_GetInstFromHandle(Handle);

    Inst = STTUNER_GetDrvInst();
    /* get the tuner instance for this driver from the top level handle */
    TunerInstance = &Inst[Instance->TopLevelHandle].Terr.Tuner;
    if(STTUNER_Util_CheckPtrNull(Instance) != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s invalid handle\n", identity));
#endif
        return(ST_ERROR_INVALID_HANDLE);
    }

    /* this (demod) drivers I/O handle */
    ThisIOHandle = 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_TERDRV_D0362
        STTBX_Print(("%s write passthru\n", identity));
#endif
        Error = STTUNER_IOARCH_ReadWrite(ThisIOHandle, Operation, SubAddr, Data, TransferSize, Timeout);
    }
    else    /* repeater */
    {
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
        STTBX_Print(("%s write repeater\n", identity));
#endif
	
        /* enable repeater then send the data  using I/O handle supplied through ioarch.c */
             
       
         Error = STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0362_STOP_ENABLE, 1);
         Error = STTUNER_IOREG_SetField(&(Instance->DeviceMap), Instance->IOHandle, F0362_I2CT_ON, 1);           
        	
       
        /* send callers data using their address. (nb: subaddress == 0)
         Function 'STTUNER_IOARCH_ReadWriteNoRep' is called as calling the normal 'STTUNER_IOARCH_ReadWrite'
        function would cause it to call the redirection function which is THIS function, and around we
        would go forever. */
	  Error = STTUNER_IOARCH_ReadWriteNoRep(IOHandle, Operation,SubAddr, Data, TransferSize, Timeout);
       
    }

    return(Error);
}


/* ----------------------------------------------------------------------------
Name: demod_d0362_Tracking()

Description:
    This routine checks the carrier against a certain threshold value and will
    perform derotator centering, if necessary -- using the ForceTracking
    option ensures that derotator centering is always performed when
    this routine is called.

    This routine should be periodically called once a lock has been
    established in order to maintain the lock.
    This routine checks the carrier against a certain threshold value and will
Parameters:
    ForceTracking, boolean to control whether to always perform
                   derotator centering, regardless of the carrier.

    NewFrequency,  pointer to area where to store the new frequency
                   value -- it may be changed when trying to optimize
                   the derotator.

    SignalFound,   indicates that whether or not we're still locked

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0362_Tracking(DEMOD_Handle_t Handle, BOOL ForceTracking, U32 *NewFrequency, BOOL *SignalFound)
{
#ifdef STTUNER_DEBUG_MODULE_TERDRV_D0362
   const char *identity = "STTUNER d0362.c demod_d0362_Tracking()";
#endif
    FE_362_Error_t           Error = ST_NO_ERROR;
    D0362_InstanceData_t    *Instance;
 
    Instance = d0362_GetInstFromHandle(Handle);
     
/****************************************
Tracking should check the lock status. Temporary disabled for testing 
*****************************************/
    FE_362_Tracking(&(Instance->DeviceMap), Instance->IOHandle,&Instance->UnlockCounter);
    
    /*Error handling*/
    return(Error);
}

ST_ErrorCode_t demod_d0362_GetTPSCellId(DEMOD_Handle_t Handle, U16  *TPSCellId)
{
	return ST_NO_ERROR;

}



/* ----------------------------------------------------------------------------
Name: demod_d0360_StandByMode()

Description:

Parameters:

Return Value:

⌨️ 快捷键说明

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