📄 d0361_echo.c
字号:
{
/* 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))
{
/* 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;
}
#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)
/* ********************************************************************* */
/* ********************************************************************* */
{
short int tps_lock;
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;
S16 wd;
U8 bypass_pga;
loc_L1 = pParams->L1s2va3vp4;
if (loc_L1 !=3)
{
return;
}
#ifdef LOG_EPQ
DebugPrintf("\n\nactive monitoring \n");
#endif
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=10;
LEP_ave=4;
/* SystemWaitFor(500); */
try=0;
/*while (try <4) */
tps_lock=STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_LOCK);
wd=(40<<(2*STTUNER_IOREG_GetField(DeviceMap,IOHandle,SYR_MODE)));
while((wd>=0)&&(!tps_lock))
{
SystemWaitFor(4);
tps_lock=STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_LOCK);
wd-=4;
}
#ifdef LOG_EPQ
if (!STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_LOCK))
{
wd=80;
}
#endif
while (try <2)
{
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_idx);
SystemWaitFor( (LEP_hold - LEP_ave) * DELTA);
tmp_best_EPQ_val=0;
epq=0;
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);
}
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*/
{
pParams->best_EPQ_val = tmp_best_EPQ_val;
pParams->best_EPQ_val_idx=LEP_idx;
pParams->L1s2va3vp4 = 4;
try=0;
#ifdef LOG_EPQ
DebugPrintf(" tmp_best_eqp %d",tmp_best_EPQ_val);
DebugPrintf(" LEP_idx %d break \n",LEP_idx);
#endif
break;
}
else
{
#ifdef LOG_EPQ
DebugPrintf(" tmp_best_eqp %d",tmp_best_EPQ_val);
DebugPrintf(" LEP_idx %d ",LEP_idx);
#endif
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 (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 loc_L1;
U8 LEP_step,LEP_hold,LEP_ave, tps_lock;
U16 epq;
S16 wd;
S8 LEP_val,current_LEP, LEP_idx;
S8 LEP_sens,LEP_start,LEP_stop;
S8 long_echo_protection;
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,agc_status,force,mode;
unsigned short int bypass_pga;
LEP_step=1;
/* 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 */
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=8;
LEP_hold=16;
/* 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(LEP_hold*DELTA); /* delay to be defined*/
}
/* EPQ measurements for different LEP_val*/
LEP_idx=LEP_start-(LEP_sens * LEP_step);
best_EPQ_val=255;
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( (LEP_hold-LEP_ave) * DELTA);
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;
U8 LEP_step,LEP_hold,LEP_ave;
S8 LEP_stop,LEP_sense,LEP_start;
U8 epq,tps_lock,mode,mode_BER;
U32 vect_ber[16];
U32 error;
S8 best_EPQ_pos;
U32 best_EPQ;
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);
LEP_hold=10;
if (lep >=0)
{
LEP_stop=7;
LEP_sense=1;
LEP_start=-8;
}
else
{
LEP_stop=-8;
LEP_sense=-1;
LEP_start=7;
}
for (i=lep;i!=LEP_stop;i+=LEP_sense)
{
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,i);
SystemWaitFor(LEP_hold>>(2 - 2*mode));
}
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_stop);
SystemWaitFor(LEP_hold>>(2 - 2*mode));
for (i=LEP_stop;i!=LEP_start;i-=LEP_sense)
{
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,i);
SystemWaitFor(LEP_hold>>(2 - 2*mode));
STTUNER_IOREG_SetField(DeviceMap,IOHandle,RESET_CNTR3,1);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,RESET_CNTR3,0);
SystemWaitFor(10<<(2*mode));
error= STTUNER_IOREG_GetField(DeviceMap,IOHandle,ERROR_COUNT3_LO)+
(STTUNER_IOREG_GetField(DeviceMap,IOHandle,ERROR_COUNT3_HI)*256);
if (STTUNER_IOREG_GetField(DeviceMap,IOHandle,LK) && (STTUNER_IOREG_GetField(DeviceMap,IOHandle,LINE_OK)) ) vect_ber[i+8]=error;
else vect_ber[i+8]=65535;
}
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_start);
SystemWaitFor(LEP_hold>>(2 - 2*mode));
STTUNER_IOREG_SetField(DeviceMap,IOHandle,RESET_CNTR3,1);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,RESET_CNTR3,0);
SystemWaitFor(10<<(2*mode));
error= STTUNER_IOREG_GetField(DeviceMap,IOHandle,ERROR_COUNT3_LO)+
(STTUNER_IOREG_GetField(DeviceMap,IOHandle,ERROR_COUNT3_HI)*256);
if (STTUNER_IOREG_GetField(DeviceMap,IOHandle,LK) ) vect_ber[LEP_start+8]=error;
else vect_ber[LEP_start+8]=65535;
best_EPQ=65535;
for (i=0;i<16;i++)
{
if (best_EPQ > vect_ber[i])
{
best_EPQ=vect_ber[i];
best_EPQ_pos=i-8;
}
}
for (i=LEP_start;i!=best_EPQ_pos;i+=LEP_sense)
{
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,i);
SystemWaitFor(1<<(2*mode));
}
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,best_EPQ_pos);
STTUNER_IOREG_SetRegister(DeviceMap,IOHandle,R_ERRCTRL3,mode_BER);
}
#endif
#ifdef ECHO_VER1
#ifndef ECHO_VER2
/* ********************************************************************* */
void Echo_long_scan_361(STTUNER_IOREG_DeviceMap_t *DeviceMap, IOARCH_Handle_t IOHandle, FE_361_OFDMEchoParams_t *pParams)
/* ********************************************************************* */
{
U8 loc_L1,u_var;
U8 LEP_step,LEP_hold,LEP_ave,tps_lock;
U16 epq;
S16 wd;
S8 LEP_val,current_LEP, LEP_idx;
S8 LEP_sens,LEP_start,LEP_stop;
S8 long_echo_protection;
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,agc_status,force,mode;
unsigned short int bypass_pga;
loc_L1 = pParams->L1s2va3vp4;
if ( (loc_L1!=1) && (loc_L1!=2))
{
return;
}
#ifdef LOG_EPQ
DebugPrintf("long echo ");
#endif
if (loc_L1==1) LEP_step=1;
else LEP_step=4;
/* 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 */
#ifdef LOG_EPQ
if (!STTUNER_IOREG_GetField(DeviceMap,IOHandle,TPS_LOCK))
{
wd=80;
}
#endif
/* current LEP val can be adjusted */
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=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_361(LEP_start))> abs(LEP_start)) LEP_idx = LEP_start;
STTUNER_IOREG_SetField(DeviceMap,IOHandle,LONG_ECHO,LEP_idx);
SystemWaitFor(LEP_hold); /* delay to be defined */
}
/* EPQ measurements for different LEP_val*/
LEP_idx=LEP_start-(LEP_sens * LEP_step);
best_EPQ_val=255;
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( (LEP_hold-LEP_ave) * DELTA);
EPQ_val=0;
/* best_EPQ_val_idx = 0;*/
bad_EPQ_val = 0;
epq=0;
for(i=0;i<LEP_ave;i++) /* modifs */
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -