?? mxd_sdk_api.c
字號(hào):
/*!
*
* \file mxd_sdk_api.c
*
* \brief SDK implementation.
*
* API of MXD1320 SDK for user
*
* \par Include files
* - mxd_sdk_api.h
*
* \par Copyright (c) 2007 Maxscend Technologies Inc. All rights reserved
*
* PROPRIETARY RIGHTS of Maxscend Technologies Inc. are involved in
* the subject matter of this material. All manufacturing, reproduction,
* use, and sales rights pertaining to this subject matter are governed
* by the license agreement. The recipient of this software implicitly
* accepts the terms of the license.
*
* \version
* Revision of last commit: $Rev:: 359 $
* Author of last commit : $Author:: MAXSCEND\yang.liu $
* Date of last commit : $Date:: 2007-12-12 13:16:06 +0800#$
*
*/
#include "mxd_sdk_api.h"
/***********************************************************************************************
*
* Static Global Variables of SDK
*
***********************************************************************************************
*/
static DEVICE_PROPERTY_S gsDeviceProprity;
/***********************************************************************************************
*
* MDW Section of SDK
* - MDW_OpenDevice
* - MDW_CloseDevice
* - MDW_TuneFreq
* - MDW_GetSystemSnr
* - MDW_GetSystemRssi
* - MDW_GetSystemPer
* - MDW_ChannelSearch
* - MDW_GetLockStatus
*
***********************************************************************************************
*/
/*!
* This function is used to open device with demod and tuner property as input
* parameters.
* \param
* [ in ] pPIL_DeviceConfig: Pointer to function for device configuration.
* [ in ] psCbSetting: Pointer to the callback setting for communication.
* \return
* device handle
* NULL, if failed.
*/
HMXDDEV MXD_API MDW_OpenDevice (
IN CONST PIL_DEVICECONFIG pPIL_DeviceConfig,
IN CONST PCALLBACK_SETTING_S psCbSetting)
{
PDEVICE_PROPERTY_S psDeviceProperty = NULL;
MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
PCALLBACK_SETTING_S psDstCbSetting = NULL;
if( NULL == pPIL_DeviceConfig )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_OpenDevice :: Invalid arg\n" );
return NULL;
}
psDeviceProperty = &gsDeviceProprity;
OAL_Memset( psDeviceProperty, 0, sizeof( DEVICE_PROPERTY_S ) );
/*Init demod and tuner para in hDevice*/
psDeviceProperty->m_hDevice = (HMXDDEV)psDeviceProperty;
( *pPIL_DeviceConfig )( &psDeviceProperty->m_sDemod, &psDeviceProperty->m_sTuner );
psDeviceProperty->m_LastErrStatus = MXD_RTN_OK;
/*Init demod callback setting in hDevice*/
if( NULL != psCbSetting )
{
psDstCbSetting = &psDeviceProperty->m_sDemod.m_sCbSetting;
psDstCbSetting->m_DtmbDataThrd = psCbSetting->m_DtmbDataThrd;
psDstCbSetting->m_DmbSch1Thrd = psCbSetting->m_DmbSch1Thrd;
psDstCbSetting->m_DmbSch2Thrd = psCbSetting->m_DmbSch2Thrd;
psDstCbSetting->m_pPIL_DataIntCallback = psCbSetting->m_pPIL_DataIntCallback;
psDstCbSetting->m_pPIL_StatusIntCallback = psCbSetting->m_pPIL_StatusIntCallback;
}
eRtnCode = MDW_SetupInterface( psDeviceProperty );
if( !MXD_SUCCESS( eRtnCode ) )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_OpenDevice :: Cannot Setup interface\n");
MDW_CloseDevice(psDeviceProperty);
return NULL;
}
/*set default mode as DEV_MODE_DTMB_MC */
MDW_SetDeviceMode( psDeviceProperty, DEV_MODE_DTMB_MC );
if( DEV_MODE_TDMB == psDeviceProperty->m_eDevMode )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_OpenDevice :: Not implement T-DMB mode\n");
MDW_CloseDevice(psDeviceProperty);
return NULL;
}
else
{
/* Reset lock status sem */
DDS_WriteRegFields( psDeviceProperty, DTMB_STATUS_SEM_REG, DTMB_LOCK_STATUS_SEM_BIT, 1, DTMB_UNLOCK_STATUS);
#ifdef __I2C_TS_USED__
if( MXD_MP2TS_IF == psDeviceProperty->m_sDemod.m_sChannelProperty.m_eTsStreamAccessType )
{
DDS_EnableMxdMp2tsTx( psDeviceProperty );
}
else
{
DDS_DisableMxdMp2tsTx( psDeviceProperty );
}
#endif /* end of #ifdef __I2C_TS_USED__ */
DDS_SetupSdramController( psDeviceProperty );
DTMB_InitDevice( psDeviceProperty );
DTMB_DownloadMtx(psDeviceProperty,
MTXTABLE_IN_SDRAM,
MTXHUFMANTABLE_ADDR,
MTX_HUFMAN_TABLE_LEN);
}
return psDeviceProperty->m_hDevice;
} /* end of MDW_OpenDevice( ) */
/*!
* This function is used to close device.
* \param
* [ in ] hDevice: Device handle.
* \return
* Return code by MXD_RTN_CODE_E enumeration
*/
MXD_RTN_CODE_E MXD_API MDW_CloseDevice (IN HMXDDEV hDevice)
{
if( NULL == hDevice )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_CloseDevice :: Invalid arg\n" );
return MXD_RTN_INVALID_ARG;
}
if( DEV_MODE_TDMB == ((PDEVICE_PROPERTY_S)hDevice)->m_eDevMode )
{
return MXD_RTN_NOT_IMPLEMENTED;
}
else
{
DTMB_StopStream( hDevice);
DTMB_ResetDevice( hDevice );
}
MDW_CloseInterface( hDevice );
return MXD_RTN_OK;
} /* end of MDW_CloseDevice( ) */
/*!
* This function is used to set device working mode.
* \param
* [ in ] hDevice: Device handle.
* [ in ] eDeviceMode: Device working mode to be set.
* \return
* Return code by MXD_RTN_CODE_E enumeration.
* \issues
* Cannot Set mode from T-DMB to DTMB, or DTMB to T-DMB in this version
*/
MXD_RTN_CODE_E MXD_API MDW_SetDeviceMode (
IN HMXDDEV hDevice,
IN DEVICE_WORK_MODE_E eDeviceMode)
{
if( DEV_MODE_TDMB == eDeviceMode )
{
((PDEVICE_PROPERTY_S)hDevice)->m_LastErrStatus = MXD_RTN_FAIL;
return MXD_RTN_NOT_SUPPORTED;
}
else
{
DTMB_ResetDevice( hDevice );
DTMB_SetDeviceMode( hDevice, eDeviceMode );
((PDEVICE_PROPERTY_S)hDevice)->m_eDevMode = eDeviceMode;
}
return MXD_RTN_OK;
}/* end of MDW_SetDeviceMode( ) */
#ifndef __TUNER_EXT_CTRL__
/*!
* This function is used to tune frequency for current system.
* \param
* [ in ] hDevice: Device handle.
* [ in ] freqHz: frequency in Hz.
* \return
* Return code by MXD_RTN_CODE_E enumeration.
*/
MXD_RTN_CODE_E MXD_API MDW_TuneFreq (
IN HMXDDEV hDevice,
IN MXD_U32 freqHz)
{
MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
if( NULL == hDevice )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_TuneFreq :: Invalid arg\n" );
return MXD_RTN_INVALID_ARG;
}
((PDEVICE_PROPERTY_S)hDevice)->m_sTuner.m_pPIL_SetFreq( hDevice, freqHz );
eRtnCode = ((PDEVICE_PROPERTY_S)hDevice)->m_sTuner.m_pPIL_GetTunerStatus(hDevice);
if( !MXD_SUCCESS( eRtnCode ) )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_TuneFreq :: Get tuner status err\n");
return eRtnCode;
}
((PDEVICE_PROPERTY_S)hDevice)->m_FreqHz = freqHz;
return MXD_RTN_OK;
}/* end of MDW_TuneFreq( ) */
#endif /* end of #ifdef __TUNER_EXT_CTRL__ */
/*!
* This function is used to get system SNR.
* \param
* [ in ] hDevice: Device handle.
* \return
* Return system SNR.
* \issues
* This function is not implement for T-DMB mode in this version.
*/
MXD_U32 MXD_API MDW_GetSystemSnr (IN HMXDDEV hDevice)
{
if( DEV_MODE_TDMB == ((PDEVICE_PROPERTY_S)hDevice)->m_eDevMode )
{
((PDEVICE_PROPERTY_S)hDevice)->m_LastErrStatus = MXD_RTN_FAIL;
return 0;
}
else
{
return DTMB_GetSnr( hDevice );
}
}/* end of MDW_GetSystemSnr( ) */
/*!
* This function is used to get system RSSI.
* \param
* [ in ] hDevice: Device handle.
* \return
* Return system RSSI.
* \issues
* This function is not implement for T-DMB mode in this version.
*/
MXD_U32 MXD_API MDW_GetSystemRssi (IN HMXDDEV hDevice)
{
if( DEV_MODE_TDMB == ((PDEVICE_PROPERTY_S)hDevice)->m_eDevMode )
{
((PDEVICE_PROPERTY_S)hDevice)->m_LastErrStatus = MXD_RTN_FAIL;
return 0;
}
else
{
return DTMB_GetRssi( hDevice );
}
}/* end of MDW_GetSystemRssi( ) */
/*!
* This function is used to get system PER.
* \param
* [ in ] hDevice: Device handle.
* [ in ] ePerType: PER type
* \return
* Return system PER.
* \remarks
* It only supports LDPC type of PER for DMB-T mode.
* \issues
* This function is not implement for T-DMB mode in this version.
*/
MXD_U32 MXD_API MDW_GetSystemPer (
IN HMXDDEV hDevice,
IN SYSTEM_PER_TYPE_E ePerType)
{
if( DEV_MODE_TDMB == ((PDEVICE_PROPERTY_S)hDevice)->m_eDevMode )
{
((PDEVICE_PROPERTY_S)hDevice)->m_LastErrStatus = MXD_RTN_FAIL;
return 0;
}
else
{
if( PER_POST_LDPC != ePerType )
{
((PDEVICE_PROPERTY_S)hDevice)->m_LastErrStatus = MXD_RTN_FAIL;
return 0;
}
return DTMB_GetBler( hDevice );
}
}/* end of MDW_GetSystemPer( ) */
/*!
* This function is used to search Channel.
* \param
* [ in ] hDevice: Device handle.
* [ in ] freqHz: frequency in Hz.
* [ in ] milliseconds: Timeout seconds.
* [ OUT ] psChannelInfo: pointer to the system information returned,
* the structure should be matched with the
* device working mode.
* ( dedicated for DTMB: service map structure)
* \return
* Return code by MXD_RTN_CODE_E enumeration.
* \remarks
* Set the device in DMB-T mode if search corresponding channel, else set T-DMB mode before searching.
* \issues
* This function is not implement for T-DMB mode in this version.
*/
MXD_RTN_CODE_E MXD_API MDW_ChannelSearch (
IN HMXDDEV hDevice,
IN MXD_U32 freqHz,
IN MXD_U32 milliseconds,
OUT VOID *psChannelInfo)
{
DEVICE_WORK_MODE_E eDevWorkMode;
MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
if( ( NULL == hDevice ) || ( NULL == psChannelInfo ) )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_ChannelSearch :: Invalid arg\n" );
return MXD_RTN_INVALID_ARG;
}
if( DEV_MODE_TDMB == ((PDEVICE_PROPERTY_S)hDevice)->m_eDevMode )
{
return MXD_RTN_NOT_IMPLEMENTED;
}
else
{
/* Reset lock status sem */
DDS_WriteRegFields( hDevice, DTMB_STATUS_SEM_REG, DTMB_LOCK_STATUS_SEM_BIT, 1, DTMB_UNLOCK_STATUS);
if( ((PDEVICE_PROPERTY_S)hDevice)->m_FreqHz != freqHz )
{
#ifndef __TUNER_EXT_CTRL__
eRtnCode = MDW_TuneFreq( hDevice, freqHz );
if( !MXD_SUCCESS( eRtnCode ) )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_ChannelSearch :: Tune frequence err!\n");
return eRtnCode;
}
#endif /* end of #ifdef #ifdef __TUNER_EXT_CTRL__ */
DTMB_ResetDevice( hDevice );
eRtnCode = DTMB_IsSignalExist( hDevice, 500 );
if(!MXD_SUCCESS( eRtnCode ))
{
return eRtnCode;
}
DTMB_ResetDevice( hDevice );
eRtnCode = DTMB_UfoCalibrate( hDevice );
if( !MXD_SUCCESS( eRtnCode ) )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_ChannelSearch:: UFO calibration err!\n");
return MXD_RTN_FAIL;
}
DTMB_ResetDevice( hDevice );
eRtnCode = DTMB_CypCalibrate(hDevice, 0, 70);
if( !MXD_SUCCESS( eRtnCode ) )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_ChannelSearch:: CYP calibration err!\n");
return MXD_RTN_FAIL;
}
}
eDevWorkMode = DTMB_DetectMode( hDevice, milliseconds/2 );
if( DEV_MODE_DEFAULT == eDevWorkMode )
{
return MXD_RTN_FAIL;
}
eRtnCode = DTMB_GetServiceMap( hDevice, (PDTMB_SERVICE_MAP_S)psChannelInfo );
if(!MXD_SUCCESS( eRtnCode ))
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_ChannelSearch:: get service map err!\n");
return eRtnCode;
}
DTMB_StartStream( hDevice, ((PDTMB_SERVICE_MAP_S)psChannelInfo)->m_TpsId );
/* Reset lock status sem: NOT EXIST IN TDMB mode */
DDS_WriteRegFields( hDevice, DTMB_STATUS_SEM_REG, DTMB_LOCK_STATUS_SEM_BIT, 1, DTMB_LOCK_STATUS);
}
return MXD_RTN_OK;
}/* end of MDW_ChannelSearch( ) */
/*!
* This function is used to detect whether signal locked when playing.
* \param
* [ in ] hDevice: Device handle.
* \return
* Return code by MXD_RTN_CODE_E enumeration.
* \issues
* This function is not implement for T-DMB mode in this version.
*/
MXD_RTN_CODE_E MXD_API MDW_GetLockStatus ( IN HMXDDEV hDevice )
{
MXD_U8 regVal = 0;
PCALLBACK_SETTING_S psCallbackSetting = NULL;
MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
CALLBACK_RC_E eCallBackRtnCode = CB_RC_FAIL;
if( NULL == hDevice )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "MDW_GetLockStatus :: Invalid arg\n" );
return MXD_RTN_INVALID_ARG;
}
if( DEV_MODE_TDMB == ((PDEVICE_PROPERTY_S)hDevice)->m_eDevMode )
{
return MXD_RTN_FAIL;
}
else
{
DDS_ReadRegFields( hDevice, DTMB_STATUS_SEM_REG, DTMB_LOCK_STATUS_SEM_BIT, 1, ®Val);
if( DTMB_UNLOCK_STATUS == (regVal & 0x01))
{
return MXD_RTN_FAIL;
}
DDS_ReadReg( hDevice, DTMB_TDP_INT_STATUS_REG, ®Val);
if( 0 == (regVal & DTMB_TDP_FTT_FAIL_INT_SET ) )
{
eRtnCode = MXD_RTN_OK;
}
else
{
/* Reset lock status sem */
DDS_WriteRegFields( hDevice, DTMB_STATUS_SEM_REG, DTMB_LOCK_STATUS_SEM_BIT, 1, DTMB_UNLOCK_STATUS);
eRtnCode = MXD_RTN_FAIL;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -