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

📄 d0361_echo.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ********************************************************************* */
/* ********************************************************************* */
	void passive_monitoring_361(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, FE_361_OFDMEchoParams_t *pParams)
/* ********************************************************************* */
/* ********************************************************************* */

{
U8 loc_L1,LEP_step,LEP_ave,LEP_hold;
U16 epq;
S8 LEP_sens,LEP_start,LEP_stop,LEP_val;
unsigned short int tmp_best_EPQ_val,i;
unsigned int error;
U8 tempo;
U8 epq_auto=0;

/********* To check the status of auto epq**********/
epq_auto=STTUNER_IOREG_GetField(DeviceMap,IOHandle,AUTO_LE_EN);
if(epq_auto==1)
{
   return;
}

loc_L1 = pParams->L1s2va3vp4;
if (loc_L1==4) LEP_step = 1;

if (!STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_LOCK) )  return ;

/* programmation NON dynamique ou dynamique si Doppler */

if (loc_L1 !=4)
{
	 return;
}
SystemWaitFor(10);
LEP_val=STTUNER_IOREG_GetField(DeviceMap,IOHandle,LONG_ECHO);
if (LEP_val >=0)
	{
	LEP_sens = -1;
	LEP_start = 7;
	LEP_stop = -8;
	}
else
	{
	LEP_sens = +1;
	LEP_start = -8;
	LEP_stop = +7;
	}

/* EPQ measurements for current LEP */
LEP_hold=10;
LEP_ave=4;
SystemWaitFor(DELTA);
tmp_best_EPQ_val=0;                          
for (i=0;i<8;i++)
{
tmp_best_EPQ_val+=*(pParams->past_EPQ_val+i);
}
pParams->best_EPQ_val = (tmp_best_EPQ_val+4)/8;

/*scroll past epq values */
for (i=7;i>0;i--)
{
*(pParams->past_EPQ_val+i)=*(pParams->past_EPQ_val+i-1);
}

tmp_best_EPQ_val=0;
tempo=LEP_hold - LEP_ave;
SystemWaitFor(tempo);
epq=0;

error=STTUNER_IOREG_GetField(DeviceMap,IOHandle,LINE_OK);           
error=LEP_ave;
for (i=0;i<LEP_ave;i++)
{
epq+=Get_EPQ_361(DeviceMap,IOHandle,pParams->I2CSpeed);
/* if (epq>tmp_best_EPQ_val) tmp_best_EPQ_val = epq;*/
/*SystemWaitFor(DELTA*2);*/
error-=STTUNER_IOREG_GetField(DeviceMap,IOHandle,LINE_OK);
SystemWaitFor(DELTA);
}

/* dcdc cut 2.0 */
tmp_best_EPQ_val=(epq+ (LEP_ave>>1))/LEP_ave;


*(pParams->past_EPQ_val)=tmp_best_EPQ_val;

if (tmp_best_EPQ_val <=(pParams->EPQ_ref)) 
	{
	/*	if (tmp_best_EPQ_val <= pParams->best_EPQ_val) pParams->best_EPQ_val = tmp_best_EPQ_val;*/
		pParams->L1s2va3vp4 = 4;
		SystemWaitFor(10);
		
	}
/* addendum */
else if (tmp_best_EPQ_val>(pParams->EPQ_ref+4)) 
	{
		pParams->L1s2va3vp4 = 3;
		SystemWaitFor(10);
	}
/* end of */

else if (tmp_best_EPQ_val <=(pParams->best_EPQ_val + 5)) 
	{
	/*	if (tmp_best_EPQ_val <= pParams->best_EPQ_val) pParams->best_EPQ_val = tmp_best_EPQ_val;*/
		pParams->L1s2va3vp4 = 4;
		SystemWaitFor(10);
	}
else if (tmp_best_EPQ_val > (pParams->best_EPQ_val + 4)) 
	{
		pParams->L1s2va3vp4 = 3;
		SystemWaitFor(10);
		#ifdef LOG_EPQ
		DebugPrintf("\n pm tmp_best_EPQ_val %d  pParams->best_EPQ_val %d LEP_idx %d\n ", tmp_best_EPQ_val, pParams->best_EPQ_val,LEP_val);
		#endif
	}

if (error==LEP_ave)
{
	    pParams->L1s2va3vp4 = 2;
	    SystemWaitFor(10);
}
/*
#ifdef LOG_ECHO
fa= fopen("debug_echo.txt","a");
fprintf(fa,"pm tmp_EPQ %d  best_EPQ %d L1...%d LEP %d\n",tmp_best_EPQ_val,pParams->best_EPQ_val,pParams->L1s2va3vp4,LEP_val);
fclose(fa);
#endif
#ifdef LOG_EPQ
DebugPrintf("pm tmp_EPQ %d  best_EPQ %d L1...%d LEP %d\n",tmp_best_EPQ_val,pParams->best_EPQ_val,pParams->L1s2va3vp4,LEP_val);
#endif
*/
return;
}

/* ********************************************************************* */   
/* ********************************************************************* */
void active_monitoring_361(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, FE_361_OFDMEchoParams_t *pParams)
/* ********************************************************************* */
/* ********************************************************************* */   

{

U8 loc_L1,LEP_step,LEP_ave,LEP_hold;
S8 LEP_sens,LEP_start,LEP_stop,LEP_val,LEP_idx;
unsigned short int tmp_best_EPQ_val,tmp_min_EPQ_val,i,try;
U16 epq;
U8 tempo;
unsigned short int last_epq;

U8 epq_auto=0;

/********* To check the status of auto epq**********/
epq_auto=STTUNER_IOREG_GetField(DeviceMap,IOHandle,AUTO_LE_EN);
if(epq_auto==1)
{
   return;
}

loc_L1 = pParams->L1s2va3vp4;
if (loc_L1 !=3)
{
	 return;
}

	
if (!STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_LOCK)) return;

#ifdef LOG_EPQ
DebugPrintf("\n\nactive monitoring \n");
#endif

SystemWaitFor(10);
/* programmation core dynamique */

STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_CHC_CTL1,0xB1);
STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_CRL_CTL,0x4F);
STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_CAS_CTL,0x40);
STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_FREESTFE_1,0x03);
STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_AGC_CTL,0x18);


/* end prog core dynamique */

LEP_step =4;

LEP_val=STTUNER_IOREG_GetField(DeviceMap,IOHandle,LONG_ECHO);
/*LEP_val = 0; fine adjustment*/

if (LEP_val >=0)
	{
	LEP_sens = -1;
	LEP_start = 7;
	LEP_stop = -8;
	}
else
	{
	LEP_sens = +1;
	LEP_start = -8;
	LEP_stop = +7;
	}
	

/* EPQ measurements for different  LEP_val */
tmp_min_EPQ_val = 255;
LEP_idx = LEP_val; 
LEP_hold=8;
LEP_ave=4;
/* SystemWaitFor(500); */
try=0;
/*while (try <4)*/

#ifdef LOG_EPQ
if (!STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_LOCK))
{
wd=80;
}
#endif


#ifdef LOG_EPQ
DebugPrintf(" initial eqp %d \n",LEP_idx);
#endif	

last_epq=0;
tempo= (LEP_hold - LEP_ave) * DELTA;
while ( ( (try<2) || (last_epq==1) )  && (STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_LOCK) ) )
{

STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_idx);

SystemWaitFor( tempo );
tmp_best_EPQ_val=0;
epq=0;
	for (i=0;i<LEP_ave;i++)
	{
	epq+=Get_EPQ_361(DeviceMap,IOHandle,pParams->I2CSpeed);
	SystemWaitFor(DELTA); 
	}

tmp_best_EPQ_val=(epq+(LEP_ave>>1))/LEP_ave;
		
			#ifdef LOG_EPQ
			DebugPrintf(" tmp_best_eqp %d",tmp_best_EPQ_val);
			DebugPrintf(" LEP_idx %d    break \n",LEP_idx);			
			#endif	
			
/* dcdc cut 2.0 tmp_best_EPQ_val=(tmp_best_EPQ_val+(LEP_ave>>1))/LEP_ave;*/
/*DebugPrintf("\n LEP %d  EPQ_val = %d\n",LEP_idx,tmp_best_EPQ_val);*/

	/* if ((tmp_best_EPQ_val- pParams->best_EPQ_val)<=4)*/ /*dcdc*/ 
	
	if ( ((tmp_best_EPQ_val- pParams->best_EPQ_val)<=5) && (tmp_best_EPQ_val <=(pParams->EPQ_ref+1)) )/*dcdc*/ 
		{
		pParams->best_EPQ_val = tmp_best_EPQ_val;
		pParams->best_EPQ_val_idx=LEP_idx;
		pParams->L1s2va3vp4 = 4;
		try=0;
		
		break;
		}
	
	else
		{
			
		if (tmp_best_EPQ_val <=(tmp_min_EPQ_val)) 
			{
			tmp_min_EPQ_val = tmp_best_EPQ_val;
			}

			LEP_idx= LEP_idx + LEP_sens*LEP_step;
			
			if (LEP_idx >= 7)
				{
				LEP_idx = 7;
				LEP_sens = -1;
				LEP_step=4;
				try++;
			



				}
			else if (LEP_idx <=-8)
				{
				LEP_idx = -8;
				LEP_sens = 1;
				LEP_step=4;
				}

		if ( (try==2) && (LEP_idx==7)) last_epq=1;
		else last_epq = 0;
		
		if (tmp_best_EPQ_val > (pParams->best_EPQ_val + 2)) 
			{
			pParams->L1s2va3vp4 = 3;
			}

		}
} /* end of while */

	#ifdef LOG_EPQ
	DebugPrintf("try %d  ",try);
	DebugPrintf ("%d  %d \n",pParams->best_EPQ_val,pParams->best_EPQ_val_idx);
	#endif

if (try>1) 	
{
pParams->L1s2va3vp4 = 1;
}
else				
{
pParams->L1s2va3vp4 = 4;
}
#ifdef LOG_ECHO
fa= fopen("debug_echo.txt","a");
fprintf(fa,"am %d  tmp_EPQ %d trial %d LEP %d L1...%d \n",loc_L1,tmp_best_EPQ_val,try,LEP_idx,pParams->L1s2va3vp4);
fclose(fa);
#endif


return;
}



/* ********************************************************************* */
void Ack_long_scan_361(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle)
/* ********************************************************************* */

{

U8 LEP_step,LEP_hold,LEP_ave;
U16 epq;
U8 tempo;

S8 current_LEP, LEP_idx;
S8 LEP_sens,LEP_start,LEP_stop;

unsigned short int i;
unsigned short int EPQ_val;
unsigned short int best_EPQ_val,bad_EPQ_val;
short int best_EPQ_val_idx;
U8 epq_auto=0;

/********* To check the status of auto epq**********/
epq_auto=STTUNER_IOREG_GetField(DeviceMap,IOHandle,AUTO_LE_EN);
if(epq_auto==1)
{
   return;
}


LEP_step=3;

/* end prog core dynamique */
current_LEP=STTUNER_IOREG_GetField(DeviceMap,IOHandle,LONG_ECHO);
if (current_LEP >= 0)
	{
	LEP_sens=-1;
	LEP_start=7;
	LEP_stop=-8;
	}
else
	{
	LEP_sens=1;
	LEP_start=-8;
	LEP_stop=7;
	}
LEP_ave=4;
LEP_hold=8;


/* re_find  start position */
LEP_idx=current_LEP;
while (LEP_idx!=LEP_start)
{
LEP_idx-=LEP_sens*LEP_step;
if ( (LEP_idx*sign_361(LEP_start))> abs(LEP_start)) LEP_idx = LEP_start;
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_idx);
SystemWaitFor(DELTA); /* delay to be defined*/
}


/* EPQ measurements for different LEP_val*/
LEP_idx=LEP_start-(LEP_sens * LEP_step);
best_EPQ_val=255;
tempo=(LEP_hold-LEP_ave) * DELTA;
do
{

LEP_idx+=(LEP_sens * LEP_step);

if ( (LEP_idx*sign_361(LEP_stop))> abs(LEP_stop)) LEP_idx = LEP_stop;

STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_idx);
SystemWaitFor( tempo );
	EPQ_val=0;

	bad_EPQ_val = 0;
	epq=0;
	for(i=0;i<LEP_ave;i++)
		{
		epq+=Get_EPQ_361(DeviceMap,IOHandle,0);
/*		if (epq>EPQ_val) EPQ_val=epq;  */
		SystemWaitFor(DELTA);/*wait 1(DELTA for debug)  symbol(s)*/
		}
	
	EPQ_val=(epq+(LEP_ave>>1))/LEP_ave;

/* search best LEP and its index */
	if (EPQ_val<=best_EPQ_val) 
			{
			best_EPQ_val=EPQ_val;
			best_EPQ_val_idx=LEP_idx;
			}
} while (LEP_idx!=LEP_stop);


/* re-find best longechoprotection position */
LEP_sens = -LEP_sens;
/* LEP is in LEP_stop following the previous loop */

for (LEP_idx=LEP_stop;LEP_idx!=best_EPQ_val_idx;LEP_idx+=(LEP_step*LEP_sens) ) 
	{
	STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_idx);
	SystemWaitFor(DELTA);	/*wait 500 symbols*/
	}
	STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_idx);

return;
}	


/* ********************************************************************* */
void Dlong_scan_361(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle)
/* perform a along scan based on BER values								 */
/* ********************************************************************* */

{

S8  lep;
S8  i,ii;
U8  LEP_hold;
S8  LEP_stop,LEP_sense,LEP_start;
U8  mode,mode_BER;
U32 error;
U16 SNR_min;
S8  SNR_min_pos;
S8  best_EPQ_pos;
U8  tempo;



mode_BER=STTUNER_IOREG_GetRegister(DeviceMap,IOHandle,R_ERRCTRL3);
STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_ERRCTRL3,0x93);

lep= STTUNER_IOREG_GetField(DeviceMap,IOHandle, LONG_ECHO);
mode=STTUNER_IOREG_GetField(DeviceMap,IOHandle,SYR_MODE);
SNR_min=0;
LEP_hold=8;
if (lep >=0)
	{
		LEP_stop=7;
		LEP_sense=1;
		LEP_start=-8;
	}
else
	{
		LEP_stop=-8;
		LEP_sense=-1;
		LEP_start=7;
	}
	
/* find start position */	
tempo=	LEP_hold>>(2 - 2*mode);
for (i=lep;i!=LEP_stop;i+=LEP_sense)
	{
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,i);
		SystemWaitFor(tempo);
	}
	
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_stop);
		SystemWaitFor(tempo);

/* compute values for LEP */

for (i=LEP_stop;i!=LEP_start;i-=LEP_sense*3)
	{
	STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,i);
	error=0;
	for (ii=0;ii<8;ii++) error += STTUNER_IOREG_GetField(DeviceMap,IOHandle,CHC_SNR);
	
	if (error	> SNR_min)
		{
			SNR_min=error;
			SNR_min_pos=i;
		}
	}
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_start);

	error=0;
	for (ii=0;ii<8;ii++) error += STTUNER_IOREG_GetField(DeviceMap,IOHandle,CHC_SNR);
	
	if (error	> SNR_min)
		{
			SNR_min=error;
			SNR_min_pos=i;
		}
		
	best_EPQ_pos=SNR_min_pos;
	tempo=1<<(2*mode);
	for (i=LEP_start;i!=best_EPQ_pos;i+=LEP_sense)
		{
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,i);
		SystemWaitFor(tempo);
		}
		STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,best_EPQ_pos);		
	
}



#endif

⌨️ 快捷键说明

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