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

📄 362_echo.c

📁 STV0299 Minituner driver, for ST chipset
💻 C
📖 第 1 页 / 共 2 页
字号:

/* 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;
	}
/* addendum */
else if (tmp_best_EPQ_val>=(pParams->EPQ_ref+4)) 
	{
		pParams->L1s2va3vp4 = 3;              
	}
/* 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;
	}
else if (tmp_best_EPQ_val > (pParams->best_EPQ_val + 4)) 
	{
		pParams->L1s2va3vp4 = 3;
	}

if (error==LEP_ave)    pParams->L1s2va3vp4 = 2;
/*
#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(STCHIP_Handle_t hChip, FE_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;



loc_L1 = pParams->L1s2va3vp4;
if (loc_L1 !=3) return;
	
	
if (!ChipGetField(hChip,TPS_LOCK)) return;

/* programmation core dynamique */

ChipSetOneRegister(hChip,R_CHC_CTL1,0xB1);
ChipSetOneRegister(hChip,R_CRL_CTL,0x4F);
ChipSetOneRegister(hChip,R_CAS_CTL,0x40);
ChipSetOneRegister(hChip,R_FREESTFE_1,0x03);
ChipSetOneRegister(hChip,R_AGC_CTL,0x18);


/* end prog core dynamique */

LEP_step =4;

LEP_val=ChipGetField(hChip,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;
/* WAIT_N_MS(500); */
try=0;
//while (try <4)




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

ChipSetField(hChip,LONG_ECHO,LEP_idx);

WAIT_N_MS( tempo );
tmp_best_EPQ_val=0;
epq=0;
	for (i=0;i<LEP_ave;i++)
	{
	epq+=Get_EPQ(hChip,pParams->I2CSpeed);
	WAIT_N_MS(DELTA); 
	}

tmp_best_EPQ_val=(epq+(LEP_ave>>1))/LEP_ave;
		
			
/* 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++;
				ChipSetField(hChip,OP2_VAL,0);	
				ChipSetField(hChip,OP2_VAL,1);
				ChipSetField(hChip,OP2_VAL,0);	

				}
			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 */


if (try>1) 	
{
pParams->L1s2va3vp4 = 1;
}
else				
{
pParams->L1s2va3vp4 = 4;
}

	ChipSetField(hChip,OP2_VAL,0);   
return;
}



/* ********************************************************************* */
void Ack_long_scan(STCHIP_Handle_t hChip)
/* ********************************************************************* */

{

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;


LEP_step=3;
/* end prog core dynamique */
current_LEP=ChipGetField(hChip,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(LEP_start))> abs(LEP_start)) LEP_idx = LEP_start;
ChipSetField(hChip,LONG_ECHO,LEP_idx);
WAIT_N_MS(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(LEP_stop))> abs(LEP_stop)) LEP_idx = LEP_stop;

ChipSetField(hChip,LONG_ECHO,LEP_idx);
WAIT_N_MS( tempo );
	EPQ_val=0;

	bad_EPQ_val = 0;
	epq=0;
	for(i=0;i<LEP_ave;i++)
		{
		epq+=Get_EPQ(hChip,0);
/*		if (epq>EPQ_val) EPQ_val=epq;  */
		WAIT_N_MS(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) ) 
	{
	ChipSetField(hChip,LONG_ECHO,LEP_idx);
	WAIT_N_MS(DELTA);	//wait 500 symbols
	}
	ChipSetField(hChip,LONG_ECHO,LEP_idx);

return;
}	


/* ********************************************************************* */
void Dlong_scan(STCHIP_Handle_t hChip)
/* 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=ChipGetOneRegister(hChip, R_ERRCTRL3);
ChipSetOneRegister(hChip,R_ERRCTRL3,0x93);

lep= ChipGetField(hChip, LONG_ECHO);
mode=ChipGetField(hChip,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)
	{
		ChipSetField(hChip,LONG_ECHO,i);
		WAIT_N_MS(tempo);
	}
	
		ChipSetField(hChip,LONG_ECHO,LEP_stop);
		WAIT_N_MS(tempo);

/* compute values for LEP */

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

	error=0;
	for (ii=0;ii<8;ii++) error += ChipGetField(hChip,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)
		{
		ChipSetField(hChip,LONG_ECHO,i);
		WAIT_N_MS(tempo);
		}
		ChipSetField(hChip,LONG_ECHO,best_EPQ_pos);		
	
}


/* ********************************************************************* */   
/* ********************************************************************* */
void test_ber(STCHIP_Handle_t hChip, FE_OFDMEchoParams_t *pParams)
/* ********************************************************************* */
/* ********************************************************************* */
{
short int wd,perr,i,le;

/* latest BER evaluation */
/*if ( (pParams->best_EPQ_val * 125) < (pParams->bad_EPQ_val * 100) ) return ;*/
wd=40;
perr=0;

ChipGetField(hChip,LINE_OK);
for (i=0;i<=11;i++)
	{
	WAIT_N_MS(4);
	if (ChipGetField(hChip,LINE_OK)==0) 
		{
			perr++;
		}
	}
if (perr>=10)	
	{
			le=ChipGetField(hChip,LONG_ECHO);
			
			
	}	
return;
}




⌨️ 快捷键说明

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