📄 tmbsltuner.c
字号:
if (TunerUnit > MAX_UNITS)
return TMBSL_ERR_TUNER_BAD_UNIT_NUMBER;
// test the object
if (g1316Instance[TunerUnit].init == False)
return TMBSL_ERR_TUNER_NOT_INITIALIZED;
// test the object
if (uNbBytes > NB_REGISTERS)
return TMBSL_ERR_TUNER_BAD_PARAMETER;
//--------------
// get the value
//--------------
if (uIndex == -1)
{
// read the status byte if index is -1
if (g1316Instance[TunerUnit].systemFunc.SY_Read(
g1316Instance[TunerUnit].uHwAddress,
0, 1, puBytes) != 1)
return TMBSL_ERR_IIC_ERR;
}
else
{
UInt32 uCounter;
// return value previously written
for (uCounter = uIndex; uCounter < uNbBytes; uCounter++)
puBytes[uCounter-uIndex] = g1316Instance[TunerUnit].pTunerReg[uCounter];
}
return TM_OK;
}
//-----------------------------------------------------------------------------
// FUNCTION: tmbsl1316SetConfig:
//
// DESCRIPTION: Set the config of the 1316
//
// RETURN: TMBSL_ERR_TUNER_BAD_UNIT_NUMBER
// TMBSL_ERR_TUNER_NOT_INITIALIZED
// TM_OK
//
// NOTES:
//-----------------------------------------------------------------------------
//
tmErrorCode_t
tmbsl1316SetConfig(
tmUnitSelect_t TunerUnit, // I: TunerUnit number
UInt32 uItemId, // I: Identifier of the item to modify
UInt32 uValue // I: Value to set for the config item
)
{
//----------------------
// test input parameters
//----------------------
// test the instance number
if (TunerUnit > MAX_UNITS)
return TMBSL_ERR_TUNER_BAD_UNIT_NUMBER;
// test the object
if (g1316Instance[TunerUnit].init == False)
return TMBSL_ERR_TUNER_NOT_INITIALIZED;
//--------------
// set the value
//--------------
switch((tm1316cfgIndex_t)uItemId)
{
case BOARD:
// default hardware config
g1316Instance[TunerUnit].config.uBandwidth = OM57XX_BANDWIDTH_DEF;
g1316Instance[TunerUnit].config.bAtc = OM57XX_ATC_DEF;
g1316Instance[TunerUnit].config.bTop = OM57XX_TOP_DEF;
// specific soft config
switch (uValue & 0x000000ff)
{
case 0x00:
g1316Instance[TunerUnit].uPllStep = 166666;
break;
case 0x01:
g1316Instance[TunerUnit].uPllStep = 62500;
break;
default:
return TM_ERR_NOT_SUPPORTED;
}
// specific board config
// none
// store board
g1316Instance[TunerUnit].config.uBoard = uValue;
break;
case BANDWIDTH:
g1316Instance[TunerUnit].config.uBandwidth = uValue;
break;
case ATC:
g1316Instance[TunerUnit].config.bAtc = (UInt8)uValue;
break;
case TOP:
g1316Instance[TunerUnit].config.bTop = (UInt8)uValue;
break;
default:
return TMBSL_ERR_TUNER_BAD_PARAMETER;
}
return TM_OK;
}
//-----------------------------------------------------------------------------
// FUNCTION: tmbsl1316GetConfig:
//
// DESCRIPTION: Get the config of the 1316
//
// RETURN: TMBSL_ERR_TUNER_BAD_UNIT_NUMBER
// TMBSL_ERR_TUNER_NOT_INITIALIZED
// TM_OK
//
// NOTES:
//-----------------------------------------------------------------------------
//
tmErrorCode_t
tmbsl1316GetConfig(
tmUnitSelect_t TunerUnit, // I: Tuner unit number
UInt32 uItemId, // I: Identifier of the item to modify
UInt32* puValue // I: Value to set for the config item
)
{
//----------------------
// test input parameters
//----------------------
// test the instance number
if (TunerUnit > MAX_UNITS)
return TMBSL_ERR_TUNER_BAD_UNIT_NUMBER;
// test the object
if (g1316Instance[TunerUnit].init == False)
return TMBSL_ERR_TUNER_NOT_INITIALIZED;
//--------------
// get the value
//--------------
switch((tm1316cfgIndex_t)uItemId)
{
case BOARD:
*puValue = g1316Instance[TunerUnit].config.uBoard;
break;
case BANDWIDTH:
*puValue = g1316Instance[TunerUnit].config.uBandwidth;
break;
case ATC:
*puValue = g1316Instance[TunerUnit].config.bAtc;
break;
case TOP:
*puValue = g1316Instance[TunerUnit].config.bTop;
break;
case GETNBOFUNIT:
*puValue = MAX_UNITS;
break;
default:
return TMBSL_ERR_TUNER_BAD_PARAMETER;
}
return TM_OK;
}
//-----------------------------------------------------------------------------
// FUNCTION: tmbsl1316SetRf:
//
// DESCRIPTION: Set the PLL of the 1316
//
// RETURN: TMBSL_ERR_TUNER_BAD_UNIT_NUMBER
// TMBSL_ERR_TUNER_NOT_INITIALIZED
// TMBSL_ERR_TUNER_BAD_PARAMETER
// TMBSL_ERR_IIC_ERR
// TM_OK
//
// NOTES:
//-----------------------------------------------------------------------------
//
tmErrorCode_t
tmbsl1316SetRf(
tmUnitSelect_t TunerUnit, // I: Tuner unit number
UInt32 uRf // I: Frequency in hertz
)
{
//----------------------
// test input parameters
//----------------------
// test the instance number
if (TunerUnit > MAX_UNITS)
return TMBSL_ERR_TUNER_BAD_UNIT_NUMBER;
// test the object
if (g1316Instance[TunerUnit].init == False)
return TMBSL_ERR_TUNER_NOT_INITIALIZED;
// don't test the RF to avoid side effect during scanning
//if(uRf < RF_MIN || uRf > RF_MAX)
// return TMBSL_ERR_TUNER_BAD_PARAMETER;
//--------------
// set the value
//--------------
// calculate the tuner reg
t1316CalcReg(&g1316Instance[TunerUnit], uRf);
// write in the tuner
if (g1316Instance[TunerUnit].systemFunc.SY_Write(
g1316Instance[TunerUnit].uHwAddress,
0, NB_REGISTERS, g1316Instance[TunerUnit].pTunerReg) != 1)
return TMBSL_ERR_IIC_ERR;
return TM_OK;
}
//-----------------------------------------------------------------------------
// FUNCTION: tmbsl1316GetRf:
//
// DESCRIPTION: Get the frequency programmed in the tuner
//
// RETURN: TMBSL_ERR_TUNER_BAD_UNIT_NUMBER
// TMBSL_ERR_TUNER_NOT_INITIALIZED
// TM_OK
//
// NOTES: The value returned is the one stored in the object
//-----------------------------------------------------------------------------
//
tmErrorCode_t
tmbsl1316GetRf(
tmUnitSelect_t TunerUnit, // I: Tuner unit number
UInt32* puRf // O: Frequency in hertz
)
{
//----------------------
// test input parameters
//----------------------
// test the instance number
if (TunerUnit > MAX_UNITS)
return TMBSL_ERR_TUNER_BAD_UNIT_NUMBER;
// test the object
if (g1316Instance[TunerUnit].init == False)
return TMBSL_ERR_TUNER_NOT_INITIALIZED;
//--------------
// get the value
//--------------
// the read function can't be used
*puRf = g1316Instance[TunerUnit].uRfProg;
return TM_OK;
}
//-----------------------------------------------------------------------------
// Internal functions:
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
// FUNCTION: t1316CalcReg:
//
// DESCRIPTION: Calculate the value to set in the registers of the tuner
//
// RETURN: always true
//
// NOTES: This function doesn't write in the tuner
//-----------------------------------------------------------------------------
//
Bool
t1316CalcReg (
ptm1316object_t p1316object, // I: tuner object
UInt32 uRf // I: frequency in hertz
)
{
UInt32 uFreqPll;
// calculate N0-N14
uFreqPll = uRf;
uFreqPll += p1316object->uPllStep/2;
uFreqPll /= p1316object->uPllStep;
// real frequency programmed
p1316object->uRfProg = uFreqPll * p1316object->uPllStep;
//-------------
// byte 0 and 1
//-------------
// divider ratio
p1316object->pTunerReg[0] = (UInt8)(uFreqPll >> 8);
p1316object->pTunerReg[1] = (UInt8)uFreqPll;
//-------
// byte 2
//-------
if (166666 == p1316object->uPllStep)
p1316object->pTunerReg[2] = 0xCA;
else
p1316object->pTunerReg[2] = 0xC8;
//-------
// byte 3
//-------
// charge pump and SAW filter selection
if (uRf < 130000000)
p1316object->pTunerReg[3] = 0x61;
else if (uRf < 160000000)
p1316object->pTunerReg[3] = 0xA1;
else if (uRf < 200000000)
p1316object->pTunerReg[3] = 0xC1;
else if (uRf < 290000000)
p1316object->pTunerReg[3] = 0x62;
else if (uRf < 420000000)
p1316object->pTunerReg[3] = 0xA2;
else if (uRf < 480000000)
p1316object->pTunerReg[3] = 0xC2;
else if (uRf < 620000000)
p1316object->pTunerReg[3] = 0x64;
else if (uRf < 830000000)
p1316object->pTunerReg[3] = 0xA4;
else
p1316object->pTunerReg[3] = 0xC4;
// 8 MHz bandwidth
if (8000000 == p1316object->config.uBandwidth)
p1316object->pTunerReg[3] |= 0x08;
//-------
// byte 4
//-------
p1316object->pTunerReg[4] = 0x80 | p1316object->config.bAtc << 3
| p1316object->config.bTop;
//-------
// byte 5
//-------
p1316object->pTunerReg[5] = p1316object->pTunerReg[3];
return True;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -