tda10086drv.c
来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 1,716 行 · 第 1/4 页
C
1,716 行
BYTE bRepeatTimes;
BYTE pbCommittedCommand[4];
BYTE pbUnCommittedCommand[4];
BYTE bToneburst;
int ii;
BYTE Send;
CSTRACE( INFO_LEVEL, "\n[HDI][CS_QPSK][TDA10086SendDiSEqC11Command]:\n---------Enter TDA10086SendDiSEqC11Command----------");
bRepeatTimes = bRepeat;
pbCommittedCommand[0] = 0xE0;
pbCommittedCommand[1] = 0x10;
pbCommittedCommand[2] = 0x38;
pbCommittedCommand[3] = bCommittedByte;
bToneburst = (bCommittedByte >> 2) & 0x01;
pbUnCommittedCommand[0] = 0xE0;
pbUnCommittedCommand[1] = 0x10;
pbUnCommittedCommand[2] = 0x39;
pbUnCommittedCommand[3] = bUnCommittedByte;
TDA10086WaitDiSEqCFree(bTunerIndex);
TDA10086GetOneRegister(bTunerIndex,0x36, &bPreF22KStatus);
TDA10086F22KSwitch ( bTunerIndex, CSHDI_OFF); // 22k off
CSSleep(30); // Delay > 15ms
while ( 1 )
{
TDA10086SetOneRegister(bTunerIndex,0x48, pbCommittedCommand[0]);
TDA10086SetOneRegister(bTunerIndex,0x49, pbCommittedCommand[1]);
TDA10086SetOneRegister(bTunerIndex,0x4A, pbCommittedCommand[2]);
TDA10086SetOneRegister(bTunerIndex,0x4B, pbCommittedCommand[3]);
TDA10086SetOneRegister(bTunerIndex,0x36, 0x38);
TDA10086WaitDiSEqCFree(bTunerIndex);
if ((bRepeatTimes == 0) && (bRepeat >0))
{
CSSleep(40); // Delay > 15ms
break;
}
CSSleep(50); // Delay > 25ms
TDA10086SetOneRegister(bTunerIndex,0x48, pbUnCommittedCommand[0]);
TDA10086SetOneRegister(bTunerIndex,0x49, pbUnCommittedCommand[1]);
TDA10086SetOneRegister(bTunerIndex,0x4A, pbUnCommittedCommand[2]);
TDA10086SetOneRegister(bTunerIndex,0x4B, pbUnCommittedCommand[3]);
TDA10086SetOneRegister(bTunerIndex,0x36, 0x38);
TDA10086WaitDiSEqCFree(bTunerIndex);
if (bRepeat == 0)
{
CSSleep(40); // Delay > 15ms
break;
}
else
{
CSSleep(50); // Delay > 25ms
bRepeatTimes--;
}
//added by wen according to specification which said repeated message should start with frame byte with 0xE1
pbCommittedCommand[0] = 0xE1;
pbUnCommittedCommand[0] = 0xE1;
}
CSSleep(20);
if ( bToneburst )
{
TDA10086SetOneRegister(bTunerIndex,0x36, 0x06);
}
else
{
TDA10086SetOneRegister(bTunerIndex,0x36, 0x04);
}
CSSleep(40); // Delay > 15ms
TDA10086SetOneRegister(bTunerIndex,0x36, bPreF22KStatus);
// delay after diseqc to ensure signal steady
CSSleep(200);
CSTRACE( INFO_LEVEL, "\n[HDI][CS_QPSK][TDA10086SendDiSEqC11Command]:\n---------Exit TDA10086SendDiSEqC11Command----------");
return CSQPSK_SUCCESS;
}
CSQPSK_Error_t TDA10086SendDiSEqC10Command (CSHDITunerIndex bTunerIndex, BYTE bSwitchType, BYTE bCommittedByte, BYTE bToneBurstSel,BYTE bRepeat)
{
BYTE bPreF22KStatus;
BYTE bRepeatTimes;
BYTE pbCommittedCommand[4];
BYTE bToneburst;
BYTE bValue,Value,Send;
CSTRACE( INFO_LEVEL, "\n[HDI][CS_QPSK][TDA10086SendDiSEqC10Command]:\n---------Enter TDA10086SendDiSEqC10Command----------");
CSTRACE( INFO_LEVEL, "\n[HDI][CS_QPSK][TDA10086SendDiSEqC10Command]:\nbSwitchType = %d bCommittedByte = 0x%02x bRepeat = %d",bSwitchType,bCommittedByte,bRepeat);
bRepeatTimes = bRepeat;
pbCommittedCommand[0] = 0xE0;
pbCommittedCommand[1] = 0x10;
pbCommittedCommand[2] = 0x38;
pbCommittedCommand[3] = bCommittedByte;
bToneburst = (bCommittedByte >> 2) & 0x01;
if (bSwitchType == 1)
pbCommittedCommand[2] = 0x39;
TDA10086WaitDiSEqCFree(bTunerIndex);
TDA10086GetOneRegister(bTunerIndex,0x36, &Value);
TDA10086F22KSwitch ( bTunerIndex, CSHDI_OFF ); // 22k off
CSSleep(30); // Delay > 15ms
while ( 1)
{
TDA10086SetOneRegister(bTunerIndex,0x48, pbCommittedCommand[0]);
TDA10086SetOneRegister(bTunerIndex,0x49, pbCommittedCommand[1]);
TDA10086SetOneRegister(bTunerIndex,0x4A, pbCommittedCommand[2]);
TDA10086SetOneRegister(bTunerIndex,0x4B, pbCommittedCommand[3]);
TDA10086SetOneRegister(bTunerIndex,0x36, 0x38);
TDA10086WaitDiSEqCFree(bTunerIndex);
if (bRepeatTimes == 0)// && (bRepeat >0))
{
CSSleep(1); // Delay > 15ms
break;
}
else
CSSleep(10); // Delay > 15ms
bRepeatTimes--;
//added by wen according to specification which said repeated message should start with frame byte with 0xE1
pbCommittedCommand[0] = 0xE1;
}
if ( bToneburst )
{
TDA10086SetOneRegister(bTunerIndex,0x36, 0x06);
}
else
{
TDA10086SetOneRegister(bTunerIndex,0x36, 0x04);
}
CSSleep(40); // Delay > 15ms
TDA10086SetOneRegister(bTunerIndex,0x36, Value);
// delay after diseqc to ensure signal steady
CSSleep(200);
CSTRACE( INFO_LEVEL, "\n[HDI][CS_QPSK][TDA10086SendDiSEqC10Command]:\n---------Exit TDA10086SendDiSEqC10Command----------");
return CSQPSK_SUCCESS;
}
CSQPSK_Error_t TDA10086SendToneBurstCommand ( CSHDITunerIndex bTunerIndex, BYTE bTBSwitch )
{
BYTE bPreF22KStatus,Value;
int ii;
// printf("\n---------Enter TDA10086SendToneBurstCommand----------");
TDA10086WaitDiSEqCFree(bTunerIndex);
TDA10086GetOneRegister(bTunerIndex,0x36, &Value);
TDA10086F22KSwitch ( bTunerIndex, CSHDI_OFF ); // 22k off
CSSleep(20); // Delay > 15ms
if ( bTBSwitch )
{
TDA10086SetOneRegister(bTunerIndex,0x36, 0x06);
}
else
{
TDA10086SetOneRegister(bTunerIndex,0x36, 0x04);
}
CSSleep(30); // Delay > 15ms
TDA10086SetOneRegister(bTunerIndex,0x36, Value);
// printf("\n---------Exit TDA10086SendToneBurstCommand----------");
return CSQPSK_SUCCESS;
}
CSQPSK_Error_t TDA8263SetFrequency(CSHDITunerIndex bTunerIndex, DWORD TunerFrequency)
{
DWORD data1, settingfreq,uRatio;
BYTE Tunerdata[10];
BYTE data, count,uD,refdiv;
int nReturn;
int ii;
////Tunerdata[4]~[5] 8363 reg 2X,3X setting
data1 = (TunerFrequency+(PLL_FREQ_SETP/2)) / PLL_FREQ_SETP;
data1 = data1<< 1;
Tunerdata[2] = (BYTE)((data1>>8)&0xff);
Tunerdata[3] = (BYTE)(data1&0xfe);
Tunerdata[4] = 0xff;
// Tunerdata[5] = 0x0e;
Tunerdata[6] = 0x83;
Tunerdata[7] = 0x80;
/*************************************
Modify by yuxibo 05/21/2005
Change the register 8X setting to solve
the mosaic problem.
**************************************/
//Tunerdata[8] = 0x00;
//Tunerdata[9] = 0x04;
Tunerdata[8] = 0x1a;
Tunerdata[9] = 0xd4;
if ( g_bAMPoff[bTunerIndex] == 1 )
{
Tunerdata[5] = 0x0f; //attenuation of 20dB
}
else if ( g_bAMPoff[bTunerIndex] == 2)
{
Tunerdata[5] = 0xfe; //9dB additional gain
}
else
{
Tunerdata[5] = 0x0e; //normal mode
}
//Xtout output must be power down, otherwise PLL can't lock.
Tunerdata[0] = 0x11;
//Tunerdata[3] 8363 reg 1X setting
if(PLL_FREQ_SETP==2000) refdiv=0;
else if(PLL_FREQ_SETP==1000) refdiv=1;
else if(PLL_FREQ_SETP==500) refdiv=2;
else if(PLL_FREQ_SETP==250) refdiv=3;
else if(PLL_FREQ_SETP==125) refdiv=4;
else refdiv=1;
Tunerdata[1] = refdiv<<5;
uRatio= (TunerFrequency+(PLL_FREQ_SETP/2));
uRatio += (30000/2);
uRatio /= 30000;
if(uRatio <= 27)
uD = 0;
else if(uRatio <= 29)
uD = 1;
else if(uRatio <= 31)
uD = 2;
else if(uRatio <= 33)
uD = 3;
else if(uRatio <= 36)
uD = 4;
else if(uRatio <= 38)
uD = 6;
else if(uRatio <= 40)
uD = 7;
else if(uRatio <= 42)
uD = 8;
else if(uRatio <= 43)
uD = 9;
else if(uRatio <= 44)
uD = 10;
else if(uRatio <= 45)
uD = 11;
else if(uRatio <= 46)
uD = 12;
else if(uRatio <= 47)
uD = 13;
else if(uRatio <= 50)
uD = 14;
else if(uRatio <= 54)
uD = 15;
else if(uRatio <= 55)
uD = 16;
else if(uRatio <= 56)
uD = 17;
else if(uRatio <= 58)
uD = 18;
else if(uRatio <= 60)
uD = 19;
else if(uRatio <= 63)
uD = 20;
else if(uRatio <= 64)
uD = 21;
else if(uRatio <= 67)
uD = 22;
else if(uRatio <= 70)
uD = 23;
else if(uRatio <= 75)
uD = 24;
else if(uRatio <= 78)
uD = 25;
else //if(uRatio <= 88)
uD = 26;
Tunerdata[1]=Tunerdata[1]|uD;
if (TDA10086OpenTunerI2C (bTunerIndex) != CSI2C_SUCCESS)
return CSQPSK_I2C_ERROR;
nReturn = TDA8263SetPLLTuner( bTunerIndex, Tunerdata, 10 );
if (TDA10086CloseTunerI2C (bTunerIndex) != CSI2C_SUCCESS)
return CSQPSK_I2C_ERROR;
return CSQPSK_SUCCESS;
}
BYTE TDA8263GetPLLStatus(CSHDITunerIndex bTunerIndex)
{
BYTE bStatus = 0;
BYTE pbVal[2];
if ( CSI2CRequestBus_inner( bTunerIndex, CSHDI_TIMEOUT_INFINITY ) == CSI2C_SUCCESS )
{
if (CSI2CReadWithStop ( g_hdlTDA8263I2C[bTunerIndex], pbVal, 2 ) == CSI2C_SUCCESS )
{
bStatus = pbVal[0];
}
else
{
bStatus = 0;
CSTRACE( ERROR_LEVEL, "\n[HDI][CS_QPSK][TDA8263GetPLLStatus]:\n[ ERROR ] TDA8263 I2C Read Error!");
}
CSI2CReleaseBus_inner(bTunerIndex);
}
else
bStatus = 0;
return bStatus;
}
CSQPSK_Error_t TDA8263SetPLLTuner (CSHDITunerIndex bTunerIndex, PBYTE pbPLLData, int nLength)
{
int nResult = CSQPSK_SUCCESS;
int ii;
if ( CSI2CRequestBus_inner(bTunerIndex, CSHDI_TIMEOUT_INFINITY) == CSI2C_SUCCESS )
{
nResult = CSI2CWriteWithStop( g_hdlTDA8263I2C[bTunerIndex], pbPLLData, nLength );
CSI2CReleaseBus_inner(bTunerIndex);
if (nResult == CSI2C_SUCCESS)
{
return CSQPSK_SUCCESS;
}
}
return CSQPSK_I2C_ERROR;
}
static BYTE TDA10086ReadVR(CSHDITunerIndex bTunerIndex)
{
BYTE bVR;
TDA10086GetOneRegister(bTunerIndex,TDA10086REG_RATE, &bVR);
bVR = (bVR >> 4) & 0x07;
bVR++;
return bVR;
}
static CSQPSK_Error_t TDA10086WriteNCO( CSHDITunerIndex bTunerIndex )
{
DWORD dwTemp;
BYTE bVR,pbByte[4];
bVR = TDA10086ReadVR(bTunerIndex);
dwTemp = g_dwSymRate[bTunerIndex] * (DWORD)bVR * 131072UL;
dwTemp /= (((DWORD)bVR+1) * TDQX_SYSCLK);
pbByte[0] = (BYTE)((dwTemp >> 8) & 0xFF);
pbByte[1] = (BYTE)(dwTemp & 0xFF);
return TDA10086SetRegisters(bTunerIndex,TDA10086REG_FREQ_NCO_MSB, pbByte, 4);
}
void TDA10086Regiterset( CSHDITunerIndex bTunerIndex )
{
BYTE bByte, pByte[3], resByte1, resByte2, resByte3;
volatile DWORD uLong1, uLong2;
DWORD f22_reg;
float F22_FREQ;
/*AS_CLEAR_IND*/
bByte = 0x01;
TDA10086SetOneRegister(bTunerIndex,0x00,bByte);
/*AS_CARC_IND*/
bByte = 0x94;
TDA10086SetOneRegister(bTunerIndex,0x01,bByte);
/*AS_CSWP_IND*/
bByte = 0x00;
TDA10086SetOneRegister(bTunerIndex,0x02,bByte);
/*AS_CARINIT_IND*/
bByte = 0xE4;
TDA10086SetOneRegister(bTunerIndex,0x03,bByte);
/*AS_RHYC_IND*/
bByte = 0x43;
TDA10086SetOneRegister(bTunerIndex,0x04,bByte);
/* TDA10085_AGCRN */
bByte = 0x0b;
TDA10086SetOneRegister(bTunerIndex,0x05,bByte);
TDA10086WriteNCO(bTunerIndex);
/* TDA10085_H22K_LSB */
/* TDA10085_H22K_MSB */
pByte[0] = 0x78;
pByte[1] = 0x00;
TDA10086SetOneRegister(bTunerIndex,0x34,pByte[0]);
TDA10086SetOneRegister(bTunerIndex,0x35,pByte[1]);
TDA10086SetPLL(bTunerIndex);
TDA10086GetOneRegister(bTunerIndex, 0x3D, &bByte );
bByte&=~0x80;
bByte|=0x80;
TDA10086SetOneRegister(bTunerIndex, 0x3D, bByte);
bByte = 0x70/*0x70*/;
TDA10086SetOneRegister(bTunerIndex,0x17,bByte);
/* TDA10085_WPLL1 */
TDA10086SetOneRegister(bTunerIndex,0x56,0x27);
/* TDA10085_WPLL2 */
bByte = 0;
TDA10086SetOneRegister(bTunerIndex,0x57,bByte);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?