nscc_tuner.c

来自「linux 下,lgs8gl5的驱动源代码,放血了,把所有的东东都弄上来了,会不」· C语言 代码 · 共 2,040 行 · 第 1/5 页

C
2,040
字号
	    TunerInit(lowTunerI2CAdr,PLLType); // init Tuner     SetTunerFreq(lowTunerI2CAdr,Freq, 8, PLLType);// set default frequency point     // init Demodulator      DemodInit(DemodParallelOutType);    return true;}//**************************************************************************// function: Set the Demodulator works in single Carrier mode // return value:  false means operation is fail, true means operation is success     //**************************************************************************int  DemodSingleCarrSet(void){    I2C_READ myi2cRead;    unsigned char ReadRet;        myi2cRead=sread(lowDemodI2CAdr, 0x7C);    if(myi2cRead.ACK_status==1)     	ReadRet=myi2cRead.read_data;    else     	return(false);    if((ReadRet & 0x80) !=0x80 )   // in Multiple Carrier mode     {       	ReadRet=(m_BYTE) (ReadRet | 0x80);        swrite(lowDemodI2CAdr, 0x7C,ReadRet);    }		    return(true);}//**************************************************************************// function: Set the Demodulator works in multiple Carrier mode // return value:  false means operation is fail, true means operation is success //**************************************************************************int  DemodMultiCarrSet(void){  	I2C_READ myi2cRead;	unsigned char ReadRet; 	myi2cRead=sread(lowDemodI2CAdr, 0x7C);	if(myi2cRead.ACK_status==1) 		ReadRet=myi2cRead.read_data;	else 		return(false);    if((ReadRet & 0x80) == 0x80 )   // in single Carrier mode 	{   		ReadRet=(m_BYTE) (ReadRet & 0x7f);         swrite(lowDemodI2CAdr, 0x7C,ReadRet);	}	return(true);}//*****************************************************************************************//  Function: wait for Demod and Tuner are locked while detecting carrier mode. //  Input: //     SupportSingleCarrier: indicate support multiple carrier, single carrier or both of them.//  Output: lock or no lock status  //***************************************************************************************** int WaitForDetect(int SupportSingleCarrier){   int ret_status;   ret_status=false;      	if( SupportSingleCarrier== MultipleCarrierOnly )     { 		if(DemodMultiCarrSet()==false) return(false); // set Demod works in Multiple Carrier mode         ret_status=DetectFEBoard();    }   	else if(SupportSingleCarrier== SingleCarrierOnly)    {        if(DemodSingleCarrSet()==false) return(false); // set Demod works in Multiple Carrier mode          ret_status=DetectFEBoard();    }  	else if(SupportSingleCarrier== BothMultipleSingle)    {		if(DemodMultiCarrSet()==false) return(false);// set Demod works in Multiple Carrier mode 		ret_status=DetectFEBoard();    	if(ret_status!=VIEW_FIND)		{         	if(DemodSingleCarrSet()==false) return(false);// set Demod works in Multiple Carrier mode           	ret_status=DetectFEBoard();  		}		    }   return(ret_status);}//*****************************************************************************************//  Function: Detect front-end board in one certain carrier mode. //  Input: None //  Output: Detect result status,  VIEW_FIND or VIEW_TIME_OUT//***************************************************************************************** int DetectFEBoard(void){    int HaveEnabledView=0;    int ret_status, LockTimes;    int DetectTimes=0;    int GIChangeTimes;        LockTimes=0;    HaveEnabledView=0;    GIChangeTimes=1;	swrite (lowDemodI2CAdr, 0x24,0x1F); //write 0x24 register with 0x1F value, liu dong, 2008/04/18     while(HaveEnabledView==0)    {		DetectTimes++;        ret_status=DetectDemodMode(GIChangeTimes);  // all other times    	if(ret_status== DetectOkOnLock )    	{        	LockTimes ++;            	printk("lockTimes=%d\n",LockTimes);		   		if( LockTimes > MaxLockTimes )	   		{ 					HaveEnabledView=1;				break;					}	   	}	   	else if(ret_status== OnProcessNoLock) 			 	   		GIChangeTimes++;	   	Sleep(200);	   	if(HaveEnabledView==0 && DetectTimes>=MaxNoLockTimes) 	   		break; // always no lock ! wait for some times  	}	if (HaveEnabledView) 	{   		ProcessOnGI595SC();   // special processing for GI595 and signal carrier   		return VIEW_FIND;	}		else	{ 		return VIEW_TIME_OUT;	}}//**************************************************************************// function: return carrier mode   // input: None // output: Carrier mode. //**************************************************************************int   GetCarrMode(void){    	I2C_READ myi2cRead;	int CarrMode=0;	myi2cRead=sread(lowDemodI2CAdr, 0x7C);  // 0x03 	if( myi2cRead.ACK_status ==1)  	{		if( (myi2cRead.read_data & 0x80) == 0x80)  			CarrMode=SingleCarrier;  //single carrier mode 		else if( (myi2cRead.read_data & 0x80) == 0x00) 			CarrMode=MultiCarrier;	}	return(CarrMode);}//**************************************************************************// function: Special Process for Single Carrier and GI595 case  // input: None// output:  process success or not    // This function shall be called when the signal is lock //**************************************************************************int  ProcessOnGI595SC(void){    int CarrMode; 	int GI_mode;    int FEC_Mode;	int condition=0;//	unsigned char Reg_0x25;   	CarrMode=GetCarrMode();	GI_mode=GetGISet();	FEC_Mode=GetFECPara();		if(Demod_8G54 != GetDemodType())	{		if(SingleCarrier==CarrMode && GI_595==GI_mode)		{		  condition= ( (FEC_Mode & 0x1c )== QAM_64 || ( (FEC_Mode & 0x1c )== QAM_32 && (FEC_Mode & 0x03 )== CR_8 ) );		  if( 1==condition )			{				if(g_TunerPLLType!=REFCLK30400)				{					swrite(lowTunerI2CAdr, 0x25, 0x42);					Sleep(100);					swrite(lowTunerI2CAdr, 0x25, 0x7D);				}				else  swrite(lowTunerI2CAdr, 0x25, 0x06);			}						condition= (  (FEC_Mode & 0x1c )== QAM_16 && (FEC_Mode & 0x03 )== CR_8  );		  if( 1==condition && g_TunerPLLType==REFCLK30400)		  {				swrite(lowTunerI2CAdr, 0x25, 0x56);		  }		  return(1);		}		else return(0);	}	else return(0);}//*****************************************************************************************//  Function: calculate DBB signal quality  //  Input: None //  Output: quality value, 100 means the best //***************************************************************************************** int   DBBSignalQuality(void){	I2C_READ myi2cRead;	int Quality=0;			myi2cRead=sread(lowDemodI2CAdr, 0x95);	if(myi2cRead.ACK_status==1) Quality=myi2cRead.read_data;	Quality = 100 - 100*Quality/255;	return Quality;}//**************************************************************************// function: Channel Scan// input : Frequency point list that need to scan. //             the list last item shall be 0 marked as end flag   //  return value are stored in FindChannel       //**************************************************************************#if 0int ChannelScan(int *ScanChannelTable){    int Freq;    int k,m;    double RSSI_val,RSSI_val_total,RSSI_val_ave;    int HaveEnabledView=0;    int FindAllProg;            k=0;        while(1)    {  		Freq = ScanChannelTable[k++];		if(Freq <= 0) break;	        SetTunerFreq(0xc2,Freq,8,REFCLK16384);   //set frequency point to tuner       	    RSSI_val_total=0;	    for(m=0;m<RSSIAveTimes;m++) // measure RSSI for RSSIAveTimes times.	    { 	   		RSSI_val= ((float)TunerRSSICalc(Freq))/100;   	     	RSSI_val_total=RSSI_val_total+RSSI_val;	     	    }	   	    RSSI_val_ave=RSSI_val_total/RSSIAveTimes;        if( RSSI_val_ave<= NoSignalThreshold )  continue;           	    if( RSSI_val_ave > NoSignalThreshold )  	    { 	   	  	DemodAutoDetectSet();				HaveEnabledView = WaitForDetect(BothMultipleSingle);					if (HaveEnabledView==VIEW_FIND) 			{		   		FindAllProg=0;                 FindProgNum=0;                while(  FindAllProg==0)   FindAllProg = GetProgramInfo();                                FindChannel[k]. ProgNum= FindProgNum;                if(FindProgNum > 0)                 {                        for(m=0;m< FindProgNum;m++)                         {		                  	FindChannel[k]. ProgID[m]= myMpegInfo[m]. m_program_id;		                  	FindChannel[k]. VideoID[m]= myMpegInfo[m]. m_video_pid;		                  	FindChannel[k]. VideoType[m]= myMpegInfo[m]. m_video_type;		                  	FindChannel[k]. AudioID[m]= myMpegInfo[m]. m_audio_pid;		                  	FindChannel[k]. AudioType[m]= myMpegInfo[m]. m_audio_type;                        }                }     						}  //end of searching Program 				 	 		   	} // end of Detect signal and program searching 	   	}  // end of scan all channels in List 	  	return 1;}#endif//**************************************************************************// function: Delay msNum millisecond // input : msNum - delay time, in millisecond unit // Note: User shall design it according to processor processing speed//**************************************************************************void Sleep(int msNum){   int k;    k = msNum*1000;	while(k > 0) k--;	return;}//**************************************************************************// function: I2C bus Read operation  // input : target -- Device address //         addr   -- register address // output: Read result, include read data and ACK status  // Note: User shall implement this function according to real application platform//**************************************************************************I2C_READ sread(m_BYTE target , m_BYTE addr){	I2C_READ res;	int dev_addr;	int reg_addr;	char dat[2];	dev_addr = (target >> 1);	reg_addr = addr ;	dat[0] = reg_addr;	davinci_i2c_write (1, dat, dev_addr); 		davinci_i2c_read (1,dat,dev_addr);		res.ACK_status = 1;	res.read_data  = dat[0];		return (res);}//**************************************************************************// function: I2C bus write operation  // input : target -- Device address //         addr   -- register address //         data   -- write data // output: Read result, include read data and ACK status// Note: User shall implement this function according to real application platform//**************************************************************************void swrite(m_BYTE target, m_BYTE addr,m_BYTE data){	int dev_addr ;	int reg_addr ;	char dat[2];	dev_addr = (target >> 1);	reg_addr = addr ;	dat[0] = reg_addr;	dat[1] = data;	davinci_i2c_write (2, dat, dev_addr);  }//**************************************************************************// function: Get TV program information // input : None// Return: have got program information or not//**************************************************************************int GetProgramInfo(void){	return 1;}                  ////////////////////////////////////////////app///////////////////////////*******case TUNER_SET_REG:			ptr = (unsigned int *)arg;			swrite(*ptr, *(ptr + 1),*(ptr + 2));			res = 0;			break;case TUNER_GET_REG:						ptr = (unsigned int *)arg;						dat = sread((unsigned char)*ptr, *(ptr + 1));			*(ptr + 2) = dat.read_data;			res = 0;			break;dev/tunerswrite(target, addr, data);int arg[3]; //arg[0] target arg[1]=addr arg[2]= dataioctl(fd,TUNER_SET_REG,arg);****/#define DEFAULT_FRQ  			666#define DEFAULT_BANDWIDTH	 	8static int tuner_init(void){	int res = -1;	res = FrontEndBoardInit(DEFAULT_FRQ, REFCLK16384, 0);	if (res != false)	{		//Sleep(1000);		SetTunerFreq(lowTunerI2CAdr, DEFAULT_FRQ, DEFAULT_BANDWIDTH, REFCLK16384);				DemodAutoDetectSet();				if (WaitForDetect(MultipleCarrierOnly) == VIEW_FIND)		{			printk("signal is lock\n");			}		else		{			printk("signal is not lock\n");			}	}	else	{		printk("warning : tuner or Demod not install!!!\n");	}			return 0;}

⌨️ 快捷键说明

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