📄 tmbsltuner.c
字号:
// test the object
if (gTunerInstance[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 (gTunerInstance[TunerUnit].systemFunc.SY_Read(
gTunerInstance[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] = gTunerInstance[TunerUnit].pTunerReg[uCounter];
}
return TM_OK;
}
//-----------------------------------------------------------------------------
// FUNCTION: tmbslTunerSetConfig:
//
// DESCRIPTION: Set the config of the Tuner
//
// RETURN: TMBSL_ERR_TUNER_BAD_UNIT_NUMBER
// TMBSL_ERR_TUNER_NOT_INITIALIZED
// TM_OK
//
// NOTES:
//-----------------------------------------------------------------------------
//
tmErrorCode_t
tmbslTunerSetConfig(
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 (gTunerInstance[TunerUnit].init == False)
return TMBSL_ERR_TUNER_NOT_INITIALIZED;
//--------------
// set the value
//--------------
switch((tmTunercfgIndex_t)uItemId)
{
case DEFAULTCU1216TUNER:
// default hardware config
gTunerInstance[TunerUnit].config.uBandwidth = BANDWIDTH_DEF;
gTunerInstance[TunerUnit].config.bAtc = ATC_DEF;
gTunerInstance[TunerUnit].config.bTop = TOP_DEF;
// specific soft config
switch (uValue & 0x000000ff)
{
case 0x00:
gTunerInstance[TunerUnit].uPllStep = 62500;
break;
case 0x01:
gTunerInstance[TunerUnit].uPllStep = 166666;
break;
case 0x02:
gTunerInstance[TunerUnit].uPllStep = 50000;
break;
case 0x03:
gTunerInstance[TunerUnit].uPllStep = 31250;
break;
case 0x04:
gTunerInstance[TunerUnit].uPllStep = 125000;
break;
case 0x05:
gTunerInstance[TunerUnit].uPllStep = 142860;
break;
default:
// board not supported
return TM_ERR_NOT_SUPPORTED;
}
break;
case BANDWIDTH:
gTunerInstance[TunerUnit].config.uBandwidth = uValue;
break;
case ATC:
gTunerInstance[TunerUnit].config.bAtc = (UInt8)uValue & 0x01;
break;
case TOP:
gTunerInstance[TunerUnit].config.bTop = (UInt8)uValue & 0x07;
break;
default:
return TMBSL_ERR_TUNER_BAD_PARAMETER;
}
return TM_OK;
}
//-----------------------------------------------------------------------------
// FUNCTION: tmbslTunerGetConfig:
//
// DESCRIPTION: Get the config of the Tuner
//
// RETURN: TMBSL_ERR_TUNER_BAD_UNIT_NUMBER
// TMBSL_ERR_TUNER_NOT_INITIALIZED
// TM_OK
//
// NOTES:
//-----------------------------------------------------------------------------
//
tmErrorCode_t
tmbslTunerGetConfig(
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 (gTunerInstance[TunerUnit].init == False)
return TMBSL_ERR_TUNER_NOT_INITIALIZED;
//Xiaohai
//--------------
// get the value
//--------------
switch((tmTunercfgIndex_t)uItemId)
{
case BANDWIDTH:
*puValue = gTunerInstance[TunerUnit].config.uBandwidth;
break;
case ATC:
*puValue = gTunerInstance[TunerUnit].config.bAtc;
break;
case TOP:
*puValue = gTunerInstance[TunerUnit].config.bTop;
break;
case GETNBOFCU1216UNIT:
*puValue = MAX_UNITS;
break;
default:
return TMBSL_ERR_TUNER_BAD_PARAMETER;
}
//Xiaohai
return TM_OK;
}
//-----------------------------------------------------------------------------
// FUNCTION: tmbslTunerSetRf:
//
// DESCRIPTION: Set the PLL of the Tuner
//
// 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
tmbslTunerSetRf(
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 (gTunerInstance[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
tTunerCalcReg(&gTunerInstance[TunerUnit], &uRf);
//Xiaohai
// write in the tuner
// first, CB + AB bytes
/*if (gTunerInstance[TunerUnit].systemFunc.SY_Write(
gTunerInstance[TunerUnit].uHwAddress,
0, 2, &gTunerInstance[TunerUnit].pTunerReg[4]) != 1)
return TMBSL_ERR_IIC_ERR;
*/
// then all the other bytes, DB1, DB2, CB and BB
if (gTunerInstance[TunerUnit].systemFunc.SY_Write(
gTunerInstance[TunerUnit].uHwAddress,
0, 4, gTunerInstance[TunerUnit].pTunerReg) != 1)
return TMBSL_ERR_IIC_ERR;
//Xiaohai
// store value
gTunerInstance[TunerUnit].uRfProg = uRf;
return TM_OK;
}
//-----------------------------------------------------------------------------
// FUNCTION: tmbslTunerGetRf:
//
// 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
tmbslTunerGetRf(
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 (gTunerInstance[TunerUnit].init == False)
return TMBSL_ERR_TUNER_NOT_INITIALIZED;
//--------------
// get the value
//--------------
// the read function can't be used
*puRf = gTunerInstance[TunerUnit].uRfProg;
return TM_OK;
}
//-----------------------------------------------------------------------------
// Internal functions:
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
// FUNCTION: tTunerCalcReg:
//
// 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
tTunerCalcReg (
ptmTunerobject_t pTunerobject, // I: tuner object
UInt32* puRf // IO: frequency in hertz
)
{
//Xiaohai
UInt32 uFreqPll;
// calculate N0-N14
uFreqPll = *puRf;
uFreqPll += pTunerobject->uPllStep/2;
uFreqPll /= pTunerobject->uPllStep;
// real frequency programmed
pTunerobject->uRfProg = uFreqPll * pTunerobject->uPllStep;
//-------------
// byte 0 and 1
//-------------
// divider ratio
pTunerobject->pTunerReg[0] = (UInt8)(uFreqPll >> 8);
pTunerobject->pTunerReg[1] = (UInt8)uFreqPll;
//-------
// byte 2
//-------
pTunerobject->pTunerReg[2] = 0x8E&0xF9;
switch (pTunerobject->uPllStep)
{
case 166666:
pTunerobject->pTunerReg[2] |= 0x04;
break;
case 62500:
pTunerobject->pTunerReg[2] |= 0x06;
break;
case 50000: case 125000:
pTunerobject->pTunerReg[2] |= 0x00;
break;
case 31250: case 142860:
pTunerobject->pTunerReg[2] |= 0x02;
break;
}
//-------
// byte 3
//-------
pTunerobject->pTunerReg[3] &= 0xF8;
if (pTunerobject->uRfProg < (160000000 + 36125000))
pTunerobject->pTunerReg[3] |= 0x01;
else if (pTunerobject->uRfProg > (446000000 + 36125000)) // high band
pTunerobject->pTunerReg[3] |= 0x04;
else // mid band
pTunerobject->pTunerReg[3] |= 0x02;
//-------
// byte 4 = byte 2 with T2T1T0 = 011 for AB Byte Xfer
//-------
pTunerobject->pTunerReg[4] = pTunerobject->pTunerReg[2] & 0xC7; // mask first //Different from Laruent, Xiaohai
pTunerobject->pTunerReg[4] |= 0x18; // T2T1T0 = 011 //Different from Laruent, Xiaohai
//-------
// byte 5 = AB byte
//-------
pTunerobject->pTunerReg[5] = 0x00 | pTunerobject->config.bAtc << 7
| pTunerobject->config.bTop << 4;
return True;
//Xiaohai
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -