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

📄 mxd_sdk_api.c

📁 MXD_SDK_Ax.x.xxx :MXD1320 软件开发包源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    }

    /*recovery processing*/
    if( ( MXD_RTN_FAIL == eRtnCode )  && ( NULL != psCallbackSetting->m_pPIL_UnlockCallback ))
    {
        eCallBackRtnCode = psCallbackSetting->m_pPIL_UnlockCallback( hDevice, 
                     sizeof( DEVICE_PROPERTY_S ), 
                     CB_SIGNAL_UNLOCKED_STATUS, 
                     CB_STATUS_DEFAULT);	
        if( CB_RC_OK == eCallBackRtnCode )
        {
            eRtnCode = MXD_RTN_OK;
        }
        else
        {
            eRtnCode = MXD_RTN_FAIL;
        }
    }

	return MXD_RTN_OK;
} /* end of MDW_GetLockStatus */

/*!
 * This function is used to setup the demod and tuner interface. 
 * \param  
 *         [ in ] hDevice:    Device handle.
 * \return 
 *         Return code by MXD_RTN_CODE_E enumeration   
 */
MXD_RTN_CODE_E MXD_API MDW_SetupInterface (IN HMXDDEV hDevice)
{
    PDEVICE_PROPERTY_S psDeviceProperty = NULL;
    PCHANNEL_PROPERTY_S psChanProperty = NULL;
    PSPI_PROPERTY_S psSpiProperty = NULL;
    MXD_U8 regVal = 0;
    MXD_U32 spiBufferSize = 0;
    MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
	
    psDeviceProperty = (PDEVICE_PROPERTY_S)hDevice;
    psChanProperty = &psDeviceProperty->m_sDemod.m_sChannelProperty;

#ifdef __SPI_USED__
    /*setup spi interface, if used*/	
    eRtnCode = DDS_SetupMxdSpi( hDevice );
    if( !MXD_SUCCESS( eRtnCode ) )
    {
        OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_SetupInterface :: Setup mxd spi err\n");
        return eRtnCode;
    }
#endif /* end of #ifdef __SPI_USED__ */

#ifdef __I2C_TS_USED__
    /*setup mp2ts interface, if used*/		
    if( ( MXD_MP2TS_IF == psChanProperty->m_eTsStreamAccessType ) )
    {
        DDS_SetupMxdMp2ts( hDevice );
        DDS_DisableMxdMp2tsTx( hDevice );
    }
#endif /* end of #ifdef __I2C_TS_USED__ */

    /*setup sdio interface, if used*/		
    if( ( MXD_SDIO_IF == psChanProperty->m_eRegAccessType ) ||
         ( MXD_SDIO_IF == psChanProperty->m_eTsStreamAccessType ) ||
         ( MXD_SDIO_IF == psChanProperty->m_eDataAccessType) )
    {
        return MXD_RTN_NOT_IMPLEMENTED;
    }

    /*Setup tuner*/
    eRtnCode = ((PDEVICE_PROPERTY_S)hDevice)->m_sTuner.m_pPIL_InitTuner( hDevice );
    if( !MXD_SUCCESS( eRtnCode ) )
    {
        OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_SetupInterface :: Init tuner err \n");
        return eRtnCode;
    }

    /*check control path*/
    DDS_WriteReg( psDeviceProperty,  COMMON_TIC_I2C_BIT_RATE_REG, 0xaa);
    DDS_ReadReg( psDeviceProperty,  COMMON_TIC_I2C_BIT_RATE_REG, &regVal);
    if( 0xaa != regVal)
    {
        OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_SetupInterface :: Setup control path err!!!\n");
        return MXD_RTN_FAIL;
    }
    DDS_WriteReg( psDeviceProperty,  COMMON_TIC_I2C_BIT_RATE_REG, 0x55);
    DDS_ReadReg( psDeviceProperty,  COMMON_TIC_I2C_BIT_RATE_REG, &regVal);
    if( 0x55 != regVal)
    {
        OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_SetupInterface :: Setup control path err!!!\n");
        return MXD_RTN_FAIL;
    }
	
    return MXD_RTN_OK;
}/*end of MDW_SetupInterface*/

/*!
 * This function is used to close the demod and tuner interface. 
 * \param  
 *         [ in ] hDevice:    Device handle.
 * \return 
 *         Return code by MXD_RTN_CODE_E enumeration   
 */
MXD_RTN_CODE_E MXD_API MDW_CloseInterface (IN HMXDDEV hDevice)
{
    PDEVICE_PROPERTY_S psDeviceProperty = NULL;
    PCHANNEL_PROPERTY_S psChanProperty = NULL;
    PSPI_PROPERTY_S psSpiProperty = NULL;
    MXD_RTN_CODE_E eRtnCode = MXD_RTN_OK;

    psDeviceProperty = (PDEVICE_PROPERTY_S)hDevice;
    psChanProperty = &psDeviceProperty->m_sDemod.m_sChannelProperty;

#ifdef __I2C_TS_USED__
    DDS_DisableMxdMp2tsTx( hDevice );
#endif /* end of #ifdef __I2C_TS_USED__ */

#ifdef __SPI_USED__
    DDS_StopMxdSpi( hDevice );
    psSpiProperty = &psDeviceProperty->m_sDemod.m_sSpiProperty;
#endif /* end of #ifdef __SPI_USED__ */

    return MXD_RTN_OK;
}/*end of MDW_CloseInterface*/

/*! 
 * This function is used to return status for no MXD_RTN_CODE_E function 
 * \param  
 *         [ in ] hDevice:    Device handle.
 * \return
 *         TRUE if no err,
 *         FALSE if some err.   
 */
MXD_RTN_CODE_E MXD_API MDW_GetLastErrStatus (IN HMXDDEV hDevice)
{
    return ((PDEVICE_PROPERTY_S)hDevice)->m_LastErrStatus;
}/*end of MDW_GetLastErrStatus*/


/***********************************************************************************************
 *
 * Tuner Section of SDK
 * - TIF_ReadTunerReg
 * - TIF_WriteTunerReg
 *
 ***********************************************************************************************
 */
#ifndef __TUNER_EXT_CTRL__
/*!
 * Read tuner register, this function should be used 
 *
 * \param hDevice    [ in ]  Device handle
 * \param  regAddr   [ in ]  Register address to be read.
 * \param  pRegVal   [ out ] Register value, which is read from tuner.
 *
 * \return Return code by MXD_RTN_CODE_E enumeration
 *
 * \remarks 
 *
 */
MXD_RTN_CODE_E MXD_API TIF_ReadTunerReg(
					IN HMXDDEV hDevice,
					IN MXD_U8 regAddr,
					OUT MXD_U8 *pRegVal )

{
    MXD_U8 ticStatus = 0;
    MXD_U8 checkNum = 0;
    MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;

    /*write the register address to TIC address reg*/
    DDS_WriteReg( hDevice, COMMON_TIC_TUNER_RDADDR_REG, regAddr);

    /*
    * we can read the TIC status reg to check this read operation completed or not in TIC module
    * if ok, then we read the data reg to get the register value
    */
    for (checkNum = 0; checkNum< TUNER_CHK_MAX_NUM; checkNum++)
    {
        eRtnCode = DDS_ReadReg( hDevice,  COMMON_TIC_STATUS_REG, &ticStatus);
        if( MXD_SUCCESS(eRtnCode) )
        {
            if( 0 != (ticStatus & TUNER_RW_ACCESS_FINISH))/* check bit0 of ticStatus ,if it is '1b1, then ok.*/
            {
                eRtnCode = DDS_ReadReg( hDevice,  COMMON_TIC_TUNER_RDDATA_A_REG, pRegVal);
                return eRtnCode;/* read tuner reg ok*/
            }
        }/*end of check operStatus*/
                
    }/*end of for loop*/
	return MXD_RTN_FAIL;
}/* end of TIF_ReadTunerReg()*/

/*!
 * Write tuner register, this function should be used 
 *
 * \param hDevice    [ in ] Device handle
 * \param  regAddr   [ in ]  Register address to be written
 * \param  regVal    [ in ]  Register value to be written
 *
 * \return Return code by MXD_RTN_CODE_E enumeration
 *
 * \remarks 
 *
 */
MXD_RTN_CODE_E MXD_API TIF_WriteTunerReg(
					IN HMXDDEV hDevice,
					IN MXD_U8 regAddr,
					IN MXD_U8 regVal )
{
    MXD_U8 ticStatus = 0;
    MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
    MXD_U8 checkNum = 0;

    /* write the register value to TIC write data reg*/
    DDS_WriteReg( hDevice,  COMMON_TIC_TUNER_WRDATA_A_REG, regVal );
        
    /* write the register address to TIC write address reg*/                                
    DDS_WriteReg( hDevice,  COMMON_TIC_TUNER_WRADDR_REG, regAddr );
        
    /*we can read the TIC status reg to check this write operation completed or not*/
    for( checkNum = 0; checkNum<TUNER_CHK_MAX_NUM; checkNum++)
    {
        eRtnCode = DDS_ReadReg( hDevice,  COMMON_TIC_STATUS_REG, &ticStatus );
        if( MXD_SUCCESS(eRtnCode) )
        {
            if( 0 !=(ticStatus & TUNER_RW_ACCESS_FINISH) ) /* check bit0 of ticStatus, if it is '1b1, then ok.*/
            {
                return eRtnCode; /* write tuner reg ok*/
            }
        }/* end of check operStatus */
    }/* end of for loop */

	return MXD_RTN_FAIL; /* write tuner reg error*/
}/* end of TIF_WriteTunerReg()*/
#endif /* end of #ifndef __TUNER_EXT_CTRL__ */


/***********************************************************************************************
 *
 * OAL Section of SDK
 * - OAL_Memcpy
 * - OAL_Memset
 *
 ***********************************************************************************************
 */
/*!
 * memory copy
 *
 * \param 
 *             dbgOutput    [ in ] size of memory.
 * \return 
 *             Returned destination address.
 */
VOID *OAL_Memcpy(VOID * pDest, CONST VOID *pSrc, MXD_U32 size)
{
    MXD_U32 i;

    for(i=0; i<size; i++)
    {
        (*((PMXD_U8)pDest)++) = (*((PMXD_U8)pSrc)++);
    }
    
    return 0;
}/* end of OAL_Memcpy( ) */

/*!
 * memory set
 *
 * \param dest		[ in ] pointer to the set buffer
 * \param value		[ in ] the set value
 * \param size		[ in ] the set number size
 * \return 
 *             Returned destination address.
 */
VOID *OAL_Memset(VOID * pDest , MXD_U8 value, MXD_U32 size)
{
    MXD_U32 i;

    for(i=0; i<size; i++)
    {
        (*((PMXD_U8)pDest)++) = value;
    }

    return 0;
}/*end of OAL_memset*/

/***********************************************************************************************
 *
 * DTMB Section of SDK
 * - DTMB_ResetDevice
 * - DTMB_DetectMode
 * - DTMB_SetDeviceMode
 * - DTMB_CypCalibrate
 * - DTMB_UfoCalibrate
 * - DTMB_DownloadMtx
 * - DTMB_InitDevice
 * - DTMB_StartDevice
 * - DTMB_CheckTpsVal
 * - DTMB_IsSignalSynced
 * - DTMB_StartStream
 * - DTMB_StopStream
 * - DTMB_GetSnr
 * - DTMB_GetRssi
 * - DTMB_GetBler
 * - DTMB_GetSystemInfo
 * - DTMB_GetServiceMap
 * - DTMB_IsTpsOk
 * - DTMB_IsSignalExist
 * - DTMB_CalcCpp
 * - DTMB_LoadEeprom
 *
 ***********************************************************************************************
 */

/*!
 * Reset DTMB device: on-chip buffer is flushed
 *
 * \param hDevice:  [in] Device handle. 
 *
 * \return Return code by MXD_RTN_CODE_E enumeration
 *
 */
MXD_RTN_CODE_E MXD_API DTMB_ResetDevice( IN HMXDDEV hDevice )
{
	/* clear all interrupt */
	DDS_WriteReg( hDevice,  DTMB_TDP_INT_CLEAR_REG, 0xff );
	DDS_WriteReg( hDevice,  DTMB_HIC_INT_CLEAR_REG, 0xff );

	/* soft reset all modules */
	DDS_WriteReg( hDevice,  DTMB_RESET_ALL_REG, 0x00 );
    
	/* wail for a moment ( 1ms ) for chip to reset */
	OAL_Sleep( 1 );

	/* pull the chip out of reset mode, into normal mode */
	DDS_WriteReg( hDevice,  DTMB_RESET_ALL_REG, 0xff );

	 /* flush data buffer */
	DDS_WriteRegFields( hDevice, 
						DTMB_HIC_FLUSH_RELOAD_REG,
						DTMB_DATA_BUFFER_FLUSH_BIT,
						1,
						0x1 );

	/* clear tdp status */
	((PDEVICE_PROPERTY_S)hDevice)->m_sDemod.m_TpsStatus = 0;
	
	return MXD_RTN_OK;    
    
} /* end of DTMB_ResetDevice( ) */

/*!
 * Detect multicarriers mode or singlecarrier mode in DTMB mode.
 *
 * \param hDevice:		[in] Device handle
 * \param milliseconds:[in] Check the status after delay( unit: ms )
 *
 * \return Return code by DEVICE_WORK_MODE_E enumeration
 *
 * \remarks This function must be called after DTMB device initial ok!
 */
DEVICE_WORK_MODE_E MXD_API DTMB_DetectMode( 
				 		IN HMXDDEV hDevice,
 						IN MXD_U32 milliseconds )
{
	MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
	PDEVICE_PROPERTY_S psDeviceProperty;
	DEVICE_WORK_MODE_E eDevMode[2] = { DEV_MODE_DTMB_MC, DEV_MODE_DTMB_SC };
	MXD_U8 curMode = 0;
	psDeviceProperty = (PDEVICE_PROPERTY_S)hDevice;

#ifdef __AUTO_DETECT_ALL_MODE__
	DTMB_ResetDevice( psDeviceProperty );
       DTMB_SetDeviceMode( psDeviceProperty, DEV_MODE_DTMB_AUTO );

	switch(psDeviceProperty->m_PnType)
	{
		case 0:
		case 1:
		case 2:
		case 3:
			curMode = 0;
			break;
		case 4:
			curMode = 1;
			break;
		default:
			break;
	}
	psDeviceProperty->m_eDevMode = eDevMode[curMode];

	DTMB_StartDevice( psDeviceProperty );
	eRtnCode = DTMB_IsSignalSynced( psDeviceProperty, milliseconds );
	if( MXD_SUCCESS(eRtnCode) )
	{
		psDeviceProperty->m_LastErrStatus = MXD_RTN_OK;
		return psDeviceProperty->m_eDevMode;
	}
	else
	{
		if( 0 == curMode )
		{
			curMode = 1;
		}
		else
		{
			curMode = 0;
		}
		psDeviceProperty->m_eDevMode = eDevMode[curMode];

		DTMB_ResetDevice( psDeviceProperty );
              DTMB_SetDeviceMode( psDeviceProperty, eDevMode[curMode] );
		DTMB_StartDevice( psDeviceProperty );

		eRtnCode = DTMB_IsSignalSynced( psDeviceProperty, milliseconds );
		if( MXD_SUCCESS(eRtnCode) )
		{
			psDeviceProperty->m_LastErrStatus = MXD_RTN_OK;
			return psDeviceProperty->m_eDevMode;
		}
		
		psDeviceProperty->m_LastErrStatus = MXD_RTN_FAIL;
		psDeviceProperty->m_eDevMode = DEV_MODE_DEFAULT;
		return DEV_MODE_DEFAULT;
	}

#else
	for( curMode=0; curMode<2; curMode++ )
	{
		OAL_DebugPrint( MXD_ULTRA_TRACE, "DTMB_DetectMode:: Try %d  ____ !" ,eDevMode[curMode] );
		DTMB_ResetDevice( psDeviceProperty );
		DTMB_SetDeviceMode( psDeviceProperty, eDevMode[curMode] );
		DTMB_StartDevice( psDeviceProperty );
		eRtnCode = DTMB_IsSignalSynced( psDeviceProperty, milliseconds>>1 );
		if( MXD_SUCCESS(eRtnCode) )
		{
			psDeviceProperty->m_eDevMode = eDevMode[curMode];
			psDeviceProperty->m_LastErrStatus = MXD_RTN_OK;
			return psDeviceProperty->m_eDevMode;
		}
	}
#endif
} /* end of DTMB_DetectMode( ) */

/*!
 * Set device mode  in DTMB mode.
 *
 * \param hDevice:  [in] Device handle. 
 * \param eDeviceMode:  [ in ]  Device working mode to be set.

⌨️ 快捷键说明

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