📄 mxd_porting_sharp2093.c
字号:
/*!
*
* \file mxd_porting_sharp2093.c
*
* \brief API porting for sharp tuner .
*
* C files to define the basic functions for maxscend SDK,
* which will be used in the custom application.
*
* \par Include files
* - mxd_porting_sharp2093.h
*
* \par Functions
* - MxdPorting_InitTuner
* - MxdPorting_SetFreq
* - MxdPorting_GetTunerStatus
* \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:: 169 $
* Author of last commit : $Author:: MAXSCEND\yang.liu $
* Date of last commit : $Date:: 2007-10-18 17:07:19 +0800#$
*
*
* \par Modification History
* [ Revision data author Bugzilla ID ]
* [ Description ]
*
*/
#include "mxd_porting_sharp2093.h"
/*!
* Init for tuner, including demod for tuner and tuner itself
*
* \param hDevice [ in ] Device handle
*
* \return Return code by MXD_RTN_CODE_E enumeration
*
* \remarks
*
*/
MXD_RTN_CODE_E MXD_API MxdPorting_Sharp2093InitTuner (IN HMXDDEV hDevice)
{
MXD_RTN_CODE_E eRtnCode = MXD_RTN_OK;
/*
* Setup tuner interface
*/
DDS_WriteReg( hDevice, COMMON_TIC_CONTROL_REG, SHARP_CONTROL_REG_VAL );
DDS_WriteReg( hDevice, COMMON_TIC_I2C_BIT_RATE_REG, SHARP_I2C_BITRATE_REG_VAL );
DDS_WriteReg( hDevice, COMMON_TIC_TUNER_SLAVE_ADDR_REG, SHARP_SALVE_ADDR_VAL );
DDS_WriteReg( hDevice, COMMON_TIC_HOST_ACCESS_BYTE_NUM_REG, SHARP_ACCESS_BYTE_NUM_VAL );
/* PWM setting */
DDS_WriteReg( hDevice, DTMB_TDP_PWM_INI_REG, 0x32 );/*PWM init value*/
DDS_WriteReg( hDevice, COMMON_ADC_MODE_CTRL_REG, 0xde );
DDS_WriteReg( hDevice, DTMB_TDP_PWM_CONTROL_REG, 0x44 );
DDS_WriteReg( hDevice, DTMB_TDP_PWM_CLK_STEP_REG, 0x64 );
return eRtnCode;
}/* enf of MxdPorting_InitTuner( )*/
/*!
* Tune the tuner to the frequency, this function should be used
* after MXD_TIF_InitTuner having been called.
*
* \param hDevice [ in ] Device handle
* \param freqHz [ in ] frequency to be tuned, unit: Hz
*
* \return Return code by MXD_RTN_CODE_E enumeration
*
* \remarks
*
*/
MXD_RTN_CODE_E MXD_API MxdPorting_Sharp2093SetFreq (
IN HMXDDEV hDevice,
IN MXD_U32 freqHz )
{
MXD_U32 flo; /* loacl oscillator frequency*/
MXD_U32 fclk;
MXD_U8 nref; /* reference diveder ratio*/
MXD_U32 npro; /* programmable divider ratio */
MXD_U8 cpVal;/* charge pump */
MXD_U8 bsVal;/* band setting */
MXD_U8 dividerByte1,dividerByte2;
MXD_U8 controlByte1,controlByte2,controlByte3;
MXD_U8 i;
MXD_U8 ticStatus;
MXD_U32 freqKHz;
MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
freqKHz = freqHz/1000;
fclk = 4000; /* 4MHz */
nref = 24;
flo = freqKHz + 36167;
npro = flo*nref;
npro = npro/fclk;
npro =(MXD_U16)(npro) & 0xffff;
dividerByte1= (MXD_U8)(npro>>8);
dividerByte2= (MXD_U8)npro;
/* Frequency band setting */
if( (freqHz>50500000)&&(freqHz<=146900000))
{
bsVal= 0x1;
}
else if((freqHz>=147000000)&&(freqHz<=429800000))
{
bsVal = 0x2;
}
else if((freqHz>=430000000)&&(freqHz<=858000000))
{
bsVal = 0x4;
}
/* charge pump setting */
if ( (freqHz>=147000000)&&(freqHz<=239900000) )
{
cpVal = 0x1;
}
else if( ( (freqHz>=50500000)&&(freqHz<=99900000) ) || ( (freqHz>=240000000)&&(freqHz<=309900000) ) )
{
cpVal= 0x2 ;
}
else if( ( (freqHz>=100000000)&&(freqHz<=121900000) ) || ( (freqHz>=310000000)&&(freqHz<=379900000) ) )
{
cpVal = 0x3 ;
}
else if( ( (freqHz>=122000000)&&(freqHz<=128900000) ) || ( (freqHz>=380000000)&&(freqHz<=429900000) )
|| ( (freqHz>=430000000)&&(freqHz<=577900000) ) )
{
cpVal = 0x4 ;
}
else if( ( (freqHz>=129000000)&&(freqHz<=135900000) ) || ( (freqHz>=578000000)&&(freqHz<=649900000) ) )
{
cpVal = 0x5 ;
}
else if( ( (freqHz>=136000000)&&(freqHz<=142500000) ) || ( (freqHz>=650000000)&&(freqHz<=745900000) ) )
{
cpVal = 0x6 ;
}
else if( ( (freqHz>=142600000)&&(freqHz<=146900000) ) || ( (freqHz>=745900000)&&(freqHz<=858000000) ) )
{
cpVal = 0x7;
}
controlByte2 = (MXD_U8)(cpVal<<5)|(0x10)|bsVal;
/*normal mode */
controlByte1 = 0xca;
controlByte3 = 0x80;
/* write tuner registers */
DDS_WriteReg( hDevice, COMMON_TIC_TUNER_WRDATA_D_REG, controlByte3 );
DDS_WriteReg( hDevice, COMMON_TIC_TUNER_WRDATA_C_REG, controlByte2 );
DDS_WriteReg( hDevice, COMMON_TIC_TUNER_WRDATA_B_REG, controlByte1 );
DDS_WriteReg( hDevice, COMMON_TIC_TUNER_WRDATA_A_REG, dividerByte2);
DDS_WriteReg( hDevice, COMMON_TIC_TUNER_WRADDR_REG, dividerByte1);
for( i=0; i<10; i++ )
{
eRtnCode = DDS_ReadReg( hDevice, COMMON_TIC_STATUS_REG, &ticStatus );
if(MXD_SUCCESS(eRtnCode))
{
if( ticStatus & 0x01 )
{
return MXD_RTN_OK;
}
}
}
return eRtnCode;
}/* end of MxdPorting_SetFreq( )*/
/*!
* Get tuner status. If locked, then return ok, if un-locked, then return failed.
*
* \param hDevice [ in ] Device handle
*
* \return Return code by MXD_RTN_CODE_E enumeration
*
* \remarks
*
*/
MXD_RTN_CODE_E MXD_API MxdPorting_Sharp2093GetTunerStatus (IN HMXDDEV hDevice)
{
MXD_RTN_CODE_E eRtnCode = MXD_RTN_FAIL;
MXD_U8 regVal;
MXD_U8 i;
/* Read status byte*/
for(i=0; i<200; i++)
{
DDS_WriteReg( hDevice, COMMON_TIC_TUNER_RDADDR_REG, 0x01 );
DDS_ReadReg( hDevice, COMMON_TIC_TUNER_RDDATA_A_REG, ®Val );
if( (regVal&0x50) == 0x50 )
{
return MXD_RTN_OK;
}
}
return eRtnCode;
}/* end of MxdPorting_GetTunerStatus( )*/
/*end of mxd_porting_sharp2093.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -