d0362_drv.c

来自「st7710的tuner标准驱动」· C语言 代码 · 共 1,232 行 · 第 1/3 页

C
1,232
字号
			Rtrlctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R0362_TRL_CTL);
		
		 	trl_ctl[0]=(Rtrlctl & 0x7f)| (M8_F_TRL_NOMRATE0<<7);
		 	trl_ctl[1]=M8_F_TRL_NOMRATE8_1;
		 	trl_ctl[2]=M8_F_TRL_NOMRATE16_9;
			
			STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R0362_TRL_CTL,trl_ctl,3);
			
			if (pSearch->IF_IQ_Mode == FE_362_NORMAL_IF_TUNER)
			{
				Rgain=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R0362_GAIN_SRC1);
				gain_src[0]=(Rgain & 0xf0) |M8_GAIN_SRC_HI;
				gain_src[1]=M8_GAIN_SRC_LO;
				
				STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R0362_GAIN_SRC1,gain_src,2); 
			}
			else
			{
				
				Rgain=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R0362_GAIN_SRC1);
				gain_src[0]=(Rgain & 0xf0) |M8_E_GAIN_SRC_HI;
				gain_src[1]=M8_E_GAIN_SRC_LO;
				
				STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R0362_GAIN_SRC1,gain_src,2); 
				
			}

		}
		
	}
	else	
		/****************/
           {    
           	STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R0362_GAIN_SRC1,0x5f);   /*RF4K work around*/        	
            	Rgain=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R0362_GAIN_SRC1);            	
		gain_src[0]=(Rgain & 0xf0) |0x0f;
		gain_src[1]=0x3c;
	      	
	       STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R0362_GAIN_SRC1,gain_src,2);
	     
	    
	   	       
	       Rtrlctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R0362_TRL_CTL);
		
		 	trl_ctl[0]=(Rtrlctl & 0x7f)| (0x01<<7);
		 	trl_ctl[1]=0x83;
		 	trl_ctl[2]=0x61;
	       STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R0362_TRL_CTL,trl_ctl,3);
	         
	         inc_derot[0]=0x40;
	      	inc_derot[1]=0x00;
	               
               STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R0362_INC_DEROT1,inc_derot,2);   
             
              
              }                                          
		/*************/
			
		pSearch->EchoPos   = pSearch->EchoPos;
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_LONG_ECHO,pSearch->EchoPos);
	

                error = (TunerInstance->Driver->tuner_SetFrequency)(TunerInstance->DrvHandle,(U32)pSearch->Frequency,(U32 *)&pSearch->Frequency);	
               
                
               	       
               	                    	     
               	if (TunerInstance->Driver->ID != STTUNER_TUNER_DTT7592)
               	   {
               	          FE_362_WaitTuner(TunerInstance,100,&TunerLocked);		/*	Is tuner Locked	? (wait 100 ms maxi)	*/  
		   }
		
		if((error != ST_NO_ERROR) || (TunerLocked ==FALSE) )
		{
			
			return(FE_362_SEARCH_FAILED);
			
		}
		
	       /*Error handling here Is it okay? */
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_VTH0,0x1E);
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_VTH1,0x14);
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_VTH2,0xF);
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_VTH3,0x9);
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_VTH4,0x0);
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_VTH5,0x5);

		STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R0362_PR,0xAF);
		STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R0362_VSEARCH,0x30);
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_FORCE,(pSearch->Force & 1) );
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_FRAPTCR,1);
	

	
	if  ((pSearch->Inv == STTUNER_INVERSION_NONE))
	{
	
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_INV_SPECTR,(pSearch->IF_IQ_Mode==0));	
		Instance->ResultSpectrum = (pSearch->IF_IQ_Mode == FE_362_NORMAL_IF_TUNER)?STTUNER_INVERSION: STTUNER_INVERSION_NONE;
	}				
					
	
	else if  (pSearch->Inv == STTUNER_INVERSION) 									
	{
	
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_INV_SPECTR,!(pSearch->IF_IQ_Mode==0));
		Instance->ResultSpectrum = (pSearch->IF_IQ_Mode == FE_362_NORMAL_IF_TUNER)?STTUNER_INVERSION_NONE: STTUNER_INVERSION;
	}
				
	else if ((pSearch->Inv == STTUNER_INVERSION_AUTO)||((pSearch->Inv == STTUNER_INVERSION_UNK)&& (!Params->first_lock)) )									
	{
				
		if (Params->Sense==1) 
		   {
			STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_INV_SPECTR,!(pSearch->IF_IQ_Mode==0));
			Instance->ResultSpectrum = (pSearch->IF_IQ_Mode == FE_362_NORMAL_IF_TUNER)?STTUNER_INVERSION_NONE: STTUNER_INVERSION;
		   }
		else
		   {
			STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_INV_SPECTR,(pSearch->IF_IQ_Mode==0)); 
			Instance->ResultSpectrum = (pSearch->IF_IQ_Mode == FE_362_NORMAL_IF_TUNER)? STTUNER_INVERSION : STTUNER_INVERSION_NONE;
		   }
	}	
				
		
				
	   	if((pResult->SignalStatus = FE_362_Algo(DeviceMap, IOHandle,pSearch,TopLevelHandle)) == LOCKOK_362)
		{
			pResult->Locked = TRUE;
			
			/* update results */
						
			
			/***********  dans search term auparavant **********/
			STTUNER_IOREG_GetContigousRegisters(DeviceMap, IOHandle,R0362_TPS_RCVD2,3,tps_rcvd);
			STTUNER_IOREG_GetContigousRegisters(DeviceMap, IOHandle,R0362_SYR_STAT,1,syr_stat);				
			
			pResult->Mode=(syr_stat[0]&0x04)>>2;
			
			
			pResult->Guard=syr_stat[0]&0x03;
			
			
			constell = tps_rcvd[0] & 0x03;
			if (constell == 0) 
			{
				pResult->Modulation = STTUNER_MOD_QPSK;
			}
			else if (constell==1) 
			{
				pResult->Modulation= STTUNER_MOD_16QAM;
			}
			else
			{
				 pResult->Modulation= STTUNER_MOD_64QAM;
			}
		
			
			pResult->hier  =tps_rcvd[0];
			
			
			pResult->Hprate=tps_rcvd[1] & 0x07;
			
			
			pResult->Lprate=(tps_rcvd[1] &0x70)>>4;
			
			constell = STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_PR);
			if (constell == 5)	
			{
				constell = 4;
			}
				pResult->pr = (FE_362_Rate_t) constell;
				
			/*This part of code is disabled as next cut of 362 will do spectrum
			  inversion automatically. So it will not be possible to know whether spectrum
			  is inverted or not?*/

			
			
			Params->first_lock=1;
				
			STTUNER_IOREG_GetContigousRegisters(DeviceMap, IOHandle,R0362_AGC2MAX,13,agc2max);
			
                     pResult->Agc_val=	(agc2max[9]<<16) 	+  
									((agc2max[10]&0x0f)<<24) +
									agc2max[11] +  
									((agc2max[12]&0x0f)<<8);
		
                       STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_FREEZE,1);								  
	               STTUNER_IOREG_GetContigousRegisters(DeviceMap,IOHandle,R0362_CRL_FREQ1,3,crl_freq);
	               STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_FREEZE,0);	
	          
	              
	       		 CrlRegVal = (crl_freq[2]<<16) ;
	               CrlRegVal+= (crl_freq[1] <<8);
	               CrlRegVal+= crl_freq[0];
	          
	          
	               offset = (CrlRegVal > 8388607)?(CrlRegVal - 16777216):CrlRegVal;/*2's complement negative value*/
	
	               offset *=2; /*Actual value should be multiplied by 2*/
	
		
	               STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R0362_SYR_STAT);
	         
	        
	               offset=((offset*11)/10)*4/(FE_362_Pow(4,STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_SYR_MODE))*16384);/*oroginally fieldgetval*/


                       if((offset >  150) && ( offset  <  - 150)) /*This check is to after considering
                    					      the tuner step size*/
                       {
                         pSearch->Frequency+=offset;
                         
                       }
                        pResult->Frequency=pSearch->Frequency;	
	          	
	          	
			pResult->Echo_pos=STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_LONG_ECHO);
			
	
	                /*TRL Normrate algorithm needs to be checked*/
			 /* fine tuning of timing offset if required */
			
			
			STTUNER_IOREG_GetContigousRegisters(DeviceMap,IOHandle,R0362_TRL_CTL,5,trl_ctl1);
			timing_offset=trl_ctl1[3]+ 256*trl_ctl1[4];
			  
			if (timing_offset>=32768) timing_offset-=65536;
			trl_nomrate=  (512*trl_ctl1[2]+trl_ctl1[1]*2 + ((trl_ctl1[0]&0x80)>>7));
			timing_offset=((signed)(1000000/trl_nomrate)*timing_offset)/2048;
			 
			if (timing_offset<=0) 
				{
				timing_offset=(timing_offset-11)/22;
				step=-1;
				}
			else
				{
				timing_offset=(timing_offset+11)/22;
				step=1;
				}
			for (counter=0;counter<abs(timing_offset);counter++)
				{
					trl_nomrate+=step;
					Rtrlctl=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R0362_TRL_CTL);
					trl_ctl2[0]=((trl_nomrate%2)<<7) | (Rtrlctl & 0x7f) ;
					trl_ctl2[1]=trl_nomrate/2;
					
					STTUNER_IOREG_SetContigousRegisters(DeviceMap,IOHandle,R0362_TRL_CTL,trl_ctl2,2);
					WAIT_N_MS_362(1);
				}	
				
			
			}
			else
			{
				pResult->Locked = FALSE;
				error = FE_362_SEARCH_FAILED;
			}
		
		
	return error;
}

/*----------------------------------------------------
FUNCTION    :  FE_362_GetNoiseEstimator  
ACTION :
PARAMS IN :
PARAMS OUT :
RETURN :
------------------------------------------------------*/
void FE_362_GetNoiseEstimator(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, U32 *pNoise, U32 *pBer)
{
short unsigned int  source,prf;
U32                 quoz,error;
U32 snr=0;

error  = STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_ERROR_COUNT1_LO);
error += STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_ERROR_COUNT1_HI) * 256; 
error  = error*100;

quoz=1;
if (!STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_ERRMODE1))
{
source=STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_ERR_SOURCE1); 
quoz=FE_362_PowOf2(12+2*(STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_NUM_EVENT1)));

switch (source)
{
case 0:
quoz=quoz*8;
prf=STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_PR);

switch(prf)
{
case 0:
error=(U32)(error*(1/2)); /*gbgbcast*/ 
break;

case 1:
error=(U32)(error*(2/3)); /*gbgbcast*/ 
break;

case 2:
error=(U32)(error*(3/4)); /*gbgbcast*/ 
break;

case 3:
error=(U32)(error*(5/6)); /*gbgbcast*/ 
break;

case 4:
error=(U32)(error*(6/7)); /*gbgbcast*/
break;

case 5:
error=(U32)(error*(7/8)); /*gbgbcast*/ 
break;

default:
error=error;
break;

}
break;

case 1:
quoz=quoz*8;
break;

case 2:
break;

case 3:
error=error*188;
break;

default:
error=error;
break;
}
}

snr=STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_CHC_SNR);


/**pNoise = (snr*10) >> 3;*/
/**  fix done here for the bug GNBvd20972 where pNoise is calculated in right percentage **/
*pNoise=((snr/8)*100)/32;
*pBer   = error*(100000000/quoz); /**** (error/quoz) gives my actual BER . We multiply it with
                                        10*e+8 now and 10*e+2 before for scaling purpose so that we can send a integer 
                                        value to application user . So total scaling factor is 10*e+10*****/  
return;
}



/*********************************************************
--FUNCTION	::	FE_362_Tracking
--ACTION	::	Once the chip is locked tracks its state
--PARAMS IN	::	period/duration of tracking in seconds
			::	Handle to Chip
--PARAMS OUT::	NONE
--RETURN	::	NONE
--********************************************************/
void FE_362_Tracking(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle,U32 *UnlockCounter)
{

 if ((!STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_LK)))
  {
    *UnlockCounter +=1;
  }
 else
  {
    *UnlockCounter =0;
    return;
  }
 if (*UnlockCounter >2 )   
 {   

	if (!STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_TPS_LOCK) || (!STTUNER_IOREG_GetField(DeviceMap,IOHandle,F0362_LK))  )      
		{
			 STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_CORE_ACTIVE,0);
			 WAIT_N_MS_362(2);
			 STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0362_CORE_ACTIVE,1);
			 WAIT_N_MS_362(200);
		}
}
			
	return;


}				















⌨️ 快捷键说明

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