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

📄 dtv_c.c

📁 杭州国芯dvb-c解码芯片gx1001p芯片驱动程序源代码
💻 C
字号:
/****************************************
 *				                                                 *
 *  GX1001 v1.2 demo driver  for XIMEI DTCISA8*	*
 ****************************************/

#define WRITE	1
#define READ  	0
#define TRUE	       1
#define FALSE	0

/*=============================================================================================================
*/

/* Function: Write a byte size value to chip
// Input:
//	RegAdddress -- The register address
//	WriteValue  -- The write value
*/
void GX_Write_A_Byte(int RegAddress,int WriteValue)
{

	unsigned char data[2];
	int UCtmp=-1;
	unsigned int ChipAddress ;
	
	ChipAddress  = GX_CHIP_ADDRESS;
	
	data[0] = (unsigned char)RegAddress;
	data[1] = (unsigned char)WriteValue; 
	

	UCtmp = I2cReadWrite( WRITE, ChipAddress,data, 2 );

/*
	IIC_Start();
	IIC_Send_A_Byte(CHIP_ADDRESS);
	IIC_Send_A_Byte(RegAddress);
	IIC_Send_A_Byte(WriteValue);
	IIC_Stop();
	*/
}



/* Function: Read a byte size value from chip
// Input:
//	RegAdddress -- The register address
// Output:
//	Read value
*/
int GX_Read_A_Byte(int RegAddress)
{

	unsigned int ChipAddress;
	unsigned char data[1];



	data[0] = (unsigned char)RegAddress;
	ChipAddress=GX_CHIP_ADDRESS;
	
	/*IO access*/

	I2cReadWrite( WRITE, ChipAddress,data, 1 );
	I2cReadWrite( READ, ChipAddress,data, 1 );

  	return(data[0]) ;


/*
	int temp;

	IIC_Start();
	IIC_Send_A_Byte(CHIP_ADDRESS&0xfe);
	IIC_Send_A_Byte(RegAddress));
	IIC_Start();
	IIC_Send_A_Byte(CHIP_ADDRESS|0x01);
	temp=IIC_Receive_A_Byte_NO_ACK();
	IIC_Stop();

	return temp;
	*/
}


/********************************************************************************************/




/*Init the GX1001p */
void GX_Init_Chip(void)
{      

        GX_Write_A_Byte(GX_AGC2_THRES,0x2d);
        GX_SetTheOSCFreq(28800,36000,0);        /* set crystal frequency to  28800KHz */  
        GX_SetTheOutputMode(1);                 /* set the TS output mode to parallel */
        GX_HotReset_CHIP();
}


/*Function: Set the output mode
//Input:
//		0 - Serial
//		1 - Parallel
*/
void GX_SetTheOutputMode(int mode)
{
	int temp=0;
	temp=(GX_Read_A_Byte(GX_OUT_FORMAT)&0xbf);	/*0x90 - bit6*/
	if (mode) temp+=0x40;
	GX_Write_A_Byte(GX_OUT_FORMAT,temp);	
}



/* Function: Select the QAM size (4 - 256), only for DVB.
// Input:
//	size  -- 0-2 = reserved;
//		 3 = 16QAM;
//		 4 = 32QAM; 
//		 5 = 64QAM; 
//		 6 = 128QAM;
//		 7 = 256QAM.
*/
void GX_Select_DVB_QAM_Size(int size)
{
        int temp=0;
        size<<=5;
	temp=((GX_Read_A_Byte(GX_MODE_AGC)&0x1f)+ size);
	GX_Write_A_Byte(GX_MODE_AGC,temp);  /*0x20 - bit7:5   */
}



/* Function: Set the symbol rate value
// Input:   Symbol_Rate_Value
//          The range is from 450 to 9000	( K )
//
*/
void GX_SetTheSymbolRate(unsigned long Symbol_Rate_Value)
{
        Symbol_Rate_Value*=1000;        
	GX_Write_A_Byte(GX_SYMB_RATE_H,((int)((Symbol_Rate_Value>>16)&0xff)));	/*0x43*/
	GX_Write_A_Byte(GX_SYMB_RATE_M,((int)((Symbol_Rate_Value>>8)&0xff)));	/*0x44*/
	GX_Write_A_Byte(GX_SYMB_RATE_L,((int)( Symbol_Rate_Value&0xff)));       /*0x45*/
}


// Function: Set the frequancy parameter
// Input:   OSC_frequancy_Value (KHz) 
//          Carrier_center      (KHz) 
//          Spec_invert         : 1 - Yes, 0 - No.
void GX_SetTheOSCFreq(long OSC_frequancy_Value,long Carrier_center,int Spec_invert)
{
        unsigned long temp=0;
        int write_value=0;
        
        temp=OSC_frequancy_Value*250;  
	GX_Write_A_Byte(GX_FSAMPLE_H,((int)((temp>>16)&0xff)));       //0x40
	GX_Write_A_Byte(GX_FSAMPLE_M,((int)((temp>>8)&0xff)));        //0x41
	GX_Write_A_Byte(GX_FSAMPLE_L,((int)( temp&0xff)));            //0x42
	
	//------------------------------------------------------------------------
	
	if (Carrier_center<OSC_frequancy_Value)
	{
	        if (Spec_invert)
	                write_value=(int)(((OSC_frequancy_Value-Carrier_center)*1000)/1024);
	        else
	                write_value=(int)((Carrier_center*1000)/1024);
	}
	else
	{
	        if (Spec_invert)
	                write_value=(int)((((2*OSC_frequancy_Value-Carrier_center)*1000)/1024));
	        else
	                write_value=(int)(((Carrier_center-OSC_frequancy_Value)*1000)/1024);
	}
	
	GX_Write_A_Byte(GX_DCO_CENTER_H,(((write_value>>8)&0xff)));            //0x26
	GX_Write_A_Byte(GX_DCO_CENTER_L,(( write_value&0xff)));                //0x27
	
}





/* Function: Hot reset the Chip */
void GX_HotReset_CHIP(void)
{
	int temp;
	temp=GX_Read_A_Byte(GX_MAN_PARA);
	temp|=0x02;
	GX_Write_A_Byte(GX_MAN_PARA,temp);
}


/* Function: Cool reset the Chip */
void GX_CoolReset_CHIP(void)
{
	int temp;
	temp=GX_Read_A_Byte(GX_MAN_PARA);
	temp|=0x08;
	GX_Write_A_Byte(GX_MAN_PARA,temp);
}



/* Function: Read the OK signal for all
 Output:   1 - All OK, 0 - All Fail*/
int GX_ReadThe_ALL_OK_Signal(void)
{
	int Read_temp=0;
	Read_temp=GX_Read_A_Byte(GX_STATE_IND);         /*0x13*/
	if ((Read_temp&0xf1)==0xf1)                     /*DVB-C : 0xF1*/
		return TRUE;
	else
		return FALSE;
}


/* Function: Set the Tunner data repeater enable
// Input:	 1 - On
//		 0 - Off
*/
void GX_Set_Tunner_Repeater_Enable(int OnOff)
{
	int Read_temp;
	Read_temp=GX_Read_A_Byte(GX_MAN_PARA);

	if(OnOff)
	{
		Read_temp|=0x40;        /*Open*/
	}
	else
	{
		Read_temp&=0xbf;        /*Close*/
	}
	GX_Write_A_Byte(GX_MAN_PARA,Read_temp);
}



/*==============================================================================================
*/
/* The following 4 functions is added to get the quality and intensity of input signal */



/* convert a integer to percentage ranging form 0% to 100%  */
//Input:        value - integer
//              low   - lower limit of input,corresponding to 0%  .if value <= low ,return 0
//              high  - upper limit of input,corresponding to 100%.if value >= high,return 100
//Output:       0~100 - percentage
unsigned char GX_Change2percent(int value,int low,int high)
{
        unsigned char temp=0;
        if (value<=low) return 0;
        if (value>=high) return 100;
        temp = (unsigned char)((value-low)*100/(high-low));
        return temp;
}

