?? mxd_sdk_api.c
字號:
*
* \return Return code by MXD_RTN_CODE_E enumeration
*
* \remarks
*
*/
MXD_RTN_CODE_E MXD_API DTMB_SetDeviceMode(
IN HMXDDEV hDevice ,
IN DEVICE_WORK_MODE_E eDeviceMode )
{
/* set device mode */
switch( eDeviceMode )
{
case DEV_MODE_DTMB_MC:
{
return DDS_WriteReg( hDevice, DTMB_FDP_CARRIER_MODE_REG, 0x02 );
}
case DEV_MODE_DTMB_SC:
{
return DDS_WriteReg( hDevice, DTMB_FDP_CARRIER_MODE_REG, 0x03 );
}
case DEV_MODE_DTMB_AUTO:
{
return DDS_WriteReg( hDevice, DTMB_FDP_CARRIER_MODE_REG, 0x00 );
}
case DEV_MODE_TDMB:
case DEV_MODE_DEFAULT:
default:
{
return MXD_RTN_UNDEFINED_ERR;
}
}
} /* end of DTMB_SetDeviceMode( ) */
/*!
* Calitrate device CYP.
*
* \param hDevice: [in] Device handle.
*
* \return the DU.
*
* \remarks This function must be called after Init tuner, tune freq, init device, download mtx.
*
*/
MXD_RTN_CODE_E MXD_API DTMB_CypCalibrate(
IN HMXDDEV hDevice,
IN MXD_U8 frmNumStart,
IN MXD_U8 cypThd)
{
MXD_U8 regVal;
MXD_U8 ofoValH,ofoValL;
MXD_S32 i;
MXD_U8 frmNum = 0;
MXD_S16 frmLen = 0;
MXD_S32 dN[7];
MXD_S32 dU;
MXD_U16 ofoLen = 0;
MXD_S16 ofoVal;
MXD_U8 cypFlag = 0;
MXD_S32 duSum = 0;
MXD_U32 dtU = 0;
PDEVICE_PROPERTY_S psDeviceProperty;
psDeviceProperty = ( PDEVICE_PROPERTY_S )hDevice;
/* Init du to zero */
DDS_WriteReg( hDevice, DTMB_TDP_DU_H_REG, 0x0 );
DDS_WriteReg( hDevice, DTMB_TDP_DU_M_REG, 0x0 );
DDS_WriteReg( hDevice, DTMB_TDP_DU_L_REG, 0x0 );
for( frmNum=frmNumStart; frmNum<3; frmNum++ )
{
switch( psDeviceProperty->m_PnType )
{
case 0: /*420*/
case 1:
{
frmLen = FRAME_LEN_420;
ofoLen = ( frmNum+1 )*225;
break;
}
case 2: /*945*/
case 3:
{
frmLen = FRAME_LEN_945;
ofoLen = ( frmNum+1 )*200;
break;
}
case 4: /*595*/
{
frmLen = FRAME_LEN_595;
ofoLen = ( frmNum+1 )*200;
break;
}
default:
return MXD_RTN_FAIL;
}/* end of switch ( PN type) */
DDS_WriteReg( hDevice, DTMB_TDP_OFO_LENGTH_REG, frmNum );
/* Set TDP work mode to calibration mode*/
DDS_WriteReg( hDevice, DTMB_TDP_WORK_MODE_REG, 0x02 );
DDS_WriteReg( hDevice, DTMB_TDP_INIT_FO_H_REG, (MXD_U8)(psDeviceProperty->m_InitFo>>16));
DDS_WriteReg( hDevice, DTMB_TDP_INIT_FO_M_REG, (MXD_U8)(psDeviceProperty->m_InitFo>>8));
DDS_WriteReg( hDevice, DTMB_TDP_INIT_FO_L_REG, (MXD_U8)(psDeviceProperty->m_InitFo));
DDS_WriteReg( hDevice, DTMB_TDP_INIT_REG, 0x01 );
/* polling cyp ready interrupt */
for( i=0; i<CYP_TIMEOUT_THLD; i++)
{
cypFlag = 0;
OAL_Sleep(1);
DDS_ReadRegFields( hDevice, DTMB_TDP_INT_STATUS_REG, MXD_BIT0, 1, ®Val );
if( 1 == regVal )/* Ofo ready */
{
cypFlag = 1;
break;
}
else
{
cypFlag = 0;
}
}
if( 1 == cypFlag )
{
DDS_WriteReg( hDevice, DTMB_TDP_INT_CLEAR_REG, 0x01 );
DDS_ReadReg( hDevice, DTMB_TDP_OFO_VALUE_H_REG, &ofoValH );
DDS_ReadReg( hDevice, DTMB_TDP_OFO_VALUE_L_REG, &ofoValL );
if( ofoValH & DTMB_TDP_OFO_VALUE_MINUS_SET )
{
ofoVal = (MXD_S16)((MXD_U16)(ofoValH<<8) + (MXD_U8)ofoValL - (1 << 14));
}
else
{
ofoVal = (MXD_S16)((MXD_U16)(ofoValH<<8) + (MXD_U8)ofoValL);
}
if( ofoVal > ( frmLen/2) )/* restrict to half frame length */
{
dN[frmNum] = ofoVal - frmLen;
}
else if( ofoVal < (-frmLen/2) )
{
dN[frmNum] = ofoVal + frmLen;
}
else
{
dN[frmNum] = ofoVal;
}
if(frmNum>1)
{
if( (dN[frmNum]>dN[frmNum-1])&&(dN[frmNum]<-dN[frmNum-1]))
{
dN[frmNum] = 0;
}
}
dU = (MXD_S32)((((dN[frmNum]*4096)*(8388608/945))/( ofoLen*frmLen - dN[frmNum]))*4 +1 )/2;
duSum += dU;
if( duSum>=0 )
{
dtU = (MXD_U32)duSum;
}
else
{
dtU = (MXD_U32)( duSum + 16777216 );
}
DDS_WriteReg( hDevice, DTMB_TDP_DU_H_REG, (MXD_U8)(dtU>>16) );
DDS_WriteReg( hDevice, DTMB_TDP_DU_M_REG, (MXD_U8)(dtU>>8) );
DDS_WriteReg( hDevice, DTMB_TDP_DU_L_REG, (MXD_U8)dtU );
if( ( dN[frmNum] <= cypThd ) && ( dN[frmNum] >= -cypThd ) )
{
psDeviceProperty->m_DU = dtU;
OAL_DebugPrint( MXD_ULTRA_TRACE, "DTMB_CypCalibrate:: OK! The Value is 0x%x \n", dtU );
DDS_WriteReg( hDevice, DTMB_TDP_WORK_MODE_REG, 0x0 );
return MXD_RTN_OK;
}
}
else
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "DTMB_CypCalibrate:: Timeout!\n" );
return MXD_RTN_FAIL;
}
}/* end of for( frm number) */
return MXD_RTN_OK;
} /* end of DTMB_CypCalibrate() */
/*!
* Calitrate device UFO.
*
* \param hDevice: [in] Device handle.
*
* \Return code by MXD_RTN_CODE_E enumeration
*
* \remarks This function must be called after Init tuner, tune freq, init device, download mtx.
*
*/
MXD_RTN_CODE_E MXD_API DTMB_UfoCalibrate( IN HMXDDEV hDevice )
{
MXD_U8 regVal;
MXD_U8 ufoIdxH;
MXD_U8 ufoIdxL;
MXD_S16 ufoVal;
MXD_S32 ufoKhz[10];
MXD_S32 i;
MXD_U8 ufoFlag;
MXD_U8 ufoCount;
PDEVICE_PROPERTY_S psDeviceProperty;
PTUNER_PROPERTY_S psTunerProperty;
MXD_S32 ufoSum = 0;
psDeviceProperty = ( PDEVICE_PROPERTY_S )hDevice;
psTunerProperty = &(psDeviceProperty->m_sTuner);
ufoFlag = 0;
DDS_WriteReg( hDevice, DTMB_TDP_WORK_MODE_REG, 0x0b );
psDeviceProperty->m_InitFo = DTMB_CalcCpp( psTunerProperty->m_LifFreqKhz, psTunerProperty->m_IfRate );
for(ufoCount = 0; ufoCount<6; ufoCount++)
{
ufoFlag = 0;
/* config initial frequency offset value */
/* to be changed */
DDS_WriteReg( hDevice, DTMB_TDP_INIT_FO_H_REG, (MXD_U8)(psDeviceProperty->m_InitFo>>16));
DDS_WriteReg( hDevice, DTMB_TDP_INIT_FO_M_REG, (MXD_U8)(psDeviceProperty->m_InitFo>>8));
DDS_WriteReg( hDevice, DTMB_TDP_INIT_FO_L_REG, (MXD_U8)(psDeviceProperty->m_InitFo));
DDS_WriteReg( hDevice, DTMB_TDP_INIT_REG, 0x01 );
/* polling ufo ready interrupt */
for( i=0; i<UFO_TIMEOUT_THLD; i++)
{
OAL_Sleep(1);
DDS_ReadReg( hDevice, DTMB_TDP_INT_STATUS_REG, ®Val );
if( regVal&0x1 )/* ufo ready */
{
ufoFlag = 1;
break;
}
else
{
ufoFlag = 0;
}
}
if( 1 == ufoFlag )
{
DDS_ReadReg( hDevice, DTMB_FDP_UFO_IDX_H_REG, &ufoIdxH );
DDS_ReadReg( hDevice, DTMB_FDP_UFO_IDX_L_REG, &ufoIdxL );
if( ufoIdxH&0x08)
{
ufoVal = (MXD_S16)((MXD_U16)(ufoIdxH<<8) + (MXD_U8)ufoIdxL - 4096 );
}
else
{
ufoVal = (MXD_S16)((MXD_U16)(ufoIdxH<<8) + (MXD_U8)ufoIdxL );
}
ufoKhz[ufoCount] = (ufoVal*7560)/4096;
if((ufoKhz[ufoCount] >UFO_MAX_LIMIT)||(ufoKhz[ufoCount]<-UFO_MAX_LIMIT))
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "DTMB_UfoCalibrate :: ERROR! ufo is: %f! \n" ,ufoKhz[ufoCount]);
return MXD_RTN_FAIL;
}
if(ufoCount>0)
{
if( ufoKhz[ufoCount-1]>= 0 )
{
if( (ufoKhz[ufoCount]>ufoKhz[ufoCount-1])||(ufoKhz[ufoCount]<-ufoKhz[ufoCount-1]))
{
ufoKhz[ufoCount] = 0;
}
}
else
{
if( (ufoKhz[ufoCount]>-ufoKhz[ufoCount-1])||(ufoKhz[ufoCount]<ufoKhz[ufoCount-1]))
{
ufoKhz[ufoCount] = 0;
}
}
}
ufoSum += ufoKhz[ufoCount];
psDeviceProperty->m_InitFo = DTMB_CalcCpp( (psTunerProperty->m_LifFreqKhz-ufoSum), psTunerProperty->m_IfRate );
OAL_DebugPrint( 1, "DTMB_UfoCalibrate :: The Value is : %d ,0x%x, SUM is: %d..\n", ufoKhz[ufoCount],psDeviceProperty->m_InitFo, ufoSum );
DDS_WriteReg( hDevice, DTMB_TDP_INT_CLEAR_REG, 0xff );
if( (ufoKhz[ufoCount] <= UFO_OK_THRESHOLD)&&(ufoKhz[ufoCount] >= -UFO_OK_THRESHOLD) )
{
DDS_ReadReg( hDevice, DTMB_TDP_FID_RESULT_REG, ®Val );
if( ( regVal == 0 ) || (psDeviceProperty->m_PnType > 0x4) )
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "DTMB_UfoCalibrate :: FID result ERROR!" );
return MXD_RTN_UNDEFINED_ERR;
}
else
{
psDeviceProperty->m_PnType = regVal&0x07; /* update pntype to hDevice */
OAL_DebugPrint( MXD_ULTRA_TRACE, "DTMB_UfoCalibrate :: OK! The Pn Value is : %d ,CPP is: 0x%x, UFO sum is: %d..\n", psDeviceProperty->m_PnType,psDeviceProperty->m_InitFo, ufoSum );
return MXD_RTN_OK;
}
}
}
else
{
OAL_DebugPrint( MXD_ULTRA_TRACE, "DTMB_UfoCalibrate :: Interrupt Time out! \n" );
DDS_WriteReg( hDevice, DTMB_TDP_INT_CLEAR_REG, 0xff );
psDeviceProperty->m_InitFo = DTMB_CalcCpp( psTunerProperty->m_LifFreqKhz, psTunerProperty->m_IfRate );
return MXD_RTN_FAIL;
}
}
OAL_DebugPrint( MXD_ULTRA_TRACE, "DTMB_UfoCalibrate :: Error! \n" );
psDeviceProperty->m_InitFo = DTMB_CalcCpp( psTunerProperty->m_LifFreqKhz, psTunerProperty->m_IfRate );
return MXD_RTN_FAIL;
}/* end of DTMB_UfoCalibrate() */
/*!
* Download MTX matrix to the SDRAM address appointed.
*
* \param hDevice: [in] Device handle.
* \param sdramAddr: [in] DRAM addrss allocated for MTX table
* \param pMtxTable: [in] pointer to the table of MTX to be downloaded.
* \param mtxLen: [in] length of MTX table, unit: byte
*
* \return Return code by MXD_RTN_CODE_E enumeration
*
* \remarks null
*
*/
MXD_RTN_CODE_E MXD_API DTMB_DownloadMtx(
IN HMXDDEV hDevice,
IN MXD_U32 sdramAddr,
IN MXD_U8 *pMtxTable,
IN MXD_U32 mtxLen)
{
#ifndef __EEPROM_USED__
MXD_U32 mtxCount;
MXD_U16 rtnLen;
MXD_U32 i,j;
#endif
MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
MXD_U16 blockLen;
PDEVICE_PROPERTY_S psDeviceProperty;
PDEMOD_PROPERTY_S psDemodProperty;
PCHANNEL_PROPERTY_S psChannelProperty;
psDeviceProperty = (PDEVICE_PROPERTY_S)hDevice;
psDemodProperty = &(psDeviceProperty->m_sDemod);
psChannelProperty = &(psDemodProperty->m_sChannelProperty);
DDS_WriteReg( hDevice, DTMB_HIC_FLUSH_RELOAD_REG, 0x02 );
blockLen = psDemodProperty->m_MtxLoadLen;
#ifdef __EEPROM_USED__
eRtnCode = DTMB_LoadEeprom( hDevice, sdramAddr );
return eRtnCode;
#else
DDS_WriteReg( hDevice, DTMB_HIC_MTX_ROW_EADDR_H_REG, (MXD_U8)(sdramAddr>>8) );
DDS_WriteReg( hDevice, DTMB_HIC_MTX_ROW_EADDR_L_REG, (MXD_U8)sdramAddr );
mtxCount = mtxLen/blockLen;
/* Write MTX Table via I2C */
if( MXD_I2C_IF == psChannelProperty->m_eRegAccessType )
{
DDS_WriteReg( hDevice, DTMB_HIC_MTX_SEL_REG, 0x03 );
for( i=0; i<mtxCount; i++ )
{
((PDEVICE_PROPERTY_S)hDevice)->m_sDemod.m_sI2cProperty.m_pPIL_I2cWrite(
NULL,
((PDEVICE_PROPERTY_S)hDevice)->m_sDemod.m_sI2cProperty.m_DemodSlaveAddr,
I2C_BLOCK_BUF_ADDR,
blockLen,
pMtxTable+i*blockLen,
&rtnLen );
}
/* when mtx load over, HIC mtx select must be disabled */
DDS_WriteReg( hDevice, DTMB_HIC_MTX_SEL_REG, 0x00 );
return MXD_RTN_OK;
}
else /* Write MTX Table via SPI */
{
DDS_WriteReg( hDevice, DTMB_HIC_SDRM_DIR_ENABLE_REG, 0x01 );
DDS_WriteReg( hDevice, DTMB_HIC_SDRM_DIR_ADDR_H_REG, (MXD_U8)(sdramAddr>>8) );
for( i=0; i<mtxCount; i++ )
{
DDS_WriteReg( hDevice, DTMB_HIC_SDRM_DIR_ADDR_M_REG, (MXD_U8)i );
for( j=0; j<256; j++ )
{
DDS_WriteReg( hDevice, DTMB_HIC_SDRM_DIR_ADDR_L_REG, (MXD_U8)j );
DDS_WriteReg( hDevice, DTMB_HIC_SDRM_DIR_WR_DATA_H_REG, pMtxTable[i*512+2*j] );
DDS_WriteReg( hDevice, DTMB_HIC_SDRM_DIR_WR_DATA_L_REG, pMtxTable[i*512+2*j+1] );
DDS_WriteReg( hDevice, DTMB_HIC_SDRM_DIR_ACCESS_REG, 0x01 );
}
/* when mtx write over, sdram direct R/W must be disabled */
DDS_WriteReg( hDevice, DTMB_HIC_SDRM_DIR_ENABLE_REG, 0x00 );
}
return MXD_RTN_OK;
}
#endif
}/* end of DTMB_DownloadMtx( ) */
/*!
* Init DTMB device but not start, excluding tuner.
*
* \param hDevice: [in] Device handle
*
* \return Return code by MXD_RTN_CODE_E enumeration.
*
* \remarks
*
*/
MXD_RTN_CODE_E MXD_API DTMB_InitDevice( IN HMXDDEV hDevice )
{
MXD_RTN_CODE_E eRtnCode = MXD_RTN_OK;
MXD_S32 videoStreamThd;
PDEVICE_PROPERTY_S psDeviceProperty;
PTUNER_PROPERTY_S psTunerProperty;
PDEMOD_PROPERTY_S psDemodProperty;
MXD_U8 intCtrlVal= 0;
MXD_U8 ifType;
psDeviceProperty = ( PDEVICE_PROPERTY_S )hDevice;
psTunerProperty = &(psDeviceProperty->m_sTuner);
psDemodProperty = &(psDeviceProperty->m_sDemod);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -