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

📄 362_echo.c

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


/*	standard ansi includes	*/
/*#include "math.h"*/
#include "stdlib.h"
#include "chip.h"
#ifdef HOST_PC    
//#include <utility.h> 
//#include <ansi_c.h>
/*	generic includes	*/
#include "gen_macros.h"
//#include "gen_types.h"
//#include "gen_csts.h" 
#include "362_Util.h"
#include "Tuner.h" 

#else 		/* include STAPI */

#include "stlite.h"                     /* Standard includes */
#include "stddefs.h"
#include "stcommon.h"

#endif

#include "362_init.h"
#include "362_echo.h"
#include "362_drv.h"


#ifndef HOST_PC
	#define UTIL_Delay(micro_sec) task_delay((unsigned int)(((micro_sec) + 999) / 1000) * ST_GetClocksPerSecond() / 1000)
	#define  SystemWaitFor(x) UTIL_Delay((x*1000)) 
#endif

#define DELTA 2
#define MAX_EPQ_ACQ 30
//#define LOG_EPQ

unsigned int commutation=0;



S8 sign (int x)
{
 if (x>0) return 1;
 else if (x<0) return -1;
 else return 0;
}

void Echo_Init (STCHIP_Handle_t hChip, FE_OFDMEchoParams_t *pParams)
{
/***** Chiranjib*/

int epq_auto=0;
int i,data;

/********* To check the status of auto epq**********/
epq_auto= ChipGetField(hChip,AUTO_LE_EN);
if(epq_auto==1)
{
   return;
}
/****** here different epq reference value has been set in relation to FFT mode 
        modulation technique*********/
data=ChipGetField(hChip,TPS_CONST);
if (ChipGetField(hChip,SYR_MODE) ) 
{
switch(data)
{
   case 0 : /*QPSK*/
      pParams->best_EPQ_val=35;
      pParams->bad_EPQ_val=61;
      pParams->EPQ_ref=35;
      break;

   case 1 : /*16 QAM */
      pParams->best_EPQ_val=28;
      pParams->bad_EPQ_val=54;
      pParams->EPQ_ref=28;
      break;

   case 2 : /* 64 QAM */
      pParams->best_EPQ_val=24;
      pParams->bad_EPQ_val=50;
      pParams->EPQ_ref=24;
      break;

default :
      pParams->best_EPQ_val=24;
      pParams->bad_EPQ_val=50;
      pParams->EPQ_ref=24;
      break;
}/* end of switch */
}
else
{
	
switch(data)
{
   case 0 : /*QPSK*/
      pParams->best_EPQ_val=9;
      pParams->bad_EPQ_val=15;
      pParams->EPQ_ref=9;
      break;

   case 1 : /*16 QAM */
      pParams->best_EPQ_val=7;
      pParams->bad_EPQ_val=13;
      pParams->EPQ_ref=7;
      break;

   case 2 : /* 64 QAM */
      pParams->best_EPQ_val=6;
      pParams->bad_EPQ_val=12;
      pParams->EPQ_ref=6;
      break;

      default :
      pParams->best_EPQ_val=6;
      pParams->bad_EPQ_val=12;
      pParams->EPQ_ref=6;
      break;
}/* end of switch */

}



for (i=0;i<8;i++)
{
*(pParams->past_EPQ_val+i)=pParams->EPQ_ref;             
}

pParams->L1s2va3vp4 = 1;
pParams->I2CSpeed=SpeedInit(hChip);

/* init for Error counter number 3 */
/* error rate 2^16 */
data = (0<<7)+(1<<4)+(1<<2)+(2<<0);
ChipSetOneRegister(hChip,R_ERRCTRL3,data);
ChipSetField(hChip,RESET_CNTR3,0);
return;
}

int Get_EPQ(STCHIP_Handle_t hChip,U8 Speed)
{
int epq;
epq=ChipGetField(hChip,EPQ);
return epq ;
}




/* ********************************************************************* */
void Echo_long_scan(STCHIP_Handle_t hChip, FE_OFDMEchoParams_t *pParams)
/* ********************************************************************* */

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

U16 SNR_max,snr;
S8  SNR_max_pos;
S8 current_LEP, LEP_idx;
S8 LEP_sens,LEP_start,LEP_stop;

unsigned short int i;
unsigned short int  EPQ_val;
unsigned short int tmp_best_EPQ_val,best_EPQ_val,bad_EPQ_val;
short int best_EPQ_val_idx;




loc_L1 = pParams->L1s2va3vp4;

if ( (loc_L1!=1)  && (loc_L1!=2)) return;

	
 
if (!ChipGetField(hChip,TPS_LOCK)) return;
	
	ChipSetField(hChip,OP2_VAL,0);	
	ChipSetField(hChip,OP2_VAL,1);
	ChipSetField(hChip,OP2_VAL,0);	
	
	ChipSetField(hChip,OP2_VAL,0);	
	ChipSetField(hChip,OP2_VAL,1);
	

if (loc_L1==1) LEP_step=1;
else LEP_step=3;


/* current LEP val can be adjusted */

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=16;
LEP_hold=8; /* modif */ 

/* 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(LEP_hold); /* delay to be defined   */
}


/* EPQ measurements for different LEP_val*/
LEP_idx=LEP_start-(LEP_sens * LEP_step);
best_EPQ_val=255;
SNR_max=0;
bad_EPQ_val = 0;  
tempo= ( (LEP_hold-LEP_ave) * DELTA/2);
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;
	epq=0;
	snr=0;
	for(i=0;i<LEP_ave;i++)		  /* modifs */
		{
		epq+=Get_EPQ(hChip,pParams->I2CSpeed);
		snr+=ChipGetField(hChip,CHC_SNR);

		}
		EPQ_val= (epq+(LEP_ave>>1))/LEP_ave;
	*((pParams->EPQ_val+(LEP_idx+8)) ) = EPQ_val;//( (EPQ_val+(LEP_ave>>1))/LEP_ave );
	
	if (snr>=SNR_max)
		{
			SNR_max		=	snr;
			SNR_max_pos	=	LEP_idx;
		}
	
/* search best LEP and its index */
	if (EPQ_val<=best_EPQ_val) 
			{
			pParams->best_EPQ_val=EPQ_val;
			pParams->best_EPQ_val_idx=LEP_idx;       
			best_EPQ_val=EPQ_val;
			best_EPQ_val_idx=LEP_idx;
			}
	if (EPQ_val > bad_EPQ_val)  bad_EPQ_val=EPQ_val;
} while (LEP_idx!=LEP_stop);


if ((best_EPQ_val<30) && ((bad_EPQ_val-best_EPQ_val) <=4))
	 {
	 	best_EPQ_val		= 	*((pParams->EPQ_val+(SNR_max_pos+8)) );
		best_EPQ_val_idx	=	SNR_max_pos;	 	
	 }

pParams->best_EPQ_val=best_EPQ_val;
pParams->best_EPQ_val_idx=best_EPQ_val_idx;       
		
if (bad_EPQ_val <= 3) bad_EPQ_val=3;// to be detailled in future

/* 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);

if (best_EPQ_val> (pParams->EPQ_ref+1))
{
pParams->L1s2va3vp4=1;
	ChipSetField(hChip,OP2_VAL,0);	    
return;
}

/* verify best_LEP_val */

tmp_best_EPQ_val=0;
tempo=(LEP_hold)*DELTA;
WAIT_N_MS( tempo );
epq=0;
for (i=0;i<LEP_ave;i++)
{
		
	epq+=Get_EPQ(hChip,pParams->I2CSpeed);
/*	if(epq>tmp_best_EPQ_val) tmp_best_EPQ_val = epq;*/
	WAIT_N_MS(DELTA);	// wait next symbol
	
}
tmp_best_EPQ_val=(epq+(LEP_ave>>1))/LEP_ave;

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

if (best_EPQ_val>=(tmp_best_EPQ_val-5) )	 /* value to be checked */
	{
	best_EPQ_val=tmp_best_EPQ_val;
	pParams->L1s2va3vp4=4;
	}
else
	{
	pParams->L1s2va3vp4=1;
	}

pParams->best_EPQ_val=best_EPQ_val;
pParams->best_EPQ_val_idx=best_EPQ_val_idx;
pParams->bad_EPQ_val=bad_EPQ_val;


ChipSetField(hChip,OP2_VAL,0);	

for (i=0;i<abs(best_EPQ_val_idx);i++)
	{
		ChipSetField(hChip,OP2_VAL,1);
		ChipSetField(hChip,OP2_VAL,0);	
	
	}
								
								
return;
}	




/* ********************************************************************* */
/* ********************************************************************* */
	void passive_monitoring(STCHIP_Handle_t hChip, FE_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;

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

if (loc_L1 !=4) return;

LEP_val=ChipGetField(hChip,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;
WAIT_N_MS(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;
WAIT_N_MS(tempo);
epq=0;

error=ChipGetField(hChip,LINE_OK);           
error=LEP_ave;
for (i=0;i<LEP_ave;i++)
{
epq+=Get_EPQ(hChip,pParams->I2CSpeed);
/* if (epq>tmp_best_EPQ_val) tmp_best_EPQ_val = epq;*/
//WAIT_N_MS(DELTA*2);
error-=ChipGetField(hChip,LINE_OK);
WAIT_N_MS(DELTA);
}

⌨️ 快捷键说明

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