📄 tmbsltda18271.c
字号:
// launch optimization algorithm
// write byte EASY_PROG_BYTE_2
err = TDA18271Write(pObj, 0x04, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x04, 1) failed.", tUnit));
// wait 30 ms for image optimization completion
err = TDA18271Wait(pObj, 30);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Wait(0x%08X, 30) failed.", tUnit));
//----------------------
// back to normal mode
//----------------------
// update & write byte EASY_PROG_BYTE_4
pObj->I2CMap.uBx06.EASY_PROG_BYTE_4 = 0x64;
err = TDA18271Write(pObj, 0x06, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x06, 1) failed.", tUnit));
// synchronization
// write byte EASY_PROG_BYTE_1
err = TDA18271Write(pObj, 0x03, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x03, 1) failed.", tUnit));
tmDBGPRINTEx(DEBUGLVL_TERSE,(" - IR Calibration OK"));
//----------------------
// RF tracking filters calibration
//----------------------
tmDBGPRINTEx(DEBUGLVL_TERSE, " --> RF Tracking Filters Calibration");
err = TDA18271CalcRFFilterCurve(pObj);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271CalcRFFilterCurve(0x%08X) failed.", tUnit));
tmDBGPRINTEx(DEBUGLVL_TERSE, " - RF Tracking Filters Calibration OK");
//----------------------
// back to POR mode
//----------------------
// power up detector 1
pObj->I2CMap.uBx1B.bF.PD_AGC1_Det = 0x00;
// write byte EXTENDED_BYTE_12
err = TDA18271Write(pObj, 0x1B, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x1B, 1) failed.", tUnit));
// turn AGC1 loop on
pObj->I2CMap.uBx21.bF.AGC1_loop_off = 0x00;
// set AGC1Gain = 6dB
pObj->I2CMap.uBx21.bF.AGC1_Gain = 0x00;
// write byte EXTENDED_BYTE_18
err = TDA18271Write(pObj, 0x21, 1);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271Write(0x%08X, 0x21, 1) failed.", tUnit));
// set AGC2Gain = -6dB
pObj->I2CMap.uBx24.bF.AGC2_Gain = 0x03;
// switch to POR mode
err = TDA18271SetPowerState(pObj, tmTDA18271_PowerStandbyWith16MHzAndLoopThrough);
tmASSERTExTR(err, TM_OK, (DEBUGLVL_ERROR, "TDA18271SetPowerState(0x%08X, tmTDA18271_PowerStandbyWith16MHzAndLoopThrough) failed.", tUnit));
// disable 1.5MHz low pass filter
pObj->I2CMap.uBx26.bF.ForceLP_Fc2_En = 0x00;
pObj->I2CMap.uBx26.bF.LP_Fc = 0x00;
// 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));
return err;
}
//-------------------------------------------------------------------------------------
// FUNCTION: TDA18271Write
//
// DESCRIPTION: This function writes I2C data in the Tuner
//
// RETURN: True or False
//
// NOTES:
//-------------------------------------------------------------------------------------
//
tmErrorCode_t
TDA18271Write
(
ptmTDA18271Object_t pObj, /* I: Driver object */
UInt8 uSubAddress, /* I: sub address */
UInt8 uNbData /* I: nb of data */
)
{
tmErrorCode_t err = TM_OK;
UInt8* pI2CMap = Null;
// test the Object
if (pObj == Null || pObj->init == False)
{
tmDBGPRINTEx(DEBUGLVL_ERROR, "TDA18271 Instance not initialized.");
return TDA18271_ERR_NOT_INITIALIZED;
}
// force I2CMap
pObj->I2CMap.uBx03.bF.Dis_Power_level = (UInt8)pObj->Config.uPLMODE;
// pI2CMap & pWriteBuffer initialization
pI2CMap = &(pObj->I2CMap.uBx00.ID_BYTE);
err = POBJ_SRVFUNC_SIO.Write (pObj->tUnit, 1, &uSubAddress, uNbData, &(pI2CMap[uSubAddress]));
// return value
return err;
}
//-------------------------------------------------------------------------------------
// FUNCTION: TDA18271Read
//
// DESCRIPTION: This function reads I2C data from the Tuner
//
// RETURN: True or False
//
// NOTES:
//-------------------------------------------------------------------------------------
//
tmErrorCode_t
TDA18271Read
(
ptmTDA18271Object_t pObj, /* I: Driver object */
UInt8 uSubAddress, /* I: sub address */
UInt8 uNbData /* I: nb of data */
)
{
tmErrorCode_t err = TM_OK;
UInt8 uCounter = 0;
UInt8* pI2CMap = Null;
UInt8 ReadBuffer[TDA18271_NB_BYTES] = {0};
UInt8* pReadBuffer = Null;
err = POBJ_SRVFUNC_SIO.Read (pObj->tUnit, 0, Null, uNbData, &(ReadBuffer[0]));
// pI2CMap & pReadBuffer initialization
pI2CMap = &(pObj->I2CMap.uBx00.ID_BYTE) + uSubAddress;
pReadBuffer = &(ReadBuffer[uSubAddress]);
// copy read data in I2CMap
for (uCounter = 0; uCounter < uNbData; uCounter++)
{
*pI2CMap = (UInt8)(*pReadBuffer);
pI2CMap ++;
pReadBuffer ++;
}
// return value
return err;
}
#ifndef BSLTDA18271_DLFRONTEND
//-------------------------------------------------------------------------------------
// FUNCTION: TDA18271ShiftLog
//
// DESCRIPTION: Shift I2CLog content of wanted lines
//
// RETURN: True
//
// NOTES:
//-------------------------------------------------------------------------------------
//
Bool
TDA18271ShiftLog
(
ptmTDA18271Object_t pObj, /* I: Driver object */
UInt32 uNbRows /* I: nb of lines */
)
{
UInt32 uRow = 0;
UInt8 uColumn = 0;
UInt32 uCounter = 0;
// test the Object
if (pObj == Null || pObj->init == False)
{
tmDBGPRINTEx(DEBUGLVL_ERROR, "TDA18271 Instance not initialized.");
return TDA18271_ERR_NOT_INITIALIZED;
}
// Shift I2CLog content of wanted lines
for (uCounter = 0; uCounter < uNbRows; uCounter++)
{
for (uRow = TDA18271_LOG_NB_ROWS - 1; uRow > 0; uRow--)
{
for (uColumn = 0; uColumn < TDA18271_NB_BYTES + 2; uColumn++)
pObj->I2CLog [uRow][uColumn] = pObj->I2CLog [uRow - 1][uColumn];
}
for (uColumn = 0; uColumn < TDA18271_NB_BYTES + 2; uColumn++)
pObj->I2CLog [0][uColumn] = TDA18271_LOG_BLANK_DATA;
}
// Return value
return True;
}
//-----------------------------------------------------------------------------
// FUNCTION: TDA18271InitTick
//
// DESCRIPTION: this function will delay for the number of millisecond
//
// RETURN: nothing
//
// NOTES:
//-----------------------------------------------------------------------------
//
Bool
TDA18271InitTick(
ptmTDA18271Object_t pObj, /* I: Driver object */
UInt16 wTime /* I: time to wait for */
)
{
UInt32 uCurrentTick = 0;
// test the Object
if (pObj == Null || pObj->init == False)
return False;
// get current tick
uCurrentTick = _SYSTEMFUNC.SY_GetTickTime();
// Calculate end tick
pObj->uTickEnd = (UInt32)wTime;
pObj->uTickEnd += _SYSTEMFUNC.SY_GetTickPeriod()/2;
pObj->uTickEnd /= _SYSTEMFUNC.SY_GetTickPeriod();
pObj->uTickEnd += uCurrentTick;
// always add 1 because of rounding issue
if (wTime)
pObj->uTickEnd++;
// test overflow
if (pObj->uTickEnd < uCurrentTick)
return False;
else
return True;
}
//-----------------------------------------------------------------------------
// FUNCTION: TDA18271WaitTick
//
// DESCRIPTION: this function will block for the number of millisecond
//
// RETURN: True if time has elapsed else False
//
// NOTES:
//-----------------------------------------------------------------------------
//
Bool
TDA18271WaitTick
(
ptmTDA18271Object_t pObj /* I: Driver object */
)
{
// test the Object
if (pObj == Null || pObj->init == False)
return False;
// test if time has elapsed
if (_SYSTEMFUNC.SY_GetTickTime() >= pObj->uTickEnd)
return True;
else
return False;
}
#endif
//-------------------------------------------------------------------------------------
// FUNCTION: TDA18271Wait
//
// DESCRIPTION: This function waits for requested time
//
// RETURN: True or False
//
// NOTES:
//-------------------------------------------------------------------------------------
//
tmErrorCode_t
TDA18271Wait
(
ptmTDA18271Object_t pObj, /* I: Driver object */
UInt16 wTime /* I: time to wait for */
)
{
tmErrorCode_t err = TM_OK;
// test the Object
if (pObj == Null || pObj->init == False)
{
tmDBGPRINTEx(DEBUGLVL_ERROR, "TDA18271 Instance not initialized.");
return TDA18271_ERR_NOT_INITIALIZED;
}
// wait wTime ms
err = POBJ_SRVFUNC_STIME.Wait (pObj->tUnit, wTime);
// Return value
return err;
}
//-------------------------------------------------------------------------------------
// FUNCTION: TDA18271CalcMAINPLL:
//
// DESCRIPTION: Calculate the MAIN fractional PLL settings
//
// RETURN: True or False
//
// NOTES: This function doesn't write in the tuner
//-------------------------------------------------------------------------------------
//
tmErrorCode_t
TDA18271CalcMAINPLL(
ptmTDA18271Object_t pObj, /* I: Driver object */
UInt32 uLO /* I: Local oscillator frequency in hertz */
)
{
UInt8 uCounter = 0;
UInt32 uDiv = 0;
// test the Object
if (pObj == Null || pObj->init == False)
{
tmDBGPRINTEx(DEBUGLVL_ERROR, "TDA18271 Instance not initialized.");
return TDA18271_ERR_NOT_INITIALIZED;
}
// search for MAIN_Post_Div corresponding to uLO
do uCounter ++;
while (uLO > pObj->Config.MAIN_PLL_Map[uCounter - 1].uLO_Max && uCounter < TDA18271_MAIN_PLL_NB_ROWS);
pObj->I2CMap.uBx0C.bF.MAIN_Post_Div = ((UInt8)pObj->Config.MAIN_PLL_Map[uCounter - 1].uPost_Div) & 0x77;
// calculate MAIN_Div
uDiv = (((UInt32)(pObj->Config.MAIN_PLL_Map[uCounter - 1].uDiv) * (uLO / 1000)) << 7) / 125;
pObj->I2CMap.uBx0D.bF.MAIN_Div_22_to_16 = (UInt8)(uDiv >> 16) & 0x7F;
pObj->I2CMap.uBx0E.bF.MAIN_Div_15_to_8 = (UInt8)(uDiv >> 8);
pObj->I2CMap.uBx0F.bF.MAIN_Div_7_to_0 = (UInt8)(uDiv);
return TM_OK;
}
//-------------------------------------------------------------------------------------
// FUNCTION: TDA18271CalcCALPLL:
//
// DESCRIPTION: Calculate the CAL fractional PLL settings
//
// RETURN: True or False
//
// NOTES: This function doesn't write in the tuner
//-------------------------------------------------------------------------------------
//
tmErrorCode_t
TDA18271CalcCALPLL
(
ptmTDA18271Object_t pObj, /* I: Driver object */
UInt32 uLO /* I: Local oscillator frequency in hertz */
)
{
UInt8 uCounter = 0;
UInt32 uDiv;
// test the Object
if (pObj == Null || pObj->init == False)
{
tmDBGPRINTEx(DEBUGLVL_ERROR, "TDA18271 Instance not initialized.");
return TDA18271_ERR_NOT_INITIALIZED;
}
// search for CAL_Post_Div corresponding to uLO
do uCounter ++;
while (uLO > pObj->Config.CAL_PLL_Ma
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -