DVB-C TUNER RF_ALPS_TDAE3X 驱动代码指南

DVB-C TUNER 驱动代码指南

//请参考《GX1001P软件包说明-V8.2.doc》
//Please refer to <GX1001 Software Developer Kit User's Manual_V8.2>
/*
Abbreviation
    GX		--	GUOXIN 
    IF		--	intermediate frequency
    RF		--  radiate frequency
    SNR		--	signal to noise ratio
    OSC		--	oscillate
    SPEC	--	spectrum
    FREQ	--	frequency
*/

#include "gx1001.h"
#include <stdlib.h>
#if (GX1001_TUNER==RF_ALPS_TDAE3X)

U32  GX_IF_FREQUENCY	   = 36125;	//(tuner carrier center frequency) ( Unit: KHz ) 

U16  GX_TS_OUTPUT_MODE    = 1;        // 1: Parallel output,  0: Serial output
S32  GX_RF_AGC_MIN_VALUE	=0x00; // This parameter is effective only for GX1001B
S32  GX_RF_AGC_MAX_VALUE	=0xff; // This parameter is effective only for GX1001B
S32  GX_IF_AGC_MIN_VALUE	=0x00; // This parameter is effective only for GX1001B
S32  GX_IF_AGC_MAX_VALUE	=0xff; // This parameter is effective only for GX1001B
S32  SFenable=DISABLE;//DISABLE :do not open the sf function,ENABLE:open the sf function
S32  FMenable=ENABLE;//DISABLE:do not open the fm function,ENABLE:opne the fm function
/*============ ============================================================================================================*/
/*========================================================================================================================*/
/*========================= User-defined GX1001 software interface begin =================================================*/
/*========================================================================================================================*/

/*
Function:	Delay N ms
Input:		
        ms_value - delay time (ms)
*/
void GX1001_Delay_N_ms(S32 ms_value)
{
	//User must add the delay function
	gx_timedelay_ms(ms_value); 
}

/*
Function:	Set RF frequency (Unit: KHz)
Input:
        fvalue -- RF frequency (Unit: KHz)
Output:
        SUCCESS or FAILURE
*/
GX_STATE GX_Set_RFFrequency(U32 fvalue)
{
	U8 UCtmp = FAILURE;
	unsigned char data[6];
	unsigned long freq;

	freq=(fvalue+GX_IF_FREQUENCY)*10/625;              /*freq=(fvalue+GX_IF_FREQUENCY)*/
	data[0] = 0xC0;	                                /*Tunner Address*/
	data[1] =(unsigned char)((freq>>8)&0xff);	
	data[2] =(unsigned char)(freq&0xff);	
	data[3] = 0x9B;	/*62.5KHz*/
	data[4] = 0x20;
	data[5] = 0xC6;
		
	if (fvalue < 125000) 
	{
		data[4] |= 0x80;
	}	
	else if ((fvalue >= 125000) && (fvalue<366000)) 
	{
		data[4] |= 0x82;
	}	
	else if ((fvalue >= 366000) && (fvalue<622000)) 
	{
		data[4] |= 0x48;
	}	
	else if ((fvalue >= 622000) && (fvalue<726000)) 
	{
		data[4] |= 0x88;
	}	
	else if (fvalue >= 726000) 
	{
		data[4] |= 0xC8;
	}	

	//if (SUCCESS ==  GX_Set_Tunner_Repeater_Enable(1))	/*open the chip repeater */
	{   
		GX1001_Delay_N_ms(10);
		if (SUCCESS == GXTuner_I2cReadWrite( WRITE, data[0],data[1],&data[2], 4 ))	
		{
			GX1001_Delay_N_ms(10);
			//UCtmp =  GX_Set_Tunner_Repeater_Enable(0);	/*close the chip repeater*/
		}
	}

	//if (SUCCESS == UCtmp)
	{
		GX1001_Delay_N_ms(50);
		UCtmp =  GX_HotReset_CHIP();
	}
	return UCtmp;
}



/*
Function:   Set AGC parameter
Output:
        SUCCESS or FAILURE
*/
GX_STATE GX_Set_AGC_Parameter(void)
{
	 GX_Write_one_Byte( GX_AGC_STD,23);

	int temp=0;
	temp= GX_Read_one_Byte( GX_MODE_AGC);
	if(temp!=FAILURE)
	{
		temp&=0xe6;
		temp=temp+0x10;
		 GX_Write_one_Byte( GX_MODE_AGC,temp);
	}		
	return SUCCESS;
}




/*
Function:   get the signal intensity expressed in percentage
Output:
        The signal Strength value  ( Range is [0,100] )
*/
U8 GX_Get_Signal_Strength(void)
{
    unsigned short iAGC1_word=300,iAGC2_word=300,Amp_Value;
	unsigned short agc1_temp=0,agc2_temp=0;
    
     //the following parameters are specific for certain tuner
    int C0=95;
    int C1=0xb2,	A1=20;
    int C2=204,		A2=0;
    int C3=0x8c,	A3=20;
    int C4=179,		A4=0;
    //-----------------------------------------------
        
	int i=0;

	while (i<40)
	{
		agc1_temp = GX_Read_one_Byte( GX_AGC1_CTRL);
		agc2_temp = GX_Read_one_Byte( GX_AGC2_CTRL);

		
		if ((agc1_temp>0)&&(agc2_temp>0))
		{

			//if ((((agc1_temp - iAGC1_word)<5)||((agc1_temp - iAGC1_word)>-5))&&(((agc2_temp - iAGC2_word)<5)||((agc2_temp - iAGC2_word)>-5)))
			if((abs(agc1_temp - iAGC1_word)<5)&&(abs(agc2_temp - iAGC2_word)<5))
			{
				break;
			}
			
			iAGC1_word = agc1_temp;
			iAGC2_word = agc2_temp;
		}

		GX1001_Delay_N_ms(10);
		i++;

	}

	if (i>=40) 
	{
		iAGC1_word = GX_Read_one_Byte( GX_AGC1_CTRL);
		iAGC2_word = GX_Read_one_Byte( GX_AGC2_CTRL);
	}

	if (iAGC1_word > 0xe4) iAGC1_word = 0xe4;
	Amp_Value = C0 - ((iAGC1_word-C1)*(A1-A2))/(C2-C1) - ((iAGC2_word-C3)*(A3-A4))/(C4-C3);
	return  GX_Change2percent(Amp_Value,0,100);

}         
#endif//(RF_ALPS_TDAE == GX1001_TUNER)



上一篇:字母异位词分组


下一篇:均分纸牌 洛谷