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

📄 user_if.c

📁 三星公司的有线数字高频头资料及源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
			  compute_pll_div(fval,&ival,&qval);
			  qam_write(SB_RW,SB_STOSCM,0x1a,0);
			  qam_write(MB_W ,MB_STOSC1,ival << 8,0);
			  qam_write(MB_W ,MB_STOSC2,qval << 8,0);
			}
			else
			  if (strncmp(argv[1],"tuner_type",10) == 0) {
			    if (strcmp(argv[2],"temic") == 0) {
			       qam_status.tuner_used = SINGLE;
			    }
			    else
				if (strcmp(argv[2],"siel") == 0) {
				   qam_status.tuner_used = DOUBLE;
				}
			      else
					printf("Unknown tuner_type '%s'\n",argv[2]);
			  }
			  else {
			    printf("Unknown parameter '%s'\n",argv[1]);
			  }
	break;

      case SHELL_TUNE:
	for (cp = argv[1]; *cp != '.' && *cp != '\0'; cp++) ;
				if (*cp == '.') {
					sscanf(argv[1],"%f",&fval);
				}
	else {
					sscanf(argv[1],"%d",&ival);
				  if (ival > 0 && ival <= MAX_CHANNEL) {
						fval = 2.0 + c6m_freq_map[ival - 1];
				  }
	}
				tuner_freq(fval);

#if 0
				tuner_catv(fval);/*papillon 10/17*/
#endif
				qam_status.tnr_freq = fval;
				break;

	case SHELL_NOOP:
	break;
	default:
	printf("QAM > Syntax Error\n");
    }

    /* show prompt for stdin input */
    if (fp == stdin) printf("QAM > ");
  }
  return 0;
}

void Set_QAM()
{
	gotoxy(5,17);
	cprintf("QAM  0 : 4-Cons,  1:16-Cons,  2:32-Cons,");
	gotoxy(5,18);
	cprintf("     3 : 64-Cons, 4:128-Cons, 5:256-Cons");
	gotoxy(5,19); cprintf("> ");
	  scanf("%d",&Select_QAM);
}
void Set_Symbol()
{
	float fval;
	double dval;
	long lval;
	int ival,qval;
	gotoxy(10,18); cprintf("Enter Symbol Rate in MHz");
	gotoxy(10,19); cprintf("> ");
	  scanf("%f",&Symbol_Rate);
	  /* this sets the received symbol rate        */
	  /* STBFOS = 0x1000000*(symbol_rate/ref_freq) */
	  dval = 1.6777216e7 * Symbol_Rate / qam_status.ref_freq;
	  lval = (long) dval;
	  ival = lval >> 8;
	  qval = 0xff00 & (lval << 8);
	  qam_write(MB_W,MB_STBEN,0,0);
	  qam_write(MB_W,MB_STBFOS,ival,qval);
	  qam_write(MB_W,MB_STBEN,0x0100,0);
}

void Set_Freq()
{
  char	tmpbuf[80], *cp;
  float fval;
  int ival;

	gotoxy(10,18); cprintf("Enter tuner channel as an integer or");
	gotoxy(10,19); cprintf(" tuner freq. in MHz including the");
	gotoxy(10,20); cprintf(" decimal point.");
	gotoxy(10,21); cprintf("> ");
	fflush(stdin);
	gets(tmpbuf);
	if ( strcmp(tmpbuf, "")) {
	  for (cp = tmpbuf; *cp != '.' && *cp != '\0'; cp++) ;
	  if (*cp == '.') {
	    sscanf(tmpbuf,"%f",&fval);
	  }
	  else {
	    sscanf(tmpbuf,"%d",&ival);
	    if (ival > 0 && ival <= MAX_CHANNEL) {

	      fval = 51.025 + 7*(ival -1);
//papi set original	      fval = 2.0 + c6m_freq_map[ival - 1];
	    }
	  }
	  tuner_freq(fval);
#if 0
	  tuner_catv(fval);/*papillon 10/16*/
#endif
	  qam_status.tnr_freq = fval;
	}
}

void Dis_Show()
{
      unsigned long correctableBlocks, uncorrectableBlocks;
      unsigned long RS_Correctable_Blocks_Accumulator = 0uL;
      unsigned long RS_Uncorrectable_Blocks_Accumulator = 0uL;
      unsigned long t1, t2, deltaT;

      int    val1, val2, val3, foo;
      float  elapsedBits=0.0;
      float bitsPerBaud,pre_fec_ber,post_fec_ber;
  struct dostime_t time;
      /* read in a 24-bit value 8 bits at a time from MSB->LSB */
	/* get the start time for BER measurements */
if (FEC_IN_LOCK)
{
	_dos_gettime(&time);
  t1 = (unsigned long) 360000uL*time.hour + 6000uL*time.minute + 100uL*time.second + time.hsecond;

      qam_read(SB_R,SB_RSCR0,&val1,&foo);
      qam_read(SB_R,SB_RSCR1,&val2,&foo);
      qam_read(SB_R,SB_RSCR2,&val3,&foo);
      correctableBlocks  = ((unsigned long)val1)*65536uL;
      correctableBlocks += ((unsigned long)val2)*256Lu;
      correctableBlocks += ((unsigned long)val3);
      /* accumulate the new reading */
      RS_Correctable_Blocks_Accumulator += correctableBlocks;
      /* read in a 16-bit value 8 bits at a time from MSB->LSB */
      qam_read(SB_R,SB_RSUR0,&val1,&foo);
      qam_read(SB_R,SB_RSUR1,&val2,&foo);
      uncorrectableBlocks  = ((unsigned long)val1)*256uL;
      uncorrectableBlocks += ((unsigned long)val2);
      /* accumulate the new reading */
      delay(1000);
      RS_Uncorrectable_Blocks_Accumulator += uncorrectableBlocks;
      /* bitsPerBaud is the Log2(QAM order) */
      switch (QAM_MODE) {
	case QAM_4  :
	  bitsPerBaud=2.0;
	  break;
	case QAM_16 :
	  bitsPerBaud=4.0;
	  break;
	case QAM_32 :
	  bitsPerBaud=5.0;
	  break;
	case QAM_64 :
	  bitsPerBaud=6.0;
	  break;
	case QAM_128:
	  bitsPerBaud=7.0;
	  break;
	case QAM_256:
	  bitsPerBaud=8.0;
	  break;
      }
      /* compute the time elapsed since the last restart of measurements */
      _dos_gettime(&time);
      t2 = (unsigned long) 360000uL*time.hour + 6000uL*time.minute + 100uL*time.second + time.hsecond;
      deltaT = 10uL * (t2 - t1);   /* compute elapsed time in ms */
      elapsedBits = ((float)deltaT)*1000.0*qam_status.symbol_rate* \
		      bitsPerBaud*(188./204.);

      if (elapsedBits != 0.0) {
	pre_fec_ber  = ((float)RS_Correctable_Blocks_Accumulator) / elapsedBits;
	post_fec_ber = ((float)RS_Uncorrectable_Blocks_Accumulator) / elapsedBits;

	/*
	  Add correction factor which is based on an assumption about the number
	  of bytes in the block that were in error as well as how many bits were
	  incorrect in each of these imperfect bytes.
	*/
	post_fec_ber *= 12.0;
	printf(" pre_fec: %5.2E", pre_fec_ber);
printf(" post_fec: %5.2E", post_fec_ber);
printf(" UCB: %d", RS_Uncorrectable_Blocks_Accumulator);
      }
    }   // if (FEC_IN_LOCK)
}
void QAM_Init()
{
 float fval, offset;
 int ival,qval;
 double dval;
 long lval;
 unsigned int      thresh_msbs;

 //bus_type I2C
qam_status.status &= ~SPI_SELECT;
//slave_address
glb_slave_addr = 0x0C;
/* STBFOS = 0x1000000*(symbol_rate/ref_freq) */
dval = 1.6777216e7 * Symbol_Rate / qam_status.ref_freq;
		lval = (long) dval;
		ival = lval >> 8;
		qval = 0xff00 & (lval << 8);
		qam_write(MB_W,MB_STBEN,0,0);
		qam_write(MB_W,MB_STBFOS,ival,qval);
		qam_write(MB_W,MB_STBEN,0x0100,0);
//lo_freq
	   compute_pll_div(Down_Xtal,&ival,&qval);
	   qam_write(SB_RW,SB_STOSCM,0x1a,0);
	   qam_write(MB_W ,MB_STOSC1,ival << 8,0);
	   qam_write(MB_W ,MB_STOSC2,qval << 8,0);
//tuner
	   qam_status.tuner_used = SINGLE;
	  /*
		Now that we've read in what the lock_thresh
	    is we will convert from dB to linear scale
	    and feed it back to the 3118 so that it can
	    internally determine if the SNR is above this
	    chosen threshold and set the appropriate bit
	    in the IRQ register.
	  */
	    offset = OFFSET_QAM_64;    //QAM 64
	  fval = pow(10.0, -(qam_status.lock_thresh - offset)/20.0);
	  thresh_msbs = (unsigned int) fval;
	  ival = thresh_msbs;    /* store unsigned value in a signed variable */
	  /* only 16 bits of the 24 bit multi-byte register will be specified */
	  qam_write(MB_W,MB_STSNRT,ival,0);
}
void Adapt_AGC_2()
{
int     ival,qval,esti;
int     loop = 1;
//        T_AGC = 120;
//  Tuner_AGC(T_AGC);

qam_read(MB_R,MB_LDAI,&ival,&qval);
/* NIM qam */
qam_read(MB_R,MB_LDAI,&ival,&qval);
//      printf("ival : %d",ival);
//        getch();

if(ival < -18000)
{
      T_AGC = 100;
}
else if(ival < 32700)             //-20000<<14000
{
T_AGC = 120;//setting Level High.  ref T_AGC = 80
}
else

{
T_AGC = 140;
Tuner_AGC(T_AGC);
delay(100);
qam_read(MB_R,MB_LDAI,&ival,&qval);
if(ival <10000)
T_AGC = 130;
}
Tuner_AGC(T_AGC);
}


void  My_Acquisition()
{
//Tuner_AGC(150); //default starting number
// ksk 99.11.15
Init_Config();
//### Set Gain ###
delay(10+gap);
//### Acquire Baud Timing ###
Acquire_Baud_Timing();
//Adapt_AGC(); //papi
//### Pre-Equalization ###
qam_write(SB_RW,SB_FRZCTL,0x21,0);// # enable equalizers and main tap real
delay (20+gap);
qam_write(SB_RW,SB_FRZCTL,0x39,0);// # freeze equalizers at current taps

//### Carrier Coarse Acquisition thru Sweep
qam_write(MB_W,MB_STDRI,0xfd71,0x0000);//  # papi  (fd71) start point for sweep at -100 kHz at 5 Mbaud
//qam_write(MB_W,MB_STDRI,0xffbe,0x0000);//  # papi  (ffbe) start point for sweep at -10 kHz at 5 Mbaud
qam_write(MB_W,MB_STDRSP,0x0a00,0x0000);//# enable sweep up, medium rate
delay (180+gap);
qam_write(MB_W,MB_STDRSP,0x0000,0x0000);//# disable sweep
qam_write(SB_RW,SB_FRZCTL,0x21,0x00);//FFE Main Tap Imaginayr Freeze.AGC Freeze
delay (10+gap);
//### Carrier Refinement ###
qam_write(MB_W,MB_STDRLC,0xf400,0x0000);//# reduce carrier BW
delay (20+gap);
//### Constellation Refinement ###
      switch (Select_QAM) {
	case QAM_4  :
	  Constellation_4_Refinement();
	  break;
	case QAM_16 :
	  Constellation_16_Refinement();
	  break;
	case QAM_32 :
	  Constellation_32_Refinement();
	  break;
	case QAM_64 :
	  Constellation_64_Refinement();
	  break;
	case QAM_128:
	  Constellation_128_Refinement();
	  break;
	case QAM_256:
	  Constellation_256_Refinement();
	  break;
      }
#if 1
Init_FEC();
#endif
qam_write(MB_W,MB_STATHR,0x0600,0x0000);//# set AGC power threshold

}
void Check_Spectrum_Inverse()
{
  int    ival,qval;
		qam_read(SB_R,SB_IRQCTL,&ival,&qval);
	cprintf("%4.2f dB",qam_status.snr_estimate);
 if(QAM_IN_LOCK)
 {

	if(qam_status.snr_estimate >23)
	 {

		if(!FEC_IN_LOCK)
		{
			if(Normal ==0)
			{	Normal = 1;  //spectrum Normal
			qam_write(SB_RW,SB_FMTCTL,0x0C,0x00);   // enable ADCLK, diff and Gray decoding, internal A/D w/ offset binary
			}
		else
			{
			Normal = 0;  //spectrum Inv.
			qam_write(SB_RW,SB_FMTCTL,0x04,0x00);   // enable ADCLK, diff and Gray decoding, internal A/D w/ offset binary
			}//normal spectrum

	       //	qam_write(SB_RW,SB_FMTCTL,0x0C,0x00);   // enable ADCLK, diff and Gray decoding, internal A/D w/ offset binary

		}
	}
 }

}
void Check_Lock()
{
  int    ival,qval;
		/* Check for FEC lock only if QAM_LOCK */
		/* Read the IRQ register to see if FEC in lock */
		qam_read(SB_R,SB_IRQCTL,&ival,&qval);
		if ((ival & 0x08) == 0x08) {
		       qam_status.status |= FEC_LOCK_STATUS;
		} else {
		       qam_status.status &= (~FEC_LOCK_STATUS);
		  /* if auto lock enabled and out of lock, reacquire */
		QAM_Init();
		Adapt_AGC_2();
		My_Acquisition();
	Check_Spectrum_Inverse();

		}
}
/********************************************************************
* main - entry point for user interface program.
*********************************************************************/

void main(void) {
  double      dval;
  long        lval;
  int         i,x,y,c,menu_lvl=0,rev=0;
  int         op,port,rstat;
  int         reg,ival,qval;
  char        fname[80],*cp,tmpbuf[80],channel[32],*revision;
  uchar       cval,scr_buf[512],script,cmd;
  FILE        *fp;
  float       fval;
  // papi 98.2.28
  char	      key;
  unsigned int	uval,esc=1;
  //end
  /* clear screen */
  NORMAL_VIDEO;
  clrscr();

  /* set default modes and acq scripts */

  qam_status.status     = 0;
  qam_status.errno      = 0;
  qam_status.lock_thresh= 20.5;
  qam_status.tuner_used = SINGLE;//default single conversion.
  qam_status.acq_script = 0;
if (NTSC) //USA
{
Symbol_Rate = 5.0;// China spec.
Down_Xtal = 38.000;
qam_status.ref_freq   = 11.52;  /* set in startup.cmd */
}
else //PAL  China  Default
{
Symbol_Rate = 6.925;// China spec.
Down_Xtal = 28.636;
qam_status.ref_freq   = 15.00;  /* set in startup.cmd */
}

  qam_read(MB_R,MB_LDID,&ival,&qval);
  rev = 0x02 & ival;

  /* read the QAMLink status, display it and menu */
  clrscr();
  show_status(1);
  gotoxy(63,21); printf("%s",revision);
 while(esc)
 {
  // Dis_Show();
Check_Lock();
//  delay(100);
  if(kbhit())
  {
  key = getch();

  switch(key)
	{
	case('d'):
	case('D'):
	Tuner_AGC(T_AGC--);
	break;
	case('u'):
	case('U'):
	Tuner_AGC(T_AGC++);
	break;
	case('l'):
	case('L'):
	scanf("%d",&T_AGC);
	Tuner_AGC(T_AGC);
	break;
	case('f'):
	case('F'):
	Set_Freq();
	break;
	case('s'):
	case('S'):
	Set_Symbol();
	break;
	case('x'):
	case('X'):
	Set_QAM();
	break;
	case('w'):
	case('W'):
	run_command_file(stdin);
	fflush(stdin);
	clrscr();
	break;
	case('a'):
	case('A'):
	QAM_Init();
	Adapt_AGC_2();
	My_Acquisition();
	  Check_Spectrum_Inverse();

	break;
	case ('c'): /* F8 : Monitor Constellation */
	case ('C'): /* F8 : Monitor Constellation */
	const_monitor();
	break;
	case ('e'): /* F7 : Monitor Equalizer */
	case ('E'):
	if (rev == 2) {
		equ_monitor_b();
	} else {
		equ_monitor_a();
	}
	break;

	case ('r'): /* F6 : Register  BCM3118 State */
	case ('R'): /* F6 : Register  BCM3118 State */
	dump_bcm3118();
	break;
	case('i'):// spectral inverse
	case('I'):
	Check_Spectrum_Inverse();
	break;
	case('q'):
	case('Q'):
	esc = 0;
	break;
	case('o'):
	case('O'):

	break;
	case('M'):
	case('m'):
	for(ival = 500;ival <900;ival+=7)
	{
	tuner_freq(ival);
	}
	break;
	default:
	break;

	}//end switch
	clrscr();

  }//end if(kbhit())

	  show_status(1);

  }//end while(esc)

}

⌨️ 快捷键说明

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