Пример #1
0
/**

@see   DVBT_NIM_FP_GET_RF_POWER_LEVEL_DBM

*/
s32 rtl2832_tda18272_GetRfPowerLevelDbm(DVBT_NIM_MODULE *pNim, s64 *pRfPowerLevelDbm)
{
	DVBT_DEMOD_MODULE *pDemod;

	u64 FsmStage;
	s64 IfAgc;

	// Get demod module.
	pDemod = pNim->pDemod;

	// Get FSM stage and IF AGC value.
	if(pDemod->GetRegBitsWithPage(pDemod, DVBT_FSM_STAGE, &FsmStage) != FUNCTION_SUCCESS)
		goto error_status_get_registers;

	if(pDemod->GetIfAgc(pDemod, &IfAgc) != FUNCTION_SUCCESS)
		goto error_status_get_registers;

	//  Determine signal strength according to FSM stage and IF AGC value.
	if(FsmStage < 10)
		*pRfPowerLevelDbm = -120;
	else
	{
		if(IfAgc > -1250)
			*pRfPowerLevelDbm = -71 - (IfAgc / 165);
		else
			*pRfPowerLevelDbm = -60;
	}

	return FUNCTION_SUCCESS;

error_status_get_registers:
	return FUNCTION_ERROR;
}
Пример #2
0
// Additional definition for mt_control.c
UData_t
demod_get_pd(
	handle_t demod_handle,
	uint16_t *pd_value
	)
{
	DVBT_DEMOD_MODULE *pDemod;
	unsigned long RssiR;


	// Get demod module.
	pDemod = (DVBT_DEMOD_MODULE *)demod_handle;

	// Get RSSI_R value.
	if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RSSI_R, &RssiR) != FUNCTION_SUCCESS)
		goto error_status_get_registers;

	// Set pd_value according to RSSI_R.
	*pd_value = (uint16_t)RssiR;


	return MT_OK;


error_status_get_registers:
	return MT_COMM_ERR;
}
Пример #3
0
UData_t
demod_set_bbagclim(
	handle_t demod_handle,
	int on_off_status
	)
{
	DVBT_DEMOD_MODULE *pDemod;
	unsigned long IfAgcMinBinary;
	long IfAgcMinInt;


	// Get demod module.
	pDemod = (DVBT_DEMOD_MODULE *)demod_handle;

	// Get IF_AGC_MIN binary value.
	if(pDemod->GetRegBitsWithPage(pDemod, DVBT_IF_AGC_MIN, &IfAgcMinBinary) != FUNCTION_SUCCESS)
		goto error_status_get_registers;

	// Convert IF_AGC_MIN binary value to integer.
	IfAgcMinInt = BinToSignedInt(IfAgcMinBinary, RTL2832_MT2266_IF_AGC_MIN_BIT_NUM);

	// Modify IF_AGC_MIN integer according to on_off_status.
	switch(on_off_status)
	{
		case 1:

			IfAgcMinInt += RTL2832_MT2266_IF_AGC_MIN_INT_STEP;

			if(IfAgcMinInt > RTL2832_MT2266_IF_AGC_MIN_INT_MAX)
				IfAgcMinInt = RTL2832_MT2266_IF_AGC_MIN_INT_MAX;

			break;

		default:
		case 0:

			IfAgcMinInt -= RTL2832_MT2266_IF_AGC_MIN_INT_STEP;

			if(IfAgcMinInt < RTL2832_MT2266_IF_AGC_MIN_INT_MIN)
				IfAgcMinInt = RTL2832_MT2266_IF_AGC_MIN_INT_MIN;

			break;
	}

	// Convert modified IF_AGC_MIN integer to binary value.
	IfAgcMinBinary = SignedIntToBin(IfAgcMinInt, RTL2832_MT2266_IF_AGC_MIN_BIT_NUM);

	// Set IF_AGC_MIN with modified binary value.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IF_AGC_MIN, IfAgcMinBinary) != FUNCTION_SUCCESS)
		goto error_status_set_registers;


	return MT_OK;


error_status_set_registers:
error_status_get_registers:
	return MT_COMM_ERR;
}
/**

@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;
}
Пример #5
0
UData_t
tuner_set_bw_narrow(
	handle_t tuner_handle,
	handle_t demod_handle
	)
{
	DVBT_DEMOD_MODULE *pDemod;

	int DemodBandwidthMode;
	unsigned long AciDetInd;
	unsigned int TunerBandwidthHz;
	unsigned int TargetTunerBandwidthHz;


	// Get demod module.
	pDemod = (DVBT_DEMOD_MODULE *)demod_handle;

	// Get demod bandwidth mode.
	if(pDemod->GetBandwidthMode(pDemod, &DemodBandwidthMode) != FUNCTION_SUCCESS)
		goto error_status_execute_function;

	// Get demod ACI_DET_IND.
	if(pDemod->GetRegBitsWithPage(pDemod, DVBT_ACI_DET_IND, &AciDetInd) != FUNCTION_SUCCESS)
		goto error_status_get_registers;

	// Determine tuner target bandwidth according to ACI_DET_IND.
	if(AciDetInd == 0x1)
	{
		// Choose narrow target bandwidth.
		switch(DemodBandwidthMode)
		{
			case DVBT_BANDWIDTH_6MHZ:	TargetTunerBandwidthHz = MT2266_BANDWIDTH_5MHZ;		break;
			case DVBT_BANDWIDTH_7MHZ:	TargetTunerBandwidthHz = MT2266_BANDWIDTH_6MHZ;		break;
			default:
			case DVBT_BANDWIDTH_8MHZ:	TargetTunerBandwidthHz = MT2266_BANDWIDTH_7MHZ;		break;
		}
	}
	else
	{
		// Choose normal target bandwidth.
		switch(DemodBandwidthMode)
		{
			case DVBT_BANDWIDTH_6MHZ:	TargetTunerBandwidthHz = MT2266_BANDWIDTH_6MHZ;		break;
			case DVBT_BANDWIDTH_7MHZ:	TargetTunerBandwidthHz = MT2266_BANDWIDTH_7MHZ;		break;
			default:
			case DVBT_BANDWIDTH_8MHZ:	TargetTunerBandwidthHz = MT2266_BANDWIDTH_8MHZ;		break;
		}
	}

	// Get tuner bandwidth.
	if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_OUTPUT_BW, &TunerBandwidthHz)))
		goto error_status_get_tuner_bandwidth;

	// Set tuner bandwidth with normal setting according to demod bandwidth mode.
	if(TunerBandwidthHz != TargetTunerBandwidthHz)
	{
		if(MT_IS_ERROR(MT2266_SetParam(tuner_handle, MT2266_OUTPUT_BW, TargetTunerBandwidthHz)))
			goto error_status_set_tuner_bandwidth;
	}


	return MT_OK;


error_status_set_tuner_bandwidth:
error_status_get_tuner_bandwidth:
error_status_get_registers:
error_status_execute_function:
	return MT_COMM_ERR;
}
/**

@brief   Update tuner LNA_GAIN with RSSI.

One can use rtl2832_fc0013_UpdateTunerLnaGainWithRssi() to update tuner LNA_GAIN with RSSI.


@param [in]   pNim   The NIM module pointer


@retval   FUNCTION_SUCCESS   Update tuner LNA_GAIN with RSSI successfully.
@retval   FUNCTION_ERROR     Update tuner LNA_GAIN with RSSI unsuccessfully.

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

	unsigned long RssiRCalOff;
	long RssiRDiff;
	unsigned char LnaGain;
	unsigned char ReadValue;

	// added from Fitipower, 2011-2-23, v0.8
	int boolVhfFlag;      // 0:false,  1:true
	int boolEnInChgFlag;  // 0:false,  1:true
	int intGainShift;



	// 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 demod RSSI_R when tuner RSSI calibration in off.
	// Note: Tuner EN_CAL_RSSI and LNA_POWER_DOWN are set to 0x0 after rtl2832_fc0013_GetTunerRssiCalOn() executing.
	if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RSSI_R, &RssiRCalOff) != FUNCTION_SUCCESS)
		goto error_status_get_registers;

	// To avoid the wrong rssi calibration value in the environment with strong RF pulse signal.
	if(RssiRCalOff < pNimExtra->RssiRCalOn)
		pNimExtra->RssiRCalOn = RssiRCalOff;


	// Calculate RSSI_R difference.
	RssiRDiff = RssiRCalOff - pNimExtra->RssiRCalOn;

	// Get tuner LNA_GAIN.
	if(fc0013_GetRegMaskBits(pTuner, 0x14, 4, 0, &LnaGain) != FC0013_I2C_SUCCESS)
		goto error_status_get_registers;


	// Determine next LNA_GAIN according to RSSI_R difference and current LNA_GAIN.
	switch(LnaGain)
	{
		default:

			boolVhfFlag = 0;		
			boolEnInChgFlag = 1;
			intGainShift = 10;
			LnaGain = FC0013_LNA_GAIN_HIGH_19;

			// Set tuner LNA_GAIN.
			if(fc0013_SetRegMaskBits(pTuner, 0x14, 4, 0, LnaGain) != FC0013_I2C_SUCCESS)
				goto error_status_set_registers;

			break;


		case FC0013_LNA_GAIN_HIGH_19:

			if(RssiRDiff >= 10)
			{
				boolVhfFlag = 1;		
				boolEnInChgFlag = 0;
				intGainShift = 10;
				LnaGain = FC0013_LNA_GAIN_HIGH_17;

				// Set tuner LNA_GAIN.
				if(fc0013_SetRegMaskBits(pTuner, 0x14, 4, 0, LnaGain) != FC0013_I2C_SUCCESS)
					goto error_status_set_registers;

				break;
			}
			else
			{
				goto success_status_Lna_Gain_No_Change;
			}


		case FC0013_LNA_GAIN_HIGH_17:
			
			if(RssiRDiff <= 2)
			{
				boolVhfFlag = 0;	
				boolEnInChgFlag = 1;
				intGainShift = 10;
				LnaGain = FC0013_LNA_GAIN_HIGH_19;

				// Set tuner LNA_GAIN.
				if(fc0013_SetRegMaskBits(pTuner, 0x14, 4, 0, LnaGain) != FC0013_I2C_SUCCESS)
					goto error_status_set_registers;

				break;
			}

			else if(RssiRDiff >= 24)
			{
				boolVhfFlag = 0;	
				boolEnInChgFlag = 0;
				intGainShift = 7;
				LnaGain = FC0013_LNA_GAIN_MIDDLE;

				// Set tuner LNA_GAIN.
				if(fc0013_SetRegMaskBits(pTuner, 0x14, 4, 0, LnaGain) != FC0013_I2C_SUCCESS)
					goto error_status_set_registers;

				break;
			}

			else
			{
				goto success_status_Lna_Gain_No_Change;
			}


		case FC0013_LNA_GAIN_MIDDLE:

			if(RssiRDiff >= 38)
			{
				boolVhfFlag = 0;	
				boolEnInChgFlag = 0;
				intGainShift = 7;
				LnaGain = FC0013_LNA_GAIN_LOW;

				// Set tuner LNA_GAIN.
				if(fc0013_SetRegMaskBits(pTuner, 0x14, 4, 0, LnaGain) != FC0013_I2C_SUCCESS)
					goto error_status_set_registers;

				break;
			}

			else if(RssiRDiff <= 5)
			{
				boolVhfFlag = 1;
				boolEnInChgFlag = 0;
				intGainShift = 10;
				LnaGain = FC0013_LNA_GAIN_HIGH_17;

				// Set tuner LNA_GAIN.
				if(fc0013_SetRegMaskBits(pTuner, 0x14, 4, 0, LnaGain) != FC0013_I2C_SUCCESS)
					goto error_status_set_registers;

				break;
			}

			else
			{
				goto success_status_Lna_Gain_No_Change;
			}

		
		case FC0013_LNA_GAIN_LOW:

			if(RssiRDiff <= 2)
			{
				boolVhfFlag = 0;
				boolEnInChgFlag = 0;
				intGainShift = 7;
				LnaGain = FC0013_LNA_GAIN_MIDDLE;

				// Set tuner LNA_GAIN.
				if(fc0013_SetRegMaskBits(pTuner, 0x14, 4, 0, LnaGain) != FC0013_I2C_SUCCESS)
					goto error_status_set_registers;

				break;
			}

			else
			{
				goto success_status_Lna_Gain_No_Change;
			}
	}


	if(fc0013_GetRegMaskBits(pTuner, 0x14, 7, 0, &ReadValue) != FC0013_I2C_SUCCESS)
		goto error_status_get_registers;

	if( (ReadValue & 0x60) == 0 )   // disable UHF & GPS ==> lock VHF frequency
	{
		boolVhfFlag = 1;
	}


	if( boolVhfFlag == 1 )
	{
		//FC0013_Write(0x07, (FC0013_Read(0x07) | 0x10));				// VHF = 1
		if(fc0013_GetRegMaskBits(pTuner, 0x07, 7, 0, &ReadValue) != FC0013_I2C_SUCCESS)
			goto error_status_get_registers;

		if(fc0013_SetRegMaskBits(pTuner, 0x07, 7, 0, ReadValue | 0x10) != FC0013_I2C_SUCCESS)
			goto error_status_set_registers;
	}
	else
	{
		//FC0013_Write(0x07, (FC0013_Read(0x07) & 0xEF));				// VHF = 0
		if(fc0013_GetRegMaskBits(pTuner, 0x07, 7, 0, &ReadValue) != FC0013_I2C_SUCCESS)
			goto error_status_get_registers;

		if(fc0013_SetRegMaskBits(pTuner, 0x07, 7, 0, ReadValue & 0xEF) != FC0013_I2C_SUCCESS)
			goto error_status_set_registers;
	}
		

	if( boolEnInChgFlag == 1 )
	{
		//FC0013_Write(0x0A, (FC0013_Read(0x0A) | 0x20));				// EN_IN_CHG = 1
		if(fc0013_GetRegMaskBits(pTuner, 0x0A, 7, 0, &ReadValue) != FC0013_I2C_SUCCESS)
			goto error_status_get_registers;

		if(fc0013_SetRegMaskBits(pTuner, 0x0A, 7, 0, ReadValue | 0x20) != FC0013_I2C_SUCCESS)
			goto error_status_set_registers;
	}
	else
	{
		//FC0013_Write(0x0A, (FC0013_Read(0x0A) & 0xDF));				// EN_IN_CHG = 0
		if(fc0013_GetRegMaskBits(pTuner, 0x0A, 7, 0, &ReadValue) != FC0013_I2C_SUCCESS)
			goto error_status_get_registers;

		if(fc0013_SetRegMaskBits(pTuner, 0x0A, 7, 0, ReadValue & 0xDF) != FC0013_I2C_SUCCESS)
			goto error_status_set_registers;
	}


	if( intGainShift == 10 )
	{
		//FC0013_Write(0x07, (FC0013_Read(0x07) & 0xF0) | 0x0A);		// GS = 10
		if(fc0013_GetRegMaskBits(pTuner, 0x07, 7, 0, &ReadValue) != FC0013_I2C_SUCCESS)
			goto error_status_get_registers;

		if(fc0013_SetRegMaskBits(pTuner, 0x07, 7, 0, (ReadValue & 0xF0) | 0x0A) != FC0013_I2C_SUCCESS)
			goto error_status_set_registers;
	}
	else
	{
		//FC0013_Write(0x07, (FC0013_Read(0x07) & 0xF0) | 0x07);		// GS = 7
		if(fc0013_GetRegMaskBits(pTuner, 0x07, 7, 0, &ReadValue) != FC0013_I2C_SUCCESS)
			goto error_status_get_registers;

		if(fc0013_SetRegMaskBits(pTuner, 0x07, 7, 0, (ReadValue & 0xF0) | 0x07) != FC0013_I2C_SUCCESS)
			goto error_status_set_registers;
	}


success_status_Lna_Gain_No_Change:
	return FUNCTION_SUCCESS;


error_status_get_registers:
error_status_set_registers:
	return FUNCTION_ERROR;
}