/* 100LogN calculating function */
// Output = 100LogN
int GX_100Log(int iNumber_N)
{
	int iLeftMoveCount_M=0;
	int iChangeN_Y=0;
	int iBuMaY_X=0;
	int iReturn_value=0;
	long iTemp=0,iResult=0,k=0;

	iChangeN_Y=iNumber_N;
	
	for (iLeftMoveCount_M=0;iLeftMoveCount_M<16;iLeftMoveCount_M++)
	{
		if ((iChangeN_Y&0x8000)==0x8000)
			break;
		else
		{
			iChangeN_Y=iNumber_N<<iLeftMoveCount_M;
		}
	}

	iBuMaY_X=0x10000-iChangeN_Y;	//get 2's complement

	k=(long)iBuMaY_X*10000/65536;

	//iTemp= k+(1/2)*(k*k)+(1/3)*(k*k*k)+(1/4)*(k*k*k*k)
        iTemp = k + (k*k)/20000 + ((k*k/10000)*(k*33/100))/10000 + ((k*k/100000)*(k*k/100000))/400;

	//iResult=4.816480-(iTemp/2.302585);
	iResult=48165-(iTemp*10000/23025);	//4.8165 = lg2^16

	k=iResult-3010*(iLeftMoveCount_M-1);
	
	iReturn_value=(k/100);   //magnify logN by 100 times
	
	return iReturn_value;
}       
        
        
        
//Function : get the signal quality expressed in percentage,the output of this function has a range of [0,100]
unsigned char  GX_Get_SN(void)
{       
	int S_N_value=0,read_temp=0;
	int read_temp1;
	int read_temp2;
	
	read_temp1 =GX_Read_A_Byte(GX_SUM_ERR_POW_L)&0xff;      //0x51
	read_temp2 =GX_Read_A_Byte(GX_SUM_ERR_POW_H)&0xff;      //0x52
	
	if (read_temp1||read_temp2)
	{
	        read_temp = read_temp1 + (read_temp2<<8);       //SN= ar[QAM_size]-10log(read_temp) 
	        S_N_value = 493 - GX_100Log(read_temp);         //magnifid by 10 times
	}
	
	return GX_Change2percent(S_N_value,50,350);	
}       
        
        
//Function : get the signal intensity expressed in percentage,the output of this function has a range of [0,100]
unsigned char GX_Get_Signal_Strength(void)
{
        int iAGC1_word,iAGC2_word,Amp_Value;
        
        //the following parameters are specific for certain tuner
        int C0=164;
        int C1=114, A1=-7;
        int C2=189, A2=-57;
        int C3=69,  A3=4;
        int C4=148, A4=-41;
        //-----------------------------------------------
        
        
        iAGC1_word =GX_Read_A_Byte(GX_AGC1_CTRL)&0xff;      //0x2e
	iAGC2_word =GX_Read_A_Byte(GX_AGC2_CTRL)&0xff;      //0x2f
	
	Amp_Value = C0 - ((iAGC1_word-C1)*(A1-A2))/(C2-C1) - ((iAGC2_word-C3)*(A3-A4))/(C4-C3);
	
	return GX_Change2percent(Amp_Value,0,100);
}         
 
//========================================================================================================================

/*
Tuner:	Set RF frequency
unit of RF Frequnecy :KHz
If value:	36.000	MHz
PLl step:	62.5	KHz
*/
void GX_Set_RFFrequency(unsigned long fvalue)
{
        unsigned char data[5];
        unsigned long freq;
        
        
        freq=(fvalue+36000)*10/625;                     /*freq=(fvalue+36000)*/
        data[0] = 0xc0;	                                /*Tunner Address*/
        data[1] =(unsigned char)(freq>>8&0xff);	
        data[2] =(unsigned char)(freq&0xff);	
        
        data[3] = 0x86;	/*62.5KHz*/
        data[4] = 0x08;
     
        GX_Set_Tunner_Repeater_Enable(1);	/*For open the chip repeater function*/
	I2cReadWrite( WRITE, data[0], &data[1], 4 );
	/*
        IIC_Start();
        for (int i=0;i<4;i++)	IIC_Send_A_Byte(data[i]);
        IIC_Stop();
        */
        GX_Set_Tunner_Repeater_Enable(0);	/*For close the chip repeater function*/
}




/*========================================================================================================================*/

⌨️ 快捷键说明

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