📄 tmbsltda18271.c
字号:
// frequency dependent parameters update
//----------------------
// search for uCprog_table corresponding to uRF
uCounter = 0;
do uCounter ++;
while (uRF > pObj->Config.RF_CAL_Map[uCounter - 1].uRF_Max && uCounter < TDA18271_RF_CAL_NB_ROWS);
uCprog_table = (UInt8)pObj->Config.RF_CAL_Map[uCounter - 1].uRFC_Cprog;
// search for sub-band corresponding to uRF
uCounter = 0;
do uCounter ++;
while (uRF > pObj->Config.RF_BAND_Map[uCounter - 1].uRF_Max && uCounter < TDA18271_RF_BAND_NB_ROWS);
// calculate Capprox
if (pObj->Config.RF_BAND_Map[uCounter - 1].uRF1 == 0)
{
// Capprox = uCprog_table
uCapprox = (Int32)uCprog_table;
}
else if ((pObj->Config.RF_BAND_Map[uCounter - 1].uRF3 != 0) && (uRF >= pObj->Config.RF_BAND_Map[uCounter - 1].uRF2))
{
// Capprox = A2 * (uRF - uRF2) + B2 + uCprog_table
uCapprox = (Int32)(((pObj->Config.RF_BAND_Map[uCounter - 1].uRF_A2 * ((Int32)(uRF - pObj->Config.RF_BAND_Map[uCounter - 1].uRF2) / 1000000)) / 1000000)
+ pObj->Config.RF_BAND_Map[uCounter - 1].uRF_B2 + uCprog_table);
}
else
{
// Capprox = A1 * (uRF - uRF1) + B1 + uCprog_table
uCapprox = (Int32)(((pObj->Config.RF_BAND_Map[uCounter - 1].uRF_A1 * ((Int32)(uRF - pObj->Config.RF_BAND_Map[uCounter - 1].uRF1) / 1000000)) / 1000000)
+ pObj->Config.RF_BAND_Map[uCounter - 1].uRF_B1 + uCprog_table);
}
// search for udC_Over_dT corresponding to uRF
uCounter = 0;
do uCounter ++;
while (uRF > pObj->Config.RF_CAL_DC_OVER_DT_Map[uCounter - 1].uRF_Max && uCounter < TDA18271_RF_CAL_DC_OVER_DT_NB_ROWS);
// calculate CTcomp
pObj->Config.uRFCAL_TCOMP = (Int32)(pObj->Config.RF_CAL_DC_OVER_DT_Map[uCounter - 1].udC_Over_dT * (uTMVALUE_CURRENT - pObj->Config.uTMVALUE_RFCAL)) / 1000;
// calculate Cprog
uCprog_signed = uCapprox + pObj->Config.uRFCAL_TCOMP;
if (uCprog_signed < 0) uCprog_signed = 0;
if (uCprog_signed > 255) uCprog_signed = 255;
pObj->I2CMap.uBx1D.RFC_Cprog = (UInt8)uCprog_signed;
// write byte RFC_Cprog
err = TDA18271Write(pObj, 0x1D, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x1D, 1) failed.", tUnit));
//----------------------
// standard mode update
//----------------------
// update TV broadcast parameters
err = TDA18271SetStandardMode(pObj, pObj->StandardMode);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271SetStandardMode(0x%08X, %d) failed.", tUnit, pObj->StandardMode));
// switch RFAGC to high speed mode (store current value)
utmpRFAGC = pObj->I2CMap.uBx05.bF.AGC_Low_BW;
pObj->I2CMap.uBx05.bF.AGC_Low_BW = 0x00;
// write byte EASY_PROG_BYTE_3
err = TDA18271Write(pObj, 0x05, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x05, 1) failed.", tUnit));
#ifdef TMBSL_TDA18271_FREEZE_AGC
if(pObj->I2CMap.uBx00.bF.ID<5)
{
/////////////////////////////////////////////
//----------------------
// Unfreeze AGC 1&2 detectors for SECAM L only
//----------------------
switch (pObj->StandardMode)
{
case tmTDA18271_ANLG_L:
case tmTDA18271_ANLG_LL:
// switch to digital mode
pObj->I2CMap.uBx05.bF.AGCK_Mode |= 0x02;
// start AGC1
pObj->I2CMap.uBx1B.bF.PD_AGC1_Det = 0x00;
pObj->I2CMap.uBx21.bF.AGC1_loop_off = 0x00;
// start AGC2
pObj->I2CMap.uBx1B.bF.PD_AGC2_Det = 0x00;
pObj->I2CMap.uBx24.bF.AGC2_loop_off = 0x00;
// write byte EASY_PROG_BYTE_3
err = TDA18271Write(pObj, 0x05, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x05, 1) failed.", tUnit));
break;
default:
// start AGC1
pObj->I2CMap.uBx1B.bF.PD_AGC1_Det = 0x00;
pObj->I2CMap.uBx21.bF.AGC1_loop_off = 0x00;
// freeze AGC2 (set AGC2Gain = -6dB)
pObj->I2CMap.uBx1B.bF.PD_AGC2_Det = 0x01;
pObj->I2CMap.uBx24.bF.AGC2_loop_off = 0x01;
pObj->I2CMap.uBx24.bF.AGC2_Gain = 0x03;
break;
}
// write byte EXTENDED_BYTE_12
err = TDA18271Write(pObj, 0x1B, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x1B, 1) failed.", tUnit));
// write byte EXTENDED_BYTE_18
err = TDA18271Write(pObj, 0x21, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x21, 1) failed.", tUnit));
// write bytes EXTENDED_BYTE_21 to EXTENDED_BYTE_23
err = TDA18271Write(pObj, 0x24, 3);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x24, 3) failed.", tUnit));
switch (pObj->StandardMode)
{
case tmTDA18271_ANLG_L:
case tmTDA18271_ANLG_LL:
// wait 1 s for AGC 1&2 startup
err = TDA18271Wait(pObj, 1000);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Wait(0x%08X, 1000) failed.", tUnit));
break;
}
/////////////////////////////////////////////
}
#else // TMBSL_TDA18271_FREEZE_AGC
// write bytes EXTENDED_BYTE_21 to EXTENDED_BYTE_23
err = TDA18271Write(pObj, 0x24, 3);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x24, 3) failed.", tUnit));
#endif // TMBSL_TDA18271_FREEZE_AGC
//----------------------
// update frequency dependent parameters
//----------------------
// search for IR_Meas corresponding to wanted frequency
uCounter = 0;
do uCounter ++;
while (uRF > pObj->Config.IR_MEAS_Map[uCounter - 1].uRF_Max && uCounter < TDA18271_IR_MEAS_NB_ROWS);
pObj->I2CMap.uBx07.bF.IR_Meas = (UInt8)pObj->Config.IR_MEAS_Map[uCounter - 1].uIR_Meas;
// search for BP_Filter corresponding to uRF
uCounter = 0;
do uCounter ++;
while (uRF > pObj->Config.BP_FILTER_Map[uCounter - 1].uRF_Max && uCounter < TDA18271_BP_FILTER_NB_ROWS);
pObj->I2CMap.uBx03.bF.BP_Filter = (UInt8)pObj->Config.BP_FILTER_Map[uCounter - 1].uBP_Filter;
// search for RF_BAND corresponding to uRF
uCounter = 0;
do uCounter ++;
while (uRF > pObj->Config.RF_BAND_Map[uCounter - 1].uRF_Max && uCounter < TDA18271_RF_BAND_NB_ROWS);
pObj->I2CMap.uBx04.bF.RF_Band = (UInt8)pObj->Config.RF_BAND_Map[uCounter - 1].uRF_Band;
// search for Gain_Taper corresponding to uRF
uCounter = 0;
do uCounter ++;
while (uRF > pObj->Config.GAIN_TAPER_Map[uCounter - 1].uRF_Max && uCounter < TDA18271_GAIN_TAPER_NB_ROWS);
pObj->I2CMap.uBx04.bF.Gain_Taper = (UInt8)pObj->Config.GAIN_TAPER_Map[uCounter - 1].uGain_Taper;
//---------------------
// dual tuner and AGC1 extra configuration management
//---------------------
// use MAIN VCO when master, CAL VCO when slave
pObj->I2CMap.uBx10.bF.CALVCO_forLOn = (pObj->Config.uMasterDevice) ? 1 : 0;
// AGC1 & AGC2 management
pObj->I2CMap.uBx10.bF.AGC1_always_mastern = 0x00;
pObj->I2CMap.uBx10.bF.AGC1_firstn = 0x00;
// write byte EXTENDED_BYTE_1
err = TDA18271Write(pObj, 0x10, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x10, 1) failed.", tUnit));
//---------------------
// tune to wanted channel frequency
//---------------------
// use MAIN VCO when master, CAL VCO when slave
if (pObj->Config.uMasterDevice) // master
{
// calculate MAIN PLL
err = TDA18271CalcMAINPLL(pObj, uRF + pObj->Config.uIF);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271CalcMAINPLL(0x%08X, %d) failed.", tUnit, uRF + pObj->Config.uIF));
// write bytes 0x01 to 0x0F
err = TDA18271Write(pObj, 0x01, 15);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x01, 15) failed.", tUnit));
// MAIN PLL charge pump source
pObj->I2CMap.uBx13.bF.LO_ForceSrce = 0x01;
// write byte EXTENDED_BYTE_4
err = TDA18271Write(pObj, 0x13, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x13, 1) failed.", tUnit));
// wait 1 ms for charge pump source
err = TDA18271Wait(pObj, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Wait(0x%08X, 1) failed.", tUnit));
// MAIN PLL normal operation
pObj->I2CMap.uBx13.bF.LO_ForceSrce = 0x00;
// write byte EXTENDED_BYTE_4
err = TDA18271Write(pObj, 0x13, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x13, 1) failed.", tUnit));
}
else // slave
{
// calculate CAL PLL
err = TDA18271CalcCALPLL(pObj, uRF + pObj->Config.uIF);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271CalcCALPLL(0x%08X, %d) failed.", tUnit, uRF + pObj->Config.uIF));
// copy CAL PLL PostDiv to MAIN PLL Post Div
pObj->I2CMap.uBx0C.bF.MAIN_Post_Div = pObj->I2CMap.uBx08.CAL_POST_DIV_BYTE & 0x77;
// write bytes 0x01 to 0x0F
err = TDA18271Write(pObj, 0x01, 15);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x01, 15) failed.", tUnit));
// CAL PLL charge pump source
pObj->I2CMap.uBx16.bF.CAL_ForceSrce = 0x01;
// write byte EXTENDED_BYTE_7
err = TDA18271Write(pObj, 0x16, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x16, 1) failed.", tUnit));
// wait 1 ms for charge pump source
err = TDA18271Wait(pObj, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Wait(0x%08X, 1) failed.", tUnit));
// CAL PLL normal operation
pObj->I2CMap.uBx16.bF.CAL_ForceSrce = 0x00;
// write byte EXTENDED_BYTE_7
err = TDA18271Write(pObj, 0x16, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x16, 1) failed.", tUnit));
}
// wait 20 ms for PLL locking
err = TDA18271Wait(pObj, 20);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Wait(0x%08X, 20) failed.", tUnit));
// switch RFAGC to normal mode (restore previous value)
pObj->I2CMap.uBx05.bF.AGC_Low_BW = utmpRFAGC;
// write byte EASY_PROG_BYTE_3
err = TDA18271Write(pObj, 0x05, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x05, 1) failed.", tUnit));
#ifdef TMBSL_TDA18271_FREEZE_AGC
if(pObj->I2CMap.uBx00.bF.ID<5)
{
/////////////////////////////////////////////
//----------------------
// Freeze AGC 1&2 detectors for SECAM L only
//----------------------
switch (pObj->StandardMode)
{
case tmTDA18271_ANLG_L:
case tmTDA18271_ANLG_LL:
// switch back to analog mode
pObj->I2CMap.uBx05.bF.AGCK_Mode &= 0x01;
// freeze AGC1
pObj->I2CMap.uBx1B.bF.PD_AGC1_Det = 0x01;
pObj->I2CMap.uBx21.bF.AGC1_loop_off = 0x01;
// freeze AGC2
pObj->I2CMap.uBx1B.bF.PD_AGC2_Det = 0x01;
pObj->I2CMap.uBx24.bF.AGC2_loop_off = 0x01;
// write byte EASY_PROG_BYTE_3
err = TDA18271Write(pObj, 0x05, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x05, 1) failed.", tUnit));
// write byte EXTENDED_BYTE_12
err = TDA18271Write(pObj, 0x1B, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x1B, 1) failed.", tUnit));
// write byte EXTENDED_BYTE_18
err = TDA18271Write(pObj, 0x21, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x21, 1) failed.", tUnit));
// write bytes EXTENDED_BYTE_21
err = TDA18271Write(pObj, 0x24, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x24, 1) failed.", tUnit));
break;
}
}
/////////////////////////////////////////////
#endif // TMBSL_TDA18271_FREEZE_AGC
// read bytes 0x00 to 0x26
err = TDA18271Read (pObj,0x00,39);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Read(0x%08X, 0x00, 39) failed.", tUnit));
return err;
}
//-------------------------------------------------------------------------------------
// FUNCTION: tmbslTDA18271GetRf:
//
// DESCRIPTION: Get the frequency programmed in the tuner
//
// RETURN: TMBSL_ERR_TUNER_BAD_UNIT_NUMBER
// TDA18271_ERR_NOT_INITIALIZED
// TM_OK
//
// NOTES: The value returned is the one stored in the Object
//-------------------------------------------------------------------------------------
//
tmErrorCode_t
tmbslTDA18271GetRf
(
tmUnitSelect_t tUnit, /* I: Unit number */
UInt32* puRF /* O: RF frequency in hertz */
)
{
ptmTDA18271Object_t pObj = Null;
tmErrorCode_t err = TM_OK;
//------------------------------
// test input parameters
//------------------------------
// pObj initialization
err = TDA18271GetInstance(tUnit, &pObj);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271GetInstance(0x%08X) failed.", tUnit));
// test the Object
if (pObj == Null || pObj->init == False)
{
tmDBGPRINTEx(DEBUGLVL_ERROR, "TDA18271 Instance not initialized.");
return TDA18271_ERR_NOT_INITIALIZED;
}
//----------------------
// get the value
//----------------------
// the read function can't be used
*puRF = pObj->Config.uRF;
return err;
}
/*============================================================================*/
/* tmbslTDA18271Reset */
/*============================================================================*/
tmErrorCode_t
tmbslTDA18271Reset
(
tmUnitSelect_t tUnit /* I: Unit number */
)
{
ptmTDA18271Object_t pObj = Null;
tmErrorCode_t err = TM_OK;
err = TDA18271GetInstance(tUnit, &pObj);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271GetInstance(0x%08X) failed.", tUnit));
// test the Object
if (pObj == Null || pObj->init == False)
{
tmDBGPRINTEx(DEBUGLVL_ERROR, "TDA18271 Instance not initialized.");
return TDA18271_ERR_NOT_INITIALIZED;
}
err = TDA18271Init(tUnit);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Init(0x%08X) failed.", tUnit));
return err;
}
/*============================================================================*/
/* tmbslTDA18271GetIF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -