/**

@brief   Get tuner RSSI value when calibration is on.

One can use rtl2832_fc0013_GetTunerRssiCalOn() to get tuner calibration-on RSSI value.


@param [in]   pNim   The NIM module pointer


@retval   FUNCTION_SUCCESS   Get tuner calibration-on RSSI value successfully.
@retval   FUNCTION_ERROR     Get tuner calibration-on RSSI value unsuccessfully.

*/
int
rtl2832_fc0013_GetTunerRssiCalOn(
	DVBT_NIM_MODULE *pNim
	)
{
	TUNER_MODULE *pTuner;
	DVBT_DEMOD_MODULE *pDemod;
	FC0013_EXTRA_MODULE *pTunerExtra;
	RTL2832_FC0013_EXTRA_MODULE *pNimExtra;
	BASE_INTERFACE_MODULE *pBaseInterface;



	// Get tuner module and demod module.
	pTuner = pNim->pTuner;
	pDemod = pNim->pDemod;

	// Get tuner extra module.
	pTunerExtra = &(pTuner->Extra.Fc0013);

	// Get NIM extra module.
	pNimExtra = &(pNim->Extra.Rtl2832Fc0013);

	// Get NIM base interface.
	pBaseInterface = pNim->pBaseInterface;


	// Set tuner EN_CAL_RSSI to 0x1.
	if(fc0013_SetRegMaskBits(pTuner, 0x9, 4, 4, 0x1) != FC0013_I2C_SUCCESS)
		goto error_status_set_registers;

	// Set tuner LNA_POWER_DOWN to 0x1.
	if(fc0013_SetRegMaskBits(pTuner, 0x6, 0, 0, 0x1) != FC0013_I2C_SUCCESS)
		goto error_status_set_registers;

	// Wait 100 ms.
	pBaseInterface->WaitMs(pBaseInterface, 100);

	// Get demod RSSI_R when tuner RSSI calibration is on.
	if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RSSI_R, &(pNimExtra->RssiRCalOn)) != FUNCTION_SUCCESS)
		goto error_status_get_registers;


	// Set tuner EN_CAL_RSSI to 0x0.
	if(fc0013_SetRegMaskBits(pTuner, 0x9, 4, 4, 0x0) != FC0013_I2C_SUCCESS)
		goto error_status_set_registers;

	// Set tuner LNA_POWER_DOWN to 0x0.
	if(fc0013_SetRegMaskBits(pTuner, 0x6, 0, 0, 0x0) != FC0013_I2C_SUCCESS)
		goto error_status_set_registers;


	return FUNCTION_SUCCESS;


error_status_get_registers:
error_status_set_registers:
	return FUNCTION_ERROR;
}
Example #2
0
//void MxL_Delay(UINT32 mSec)
void MxL_Delay(MxL5007_TunerConfigS* myTuner, UINT32 mSec)
{
	TUNER_MODULE *pTuner;
	BASE_INTERFACE_MODULE *pBaseInterface;



	// Get tuner module and base interface.
	pTuner = myTuner->pTuner;
	pBaseInterface = pTuner->pBaseInterface;

	// Wait in ms.
	pBaseInterface->WaitMs(pBaseInterface, mSec);


	return;
}
int tua9001waitloop (TUNER_MODULE *pTuner, unsigned int i_looptime)
{
	BASE_INTERFACE_MODULE *pBaseInterface;
	unsigned long WaitTimeMs;


	// Get base interface.
	pBaseInterface = pTuner->pBaseInterface;

	/* wait time = i_looptime * 1 uS */
	// Note: 1. The unit of WaitMs() function is ms.
	//       2. WaitTimeMs = ceil(i_looptime / 1000)
	WaitTimeMs = i_looptime / 1000;

	if((i_looptime % 1000) > 0)
		WaitTimeMs += 1;

	pBaseInterface->WaitMs(pBaseInterface, WaitTimeMs);


	return TUA9001_TUNER_OK;
}
Example #4
0
/**

@see   DTMB_NIM_FP_IS_SIGNAL_LOCKED

*/
s32
dtmb_nim_default_IsSignalLocked(
	DTMB_NIM_MODULE *pNim,
	s32 *pAnswer
	)
{
	BASE_INTERFACE_MODULE *pBaseInterface;
	DTMB_DEMOD_MODULE *pDemod;
	s32 i;


	// Get base interface and demod module.
	pBaseInterface = pNim->pBaseInterface;
	pDemod         = pNim->pDemod;


	// Wait for signal lock check.
	for(i = 0; i < DTMB_NIM_SINGAL_LOCK_CHECK_TIMES_MAX_DEFAULT; i++)
	{
		// Wait 20 ms.
		pBaseInterface->WaitMs(pBaseInterface, 20);

		// Check signal lock status on demod.
		// Note: If signal is locked, stop signal lock check.
		if(pDemod->IsSignalLocked(pDemod, pAnswer) != FUNCTION_SUCCESS)
			goto error_status_execute_function;

		if(*pAnswer == YES)
			break;
	}


	return FUNCTION_SUCCESS;


error_status_execute_function:
	return FUNCTION_ERROR;
}
/**

@see   QAM_NIM_FP_IS_SIGNAL_LOCKED

*/
int
qam_nim_default_IsSignalLocked(
	QAM_NIM_MODULE *pNim,
	int *pAnswer
	)
{
	BASE_INTERFACE_MODULE *pBaseInterface;
	QAM_DEMOD_MODULE *pDemod;
	int i;


	// Get base interface and demod module.
	pBaseInterface = pNim->pBaseInterface;
	pDemod         = pNim->pDemod;


	// Wait maximum 1000 ms for signal lock check.
	for(i = 0; i < DEFAULT_QAM_NIM_SINGAL_LOCK_CHECK_TIMES_MAX; i++)
	{
		// Wait 20 ms.
		pBaseInterface->WaitMs(pBaseInterface, 20);

		// Check frame lock status on demod.
		// Note: If frame is locked, stop signal lock check.
		if(pDemod->IsFrameLocked(pDemod, pAnswer) != FUNCTION_SUCCESS)
			goto error_status_execute_function;

		if(*pAnswer == YES)
			break;
	}


	return FUNCTION_SUCCESS;


error_status_execute_function:
	return FUNCTION_ERROR;
}
Example #6
0
/**

@see   TUNER_FP_SET_RF_FREQ_HZ

*/
int
gtlp10_SetRfFreqHz(
	TUNER_MODULE *pTuner,
	unsigned long RfFreqHz
	)
{
	GTLP10_EXTRA_MODULE *pExtra;
	BASE_INTERFACE_MODULE *pBaseInterface;
	I2C_BRIDGE_MODULE *pI2cBridge;
	unsigned char DeviceAddr;

	int i;
	unsigned char WritingBytes[LEN_5_BYTE];
	unsigned char ReadingBytes[LEN_1_BYTE];

	unsigned long Divider;
	int LockStatus;

	MPI MpiDivider, MpiVar, MpiConst, MpiNone;
	long RfFreqHzInt;



	// Get tuner extra module and I2C bridge.
	pExtra = &(pTuner->Extra.Gtlp10);
	pBaseInterface = pTuner->pBaseInterface;
	pI2cBridge = pTuner->pI2cBridge;

	// Get tuner device address.
	pTuner->GetDeviceAddr(pTuner, &DeviceAddr);


	// Set DividerMsb and DividerLsb according to RF frequnecy in Hz.
	// Note: 1. Origin divider equation:
	//          Divider = round((RF_freq_MHz + 36.125) / (1 / 6))
	//                  = round((RF_freq_MHz + 36.125) * 6)
	//                  = floor((RF_freq_MHz + 36.125) * 6 + 0.5)
	//                  = floor(((RF_freq_Hz + 36125000 ) * 6 + 500000) / 1000000)
	//                  = floor(((RF_freq_Hz + 36125000) * 3 + 250000) / 500000)
	Divider = ((RfFreqHz + 36125000) * 3 + 250000) / 500000;
	Divider &= GTLP10_DIVIDER_MASK;
	pExtra->DividerMsb = (unsigned char)((Divider >> BYTE_SHIFT) & BYTE_MASK);
	pExtra->DividerLsb = (unsigned char)(Divider & BYTE_MASK);


	// Set Control2 according to RF frequency in Hz.
	if(RfFreqHz < 100000000)
	{
		pExtra->Control2 = 0x41;
	}
	else if(RfFreqHz < 122000000)
	{
		pExtra->Control2 = 0x61;
	}
	else if(RfFreqHz < 129000000)
	{
		pExtra->Control2 = 0x81;
	}
	else if(RfFreqHz < 136000000)
	{
		pExtra->Control2 = 0xa1;
	}
	else if(RfFreqHz < 147000000)
	{
		pExtra->Control2 = 0xc1;
	}
	else if(RfFreqHz < 240000000)
	{
		pExtra->Control2 = 0x22;
	}
	else if(RfFreqHz < 310000000)
	{
		pExtra->Control2 = 0x42;
	}
	else if(RfFreqHz < 380000000)
	{
		pExtra->Control2 = 0x62;
	}
	else if(RfFreqHz < 430000000)
	{
		pExtra->Control2 = 0x82;
	}
	else if(RfFreqHz < 578000000)
	{
		pExtra->Control2 = 0x84;
	}
	else if(RfFreqHz < 650000000)
	{
		pExtra->Control2 = 0xa4;
	}
	else if(RfFreqHz < 746000000)
	{
		pExtra->Control2 = 0xc4;
	}
	else
	{
		pExtra->Control2 = 0xe4;
	}


	// Set tuner registers.
	WritingBytes[0] = pExtra->DividerMsb;
	WritingBytes[1] = pExtra->DividerLsb;
	WritingBytes[2] = pExtra->Control1;
	WritingBytes[3] = pExtra->Control2;
	WritingBytes[4] = pExtra->Control3;

	if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, DeviceAddr, WritingBytes, LEN_5_BYTE) != FUNCTION_SUCCESS)
		goto error_status_set_tuner_registers;


	// Wait maximum 100 ms for tuner LO lock.
	for(i = 0, LockStatus = NO; i < GTLP10_LO_LOCK_CHECK_TIMES_MAX; i++)
	{
		// Wait 2 ms.
		pBaseInterface->WaitMs(pBaseInterface, 2);


		// Check tuner LO lock status.
		if(pI2cBridge->ForwardI2cReadingCmd(pI2cBridge, DeviceAddr, ReadingBytes, LEN_1_BYTE) != FUNCTION_SUCCESS)
			goto error_status_get_tuner_registers;

		if((ReadingBytes[0] & GTLP10_LO_LOCK_MASK) == GTLP10_LO_LOCK_MASK)
		{
			// LO is locked.
			LockStatus = YES;
			break;
		}
	}

	
	// Check tuner LO lock status.
	if(LockStatus == NO)
		goto error_status_tuner_lo_lock;


	// Set tuner RF frequency parameter.
	// Note: Origin actual RF frequency equation:
	//       Actual_RF_freq_Hz = round(Divider * 1000000 * (1 / 6) - 36125000)
	//                         = round(Divider * 1000000 / 6 - 36125000)
	//                         = floor(Divider * 1000000 / 6 - 36125000 + 0.5)
	//                         = floor((Divider * 1000000 - 216750000 + 3) / 6)
	//                         = floor((Divider * 1000000 - 216749997) / 6)
	MpiSetValue(&MpiDivider, Divider);

	MpiSetValue(&MpiConst, 1000000);
	MpiMul(&MpiVar, MpiDivider, MpiConst);

	MpiSetValue(&MpiConst, 216749997);
	MpiSub(&MpiVar, MpiVar, MpiConst);

	MpiSetValue(&MpiConst, 6);
	MpiDiv(&MpiVar, &MpiNone, MpiVar, MpiConst);

	MpiGetValue(MpiVar, &RfFreqHzInt);

	pTuner->RfFreqHz      = (unsigned long)RfFreqHzInt;
	pTuner->IsRfFreqHzSet = YES;


	return FUNCTION_SUCCESS;


error_status_tuner_lo_lock:
error_status_get_tuner_registers:
error_status_set_tuner_registers:
	return FUNCTION_ERROR;
}