📄 lg_yizhi_tuner.c
字号:
TDA10021_iWrI2c(0x2e,buffer);
/*AC_PWMREF_DEF;*/
TDA10021_iWrI2c(0x34,0x80);
/* use internal ADC*/
buffer = TDA10021_iRdI2c(0x1b);
buffer= buffer|0x01;
TDA10021_iWrI2c(0x1b,buffer);
buffer = TDA10021_iRdI2c(0x1b);
buffer= buffer|0x30;
TDA10021_iWrI2c(0x1b,buffer);
/* use only nyquist gain*/
buffer = TDA10021_iRdI2c(0x03);
buffer= buffer&0xef;
TDA10021_iWrI2c(0x03,buffer);
/* set the acquisition to +/-480ppm*/
buffer = TDA10021_iRdI2c(0x03);
buffer= buffer|0x08;
TDA10021_iWrI2c(0x03,buffer);
/* POS_AGC - not in data sheet*/
buffer = TDA10021_iRdI2c(0x02);
buffer= buffer|0x20;
TDA10021_iWrI2c(0x02,buffer);
/* set the polarity of the PWM for the AGC*/
buffer = TDA10021_iRdI2c(0x02);
buffer= buffer&0xfb;
TDA10021_iWrI2c(0x02,buffer);
buffer = TDA10021_iRdI2c(0x2e);
buffer= buffer&0xfd;
TDA10021_iWrI2c(0x2e,buffer);
/* set the threshold for the IF AGC*/
TDA10021_iWrI2c(0x3b,m_iIfagcMax);
TDA10021_iWrI2c(0x3c,m_iIfagcMin);
/* set the threshold for the TUN AGC*/
TDA10021_iWrI2c(0x35,m_iRfagcMax);
TDA10021_iWrI2c(0x36,m_iRfagcMin);
/* set the counter of saturation to its maximun size*/
buffer = TDA10021_iRdI2c(0x0e);
buffer= buffer|0x03;
TDA10021_iWrI2c(0x0e,buffer);
TDA10021_iWrI2c(0x3d,0x00);
buffer = TDA10021_iRdI2c(0x12);
buffer= buffer|0x01;
TDA10021_iWrI2c(0x12,buffer);
buffer = TDA10021_iRdI2c(0x2b);
buffer= buffer|0x01;
TDA10021_iWrI2c(0x2b,buffer);
/* set the position of the central coeffcient*/
buffer = TDA10021_iRdI2c(0x06);
buffer= buffer|0x70;
TDA10021_iWrI2c(0x06,buffer);
/* set the equalizer type*/
buffer = TDA10021_iRdI2c(0x06);
buffer= buffer|0x01;
TDA10021_iWrI2c(0x06,buffer);
buffer = TDA10021_iRdI2c(0x1c);
buffer= buffer|0x20;
TDA10021_iWrI2c(0x1c,buffer);
/* use the central coef when ENADAPT is set to 0*/
buffer = TDA10021_iRdI2c(0x1c);
buffer= buffer|0x08;
TDA10021_iWrI2c(0x1c,buffer);
/* set ALGOD and deltaF*/
lDeltaF = (long)uSysClk*5; lDeltaF /= -8;
lDeltaF += uIF; lDeltaF *= 2048;lDeltaF /= (long)uSysClk;
pByte[0] = (unsigned char)lDeltaF;
pByte[1] = (unsigned char)(((lDeltaF>>8) & 0x03) | 0x04);
TDA10021_iWrI2c(0x37,pByte[0]);
TDA10021_iWrI2c(0x38,pByte[1]);
/* set the KAGC to its maximun value*/
buffer = TDA10021_iRdI2c(0x02);
buffer= buffer|0x03;
TDA10021_iWrI2c(0x02,buffer);
/* set carrier algorithm parameters and SELCAR*/
bByte = 0x80; bByte |= (unsigned char)(1 << 2); bByte |= (unsigned char)(1<< 4);
TDA10021_iWrI2c(0x2d,bByte);
/* TS interface 1*/
/* set to 1 MSB if parallel*/
TDA10021_iWrI2c(0x20,0x7a);
/*Mpeg interface select!! Parallel or serial*/
buffer = TDA10021_iRdI2c(0x20);
buffer= buffer&0xfe;
TDA10021_iWrI2c(0x20,buffer);
/*Serial interface MSB or LSB first*/
buffer = TDA10021_iRdI2c(0x2b);
buffer= buffer&0xbf;
TDA10021_iWrI2c(0x2b,buffer);
buffer = TDA10021_iRdI2c(0x20);
buffer= buffer&0xfe;
TDA10021_iWrI2c(0x20,buffer);
/*MPEg out mode slect!!*/
buffer = TDA10021_iRdI2c(0x20);
buffer= buffer&0xf7;
TDA10021_iWrI2c(0x20,buffer);
/* set the MPEG output Mode B clock*/
buffer = TDA10021_iRdI2c(0x20);
buffer= buffer&0x9f;
buffer= buffer|0x90;
TDA10021_iWrI2c(0x20,buffer);
/* set the MPEG output clock polarity*/
buffer = TDA10021_iRdI2c(0x12);
buffer= buffer|0x01;
TDA10021_iWrI2c(0x12,buffer);
/* TS interface 2*/
buffer = TDA10021_iRdI2c(0x2b);
buffer= buffer&0xbf;
TDA10021_iWrI2c(0x2b,buffer);
/* set the BER depth*/
buffer = TDA10021_iRdI2c(0x10);
buffer= buffer&0xbf;
buffer= buffer|0x80;
TDA10021_iWrI2c(0x10,buffer);
/* mpeg out enable insert*/
TDA10021_iWrI2c(0x2c,0x0d);
/* spectrum inv yes;*/
buffer = TDA10021_iRdI2c(0x00);
buffer= buffer|0x20;
TDA10021_iWrI2c(0x00,buffer);
}
unsigned long Q10021WriteSymbolRate(unsigned long uFreqSymb)
{
unsigned char pWrite[4], bNdec, bSFil,buffer;
unsigned long uBDR, uFreqSymbInv, uFreqSymb240;
float fFreqSymb, fSysClk ,fResult, fBDR ;
/*add 240 ppm to the SR*/
uFreqSymb240 = uFreqSymb*240;
uFreqSymb240 /= 1000000;
uFreqSymb240 = uFreqSymb + uFreqSymb240;
/* calculate the number of decimation and the antialias filter*/
bNdec = 0; bSFil = 0;
if ((uFreqSymb240/10) < (uSysClk/123)){ bNdec = 0; bSFil = 1;}
if ((uFreqSymb240/10) < (uSysClk/160)){ bNdec = 1; bSFil = 0;}
if ((uFreqSymb240/10) < (uSysClk/246)){ bNdec = 1; bSFil = 1;}
if ((uFreqSymb240/10) < (uSysClk/320)){ bNdec = 2; bSFil = 0;}
if ((uFreqSymb240/10) < (uSysClk/492)){ bNdec = 2; bSFil = 1;}
if ((uFreqSymb240/10) < (uSysClk/640)){ bNdec = 3; bSFil = 0;}
if ((uFreqSymb240/10) < (uSysClk/984)){ bNdec = 3; bSFil = 1;}
/* program SFIL*/
if (bSFil==1)
{
buffer = TDA10021_iRdI2c(0x0e);
TDA10021_iWrI2c(0x0e,buffer|0x10);
}
if (bSFil==0)
{
buffer = TDA10021_iRdI2c(0x0e);
TDA10021_iWrI2c(0x0e,buffer&0xef);
}
/* program NDEC*/
if (bNdec==1)
{
buffer = TDA10021_iRdI2c(0x03);
buffer = buffer|0x40;
buffer = buffer&0x7f;
TDA10021_iWrI2c(0x03,buffer);
}
if (bNdec==0)
{
buffer = TDA10021_iRdI2c(0x03);
TDA10021_iWrI2c(0x03,buffer&0x3f);
}
if (bNdec==2)
{
buffer = TDA10021_iRdI2c(0x03);
buffer = buffer&0xbf;
buffer = buffer|0x80;
TDA10021_iWrI2c(0x03,buffer);
}
if (bNdec==3)
{
buffer = TDA10021_iRdI2c(0x03);
TDA10021_iWrI2c(0x03,buffer|0xc0);
}
/* calculate the inversion of the symbol frequency*/
uFreqSymbInv = uSysClk*16;
uFreqSymbInv >>= bNdec; /* divide by 2^decim*/
uFreqSymbInv += uFreqSymb/2; /* rounding for division*/
uFreqSymbInv /= uFreqSymb;
if (uFreqSymbInv > 255) uFreqSymbInv = 255;
/* calculate the symbol rate*/
fFreqSymb = (float)uFreqSymb;
fSysClk = (float)uSysClk;
fResult = (float)(1<<(24+bNdec));
fResult /= fSysClk;
fResult *= fFreqSymb;
uBDR = (unsigned long)fResult;
/* program the value in register of the symbol rate*/
pWrite[0] = (unsigned char)(uBDR);
pWrite[1] = (unsigned char)(uBDR >> 8);
pWrite[2] = (unsigned char)(uBDR >> 16);
pWrite[3] = (unsigned char)uFreqSymbInv;
TDA10021_iWrI2c(0x0a,pWrite[0]);
TDA10021_iWrI2c(0x0b,pWrite[1]);
TDA10021_iWrI2c(0x0c,pWrite[2]);
TDA10021_iWrI2c(0x0d,pWrite[3]);
/* return the value programmed*/
fBDR = (float)uBDR;
fSysClk = (float)uSysClk;
fResult = fBDR*fSysClk;
fResult /= (float)(1<<(24+bNdec));
return (unsigned long)fResult;
}
void Q10021WriteQam(unsigned char bQAM)
{
unsigned char buffer;
static TypeQAM[6][5] =
{
{0x00, 0x8c, 0x87, 0xa2, 0x91}, /* 16 QAM <=> qam=0 */
{0x04, 0x8c, 0x64, 0x74, 0x96}, /* 32 QAM <=> qam=1 */
{0x08, 0x6a, 0x46, 0x43, 0x6a}, /* 64 QAM <=> qam=2 */
{0x0c, 0x78, 0x30, 0x30, 0x7e}, /* 128 QAM <=> qam=3 */
{0x10, 0x5c, 0x26, 0x23, 0x6b}, /* 256 QAM <=> qam=4 */
{0x14, 0x78, 0x78, 0x8c, 0x96} /* 4 QAM <=> qam=5 */
};
switch(bQAM)
{ case 0:
TDA10021_iWrI2c(0x00,0x63);
break;
case 1:
TDA10021_iWrI2c(0x00,0x67);
break;
case 2:
buffer = TDA10021_iRdI2c(0x00);
buffer = buffer|0x08;
buffer = buffer&0xeb;
TDA10021_iWrI2c(0x00,buffer);
//TDA10021_iWrI2c(0x00,0x6b);
break;
case 3:
TDA10021_iWrI2c(0x00,0x6f);
break;
case 4:
TDA10021_iWrI2c(0x00,0x73);
break;
case 5:
TDA10021_iWrI2c(0x00,0x77);
break;
}
TDA10021_iWrI2c(0x01,TypeQAM[bQAM][1]);
TDA10021_iWrI2c(0x05,TypeQAM[bQAM][2]);
TDA10021_iWrI2c(0x08,TypeQAM[bQAM][3]);
TDA10021_iWrI2c(0x09,TypeQAM[bQAM][4]);
}
unsigned char Q10021RunAlgo(unsigned long uSR, unsigned char *pGain, unsigned char bAutoGain, unsigned char bAutoSpecInv)
{
unsigned char bAGC1, bAGC2, bSI,bGainFound,buffer,buffer1;
if(bAutoGain)*pGain=0;
bGainFound=*pGain;
/* set the gain*/
if (bGainFound==0)
{
buffer = TDA10021_iRdI2c(0x0e);
TDA10021_iWrI2c(0x0e,buffer&0x1f);
}
if (bGainFound==1)
{
buffer = TDA10021_iRdI2c(0x0e);
buffer = buffer|0x20;
buffer = buffer&0x3f;
TDA10021_iWrI2c(0x0e,buffer);
}
if (bGainFound==2)
{
buffer = TDA10021_iRdI2c(0x0e);
buffer = buffer&0x6f;
buffer = buffer|0x40;
TDA10021_iWrI2c(0x0e,buffer);
}
if (bGainFound==3)
{
buffer = TDA10021_iRdI2c(0x0e);
buffer = buffer&0x7f;
buffer = buffer|0x60;
TDA10021_iWrI2c(0x0e,buffer);
}
if (bGainFound==4)
{
buffer = TDA10021_iRdI2c(0x0e);
buffer = buffer|0x80;
buffer = buffer&0x9f;
TDA10021_iWrI2c(0x0e,buffer);
}
if (bGainFound==5)
{
buffer = TDA10021_iRdI2c(0x0e);
buffer = buffer|0xa0;
buffer = buffer&0xbf;
TDA10021_iWrI2c(0x0e,buffer);
}
if (bGainFound==6)
{
buffer = TDA10021_iRdI2c(0x0e);
buffer = buffer&0xdf;
buffer = buffer|0xc0;
TDA10021_iWrI2c(0x0e,buffer);
}
if (bGainFound==7)
{
buffer = TDA10021_iRdI2c(0x0e);
TDA10021_iWrI2c(0x0e,buffer|0xe0);
}
/* set the AGC time constant*/
buffer = TDA10021_iRdI2c(0x02);
buffer= buffer|0x03;
TDA10021_iWrI2c(0x02,buffer);
/* program the CARCONF*/
TDA10021_iWrI2c(0x04,0x0a);
/* only use the central coef and disable other adaptation when gain auto*/
if (bAutoGain)
{
buffer = TDA10021_iRdI2c(0x1c);
buffer= buffer|0x08;
TDA10021_iWrI2c(0x1c,buffer);
}
/* reset the demod reset CLB bit*/
buffer = TDA10021_iRdI2c(0x00);
buffer= buffer&0xfe;
TDA10021_iWrI2c(0x00,buffer);
Q10021AlgoDelay(80000, uSR);
/* read the AGC values*/ /* test if there is a signal*/
bAGC1 = TDA10021_iRdI2c(0x17);
bAGC2 = TDA10021_iRdI2c(0x2f);
// buffer = TDA10021_iRdI2c(0x17);
// MXT_printf("\n******** 000AGC_TUNER=%d********",buffer);
// buffer = TDA10021_iRdI2c(0x2f);
// MXT_printf("\n******** 000AGC_IF=%d********",buffer);
if (bAGC1 == 255 & bAGC2 == 255) return 1;
/* test the algo in used*/
if (bAutoGain)
{
if ((bGainFound=Q10021AlgoGain( uSR, bGainFound)) == 6)
{
MXT_printf("\n********bGainFound flase ********");
return 2;/* if err */
}
else
{
/* set the AGC time constant*/
buffer = TDA10021_iRdI2c(0x02);
buffer = buffer&0xfd;
buffer = buffer|0x01;
TDA10021_iWrI2c(0x02,buffer);
/* use all coef*/
buffer = TDA10021_iRdI2c(0x1c);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -