Пример #1
0
UData_t
tuner_set_bw_normal(
	handle_t tuner_handle,
	handle_t demod_handle
	)
{
	DVBT_DEMOD_MODULE *pDemod;

	int DemodBandwidthMode;
	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;

	// Determine tuner 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_execute_function:
	return MT_COMM_ERR;
}
Пример #2
0
UData_t demod_pdcontrol_reset(handle_t demod_handle, handle_t tuner_handle, uint8_t *agc_current_state) {

	DVBT_DEMOD_MODULE *pDemod;
	unsigned long BinaryValue;


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

	// Reset AGC current state.
	*agc_current_state = AGC_STATE_START;

	// Calculate RTL2832_MT2266_IF_AGC_MIN_INT_MIN binary value.
	BinaryValue = SignedIntToBin(RTL2832_MT2266_IF_AGC_MIN_INT_MIN, RTL2832_MT2266_IF_AGC_MIN_BIT_NUM);

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

	// Set tuner bandwidth with normal setting.
	if(MT_IS_ERROR(tuner_set_bw_normal(tuner_handle, demod_handle)))
		goto error_status_set_tuner_bandwidth;


	return MT_OK;


error_status_set_tuner_bandwidth:
error_status_set_registers:
	return MT_COMM_ERR;
}
Dword MT2260B0_set (
	IN  Demodulator*	demodulator,
	IN  Byte			chip,
    IN  Word			bandwidth,
    IN  Dword			frequency
) {
    Dword error = Error_NO_ERROR;
    UData_t status = MT_OK;
    UData_t freq;
    UData_t bw;

    freq = frequency * 1000UL;
    bw = (UData_t) bandwidth * 1000UL;

    /** Change frequency */
    status = MT2260_ChangeFreq (Microtune_MT2260B0_tunerHandles[chip], freq);
	if (MT_NO_ERROR (status))
		status |= MT2260_SetParam (Microtune_MT2260B0_tunerHandles[chip], MT2260_OUTPUT_BW, bw);
	if (MT_IS_ERROR (status))
		error = Error_MT_TUNE_FAIL;

	User_delay (demodulator, 100);

	return (error);
}
Dword MT2260B0_close (
	IN  Demodulator*	demodulator,
	IN  Byte			chip
) {
	Dword error = Error_NO_ERROR;
    UData_t status = MT_OK;

	status |= MT2260_Close (Microtune_MT2260B0_tunerHandles[chip]);
    if (MT_IS_ERROR (status)) 
		error = Error_MT_TUNE_FAIL;

    return (error);
}
Dword MT2260B0_open (
	IN  Demodulator*	demodulator,
	IN  Byte			chip
) {
	Dword error = Error_NO_ERROR;
    UData_t status = MT_OK;

	Microtune_MT2260B0_userDatas[chip].chip = chip;
	Microtune_MT2260B0_userDatas[chip].demodulator = demodulator;
    status = MT2260_Open ((unsigned int)Microtune_MT2260B0_EXT_ADDRESS, &Microtune_MT2260B0_tunerHandles[chip], &Microtune_MT2260B0_userDatas[chip]);
	if (MT_NO_ERROR (status))
		status |= MT2260_SetParam (Microtune_MT2260B0_tunerHandles[chip], MT2260_STEPSIZE, 62500);
	if (MT_NO_ERROR (status))
		status |= MT2260_SetParam (Microtune_MT2260B0_tunerHandles[chip], MT2260_RF_EXT, 1);
	if (MT_NO_ERROR (status))
		status |= MT2260_SetParam (Microtune_MT2260B0_tunerHandles[chip], MT2260_BB_EXT, 1);
    if (MT_IS_ERROR (status)) 
		error = Error_MT_TUNE_FAIL;

    return (error);
}
Пример #6
0
UData_t demod_pdcontrol(handle_t demod_handle, handle_t tuner_handle, uint8_t* lna_config, uint8_t* uhf_sens,
					 uint8_t *agc_current_state, uint32_t *lna_gain_old) {

	uint16_t pd_value;
	uint16_t rf_level, bb_level;
	uint32_t lna_gain;
	uint8_t zin=0;
	
//	uint8_t temp[2];
//	uint8_t agc_bb_min;
//	demod_data_t* local_data;

	
	uint8_t band=1;  /* band=0: vhf, band=1: uhf low, band=2: uhf high */
	uint32_t freq;

	// AGC threshold values
	uint16_t sens_on[]  = {11479, 11479, 32763};
	uint16_t sens_off[] = {36867, 36867, 44767};
	uint16_t lin_off[]  = {23619, 23619, 23619};
	uint16_t lin_on[]   = {38355, 38355, 38355};
	uint16_t pd_upper[] = {85,    85,    85};
	uint16_t pd_lower[] = {74,    74,    74};
	uint8_t next_state;

	// demod_data_t* local_data = (demod_data_t*)demod_handle;	

	if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_INPUT_FREQ, &freq))) goto error_status;
	if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_LNA_GAIN, &lna_gain))) goto error_status;
	if(MT_IS_ERROR(MT2266_GetReg(tuner_handle,0x1e,&zin))) goto error_status;

	if (freq <= 250000000) band=0;
	else if (freq < 660000000) band=1;
	else band=2;
	
	if(MT_IS_ERROR(demod_get_pd(demod_handle, &pd_value))) goto error_status;
	if(MT_IS_ERROR(demod_get_agc(demod_handle, &rf_level, &bb_level))) goto error_status;

	rf_level=0xffff-rf_level;
	bb_level=0xffff-bb_level;

/*
#ifndef _HOST_DLL
	uart_write_nr("St:");
	uart_writedez(agc_current_state[num]);

	uart_write_nr(" PD: ");
	uart_writehex16(pd_value);

	uart_write_nr(" AGC: ");
	uart_writehex16(rf_level);
	uart_writehex16(bb_level);	
#endif
*/

	next_state = *agc_current_state;
	
	switch (*agc_current_state) {
	
	case AGC_STATE_START : {
		if ((int)lna_gain < LNAGAIN_MIN)  
			next_state=AGC_STATE_LNAGAIN_BELOW_MIN;
		else if (lna_gain > LNAGAIN_MAX)  
			next_state=AGC_STATE_LNAGAIN_ABOVE_MAX;
		else 
			next_state=AGC_STATE_NORMAL;
		break;
		}
	
	case AGC_STATE_LNAGAIN_BELOW_MIN : {
		if ((int)lna_gain < LNAGAIN_MIN ) 
			next_state=AGC_STATE_LNAGAIN_BELOW_MIN;
		else next_state=AGC_STATE_NORMAL;
		
		break;
		}
	
	case AGC_STATE_LNAGAIN_ABOVE_MAX : {
		if (lna_gain > LNAGAIN_MAX ) 
			next_state=AGC_STATE_LNAGAIN_ABOVE_MAX;
		else next_state=AGC_STATE_NORMAL;
		break;
		}
	
	case AGC_STATE_NORMAL : {
		if (rf_level > lin_on[band] ) {
			*lna_gain_old = lna_gain;
			next_state = AGC_STATE_MAS_GRANDE_SIGNAL;
			}
		else if (pd_value > pd_upper[band]) {
			next_state = AGC_STATE_GRANDE_INTERFERER;
			}
		else if ( (pd_value < pd_lower[band]) && (lna_gain < LNAGAIN_MAX) ) {
			next_state = AGC_STATE_NO_INTERFERER;
			}
		else if ( bb_level < sens_on[band]) {
			next_state = AGC_STATE_SMALL_SIGNAL;
			}
		break;
		}
	
	case AGC_STATE_NO_INTERFERER : {
		if (pd_value > pd_lower[band] ) 
			next_state = AGC_STATE_MEDIUM_INTERFERER;
		else if (pd_value < pd_lower[band] )
			next_state = AGC_STATE_NORMAL;
		else if ( lna_gain == LNAGAIN_MAX )
			next_state = AGC_STATE_NORMAL;
		break;
		}

	case AGC_STATE_MEDIUM_INTERFERER : {
		if (pd_value > pd_upper[band] ) 
			next_state = AGC_STATE_GRANDE_INTERFERER;
		else if (pd_value < pd_lower[band] )
			next_state = AGC_STATE_NO_INTERFERER;
		break;
		}

	
	case AGC_STATE_GRANDE_INTERFERER : {
		if (pd_value < pd_upper[band] )
			next_state = AGC_STATE_MEDIUM_INTERFERER;
		break;
		}
	
	case AGC_STATE_MAS_GRANDE_SIGNAL : {
		if (rf_level < lin_on[band])
			next_state = AGC_STATE_GRANDE_SIGNAL;
		else if (pd_value > pd_upper[band]) {
			next_state = AGC_STATE_GRANDE_INTERFERER;
			}
		break;
		}
		
	case AGC_STATE_MEDIUM_SIGNAL : {
		if (rf_level > lin_off[band])
			next_state = AGC_STATE_GRANDE_SIGNAL;
		else if (lna_gain >= *lna_gain_old) 
			next_state = AGC_STATE_NORMAL;
		else if (pd_value > pd_upper[band])
			next_state = AGC_STATE_GRANDE_INTERFERER;
		break;
		}
	
	case AGC_STATE_GRANDE_SIGNAL : {
		if (rf_level > lin_on[band])
			next_state = AGC_STATE_MAS_GRANDE_SIGNAL;
		else if (rf_level < lin_off[band]) 
			next_state = AGC_STATE_MEDIUM_SIGNAL;
		else if (pd_value > pd_upper[band])
			next_state = AGC_STATE_GRANDE_INTERFERER;
		break;
		}
	
	case AGC_STATE_SMALL_SIGNAL : {
		if (pd_value > pd_upper[band] ) 
			next_state = AGC_STATE_GRANDE_INTERFERER;
		else if (bb_level > sens_off[band]) 
			next_state = AGC_STATE_NORMAL;
		else if ( (bb_level < sens_on[band]) && (lna_gain == LNAGAIN_MAX) )
			next_state = AGC_STATE_MAX_SENSITIVITY;
		break;
		}
		
	case AGC_STATE_MAX_SENSITIVITY : {
		if (bb_level > sens_off[band]) 
			next_state = AGC_STATE_SMALL_SIGNAL;
		break;
		}
		
	}
			
	*agc_current_state = next_state;	
	
	
	switch (*agc_current_state) {
		
		case AGC_STATE_LNAGAIN_BELOW_MIN : {
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_INCR, LNAGAIN_MAX))) goto error_status;
			break;
			}
		
		case AGC_STATE_LNAGAIN_ABOVE_MAX : {
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_DECR, LNAGAIN_MIN))) goto error_status;
			break;
			}
			
		case AGC_STATE_NORMAL : {
			if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status;
			if (zin >= 2) {
				zin -= 2;
				if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status;
			}
			break;
			}
		
		case AGC_STATE_NO_INTERFERER : {
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_INCR, LNAGAIN_MAX))) goto error_status;
			if (zin >= 2) {
				zin -= 2;
				if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status;
			}

			if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status;
			break;
			}

		case AGC_STATE_MEDIUM_INTERFERER : {
			if (zin >= 2) {
				zin -= 2;
				if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status;
			}

			// Additional setting
			// Set tuner with normal bandwidth.
			if(MT_IS_ERROR(tuner_set_bw_normal(tuner_handle, demod_handle))) goto error_status;

			break;
			}
		
		case AGC_STATE_GRANDE_INTERFERER : {
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_DECR, LNAGAIN_MIN))) goto error_status;
			if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,1))) goto error_status;

			// Additional setting
			// Set tuner with narrow bandwidth.
			if(MT_IS_ERROR(tuner_set_bw_narrow(tuner_handle, demod_handle))) goto error_status;

			break;
			}
		
		case AGC_STATE_MEDIUM_SIGNAL : {
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_INCR, LNAGAIN_MAX))) goto error_status;
			if (zin >= 2) {
				zin -= 2;
				if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status;
			}
			if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status;
			break;
			}
			
		case AGC_STATE_GRANDE_SIGNAL : {
			if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status;
			break;
			}

		case AGC_STATE_MAS_GRANDE_SIGNAL : {
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_DECR, LNAGAIN_MIN))) goto error_status;
			if (lna_gain==0) {
				if (zin <= 64) {
					zin += 2;
					if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status;
					}
				}
			if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status;
			break;
			}
		
		case AGC_STATE_SMALL_SIGNAL : {
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_INCR, LNAGAIN_MAX))) goto error_status;
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_UHF_NORMAL,1))) goto error_status;
			if (zin >= 2) {
				zin -= 2;
				if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status;
			}

			if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status;
			*uhf_sens=0;
			break;
			}
		
		case AGC_STATE_MAX_SENSITIVITY : {
			if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_UHF_MAXSENS,1))) goto error_status;
			if (zin >= 2) {
				zin -= 2;
				if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status;
			}
			if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status;
			*uhf_sens=1;
			break;
			}
	}	

	if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_LNA_GAIN,&lna_gain))) goto error_status;

	*lna_config=(uint8_t)lna_gain;

/*
#ifndef _HOST_DLL
	uart_write_nr(" LNA ");	
	uart_writedez(lna_gain);
	uart_write_nr(" SENS ");
	uart_writedez(*uhf_sens);
	uart_write_nr(" Z ");
	uart_writedez(zin);
	uart_write(" ");
#endif
*/



	return MT_OK;


error_status:
	return MT_COMM_ERR;
}
Пример #7
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;
}
Пример #8
0
/**

@see   DVBT_NIM_FP_UPDATE_FUNCTION

*/
int
rtl2832_mt2266_UpdateFunction(
	DVBT_NIM_MODULE *pNim
	)
{
	TUNER_MODULE *pTuner;
	DVBT_DEMOD_MODULE *pDemod;
	MT2266_EXTRA_MODULE *pMt2266Extra;
	RTL2832_MT2266_EXTRA_MODULE *pRtl2832Mt2266Extra;

	Handle_t Mt2266Handle;
	UData_t Status;



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

	// Get tuner extra module and tuner handle.
	pMt2266Extra = (MT2266_EXTRA_MODULE *)pTuner->pExtra;
	pMt2266Extra->GetHandle(pTuner, &Mt2266Handle);

	// Get NIM extra module.
	pRtl2832Mt2266Extra = (RTL2832_MT2266_EXTRA_MODULE *)pNim->pExtra;


	// Update demod particular registers.
	if(pDemod->UpdateFunction(pDemod) != FUNCTION_SUCCESS)
		goto error_status_execute_function;


	// Enable demod DVBT_IIC_REPEAT.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS)
		goto error_status_set_registers;

	// Update demod and tuner register setting.
	Status = demod_pdcontrol(
		pDemod,
		Mt2266Handle,
		&pRtl2832Mt2266Extra->LnaConfig,
		&pRtl2832Mt2266Extra->UhfSens,
		&pRtl2832Mt2266Extra->AgcCurrentState,
		(uint32_t *)&pRtl2832Mt2266Extra->LnaGainOld
		);

	if(MT_IS_ERROR(Status))
		goto error_status_execute_function;

	// Disable demod DVBT_IIC_REPEAT.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS)
		goto error_status_set_registers;


	return FUNCTION_SUCCESS;


error_status_execute_function:
error_status_set_registers:
	return FUNCTION_ERROR;
}
Пример #9
0
/**

@see   DVBT_NIM_FP_SET_PARAMETERS

*/
int
rtl2832_mt2266_SetParameters(
	DVBT_NIM_MODULE *pNim,
	unsigned long RfFreqHz,
	int BandwidthMode
	)
{
	TUNER_MODULE *pTuner;
	DVBT_DEMOD_MODULE *pDemod;

	MT2266_EXTRA_MODULE *pMt2266Extra;
	Handle_t Mt2266Handle;
	unsigned long BandwidthHz;

	RTL2832_MT2266_EXTRA_MODULE *pRtl2832Mt2266Extra;

	UData_t Status;



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

	// Get tuner extra module.
	pMt2266Extra = (MT2266_EXTRA_MODULE *)pTuner->pExtra;

	// Get tuner handle.
	Mt2266Handle = pMt2266Extra->DeviceHandle;

	// Get NIM extra module.
	pRtl2832Mt2266Extra = (RTL2832_MT2266_EXTRA_MODULE *)pNim->pExtra;


	// Enable demod DVBT_IIC_REPEAT.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS)
		goto error_status_set_registers;

	// Set tuner RF frequency in Hz.
	if(pTuner->SetRfFreqHz(pTuner, RfFreqHz) != FUNCTION_SUCCESS)
		goto error_status_execute_function;

	// Determine BandwidthHz according to bandwidth mode.
	switch(BandwidthMode)
	{
		default:
		case DVBT_BANDWIDTH_6MHZ:		BandwidthHz = MT2266_BANDWIDTH_6MHZ;		break;
		case DVBT_BANDWIDTH_7MHZ:		BandwidthHz = MT2266_BANDWIDTH_7MHZ;		break;
		case DVBT_BANDWIDTH_8MHZ:		BandwidthHz = MT2266_BANDWIDTH_8MHZ;		break;
	}

	// Set tuner bandwidth in Hz with BandwidthHz.
	if(pMt2266Extra->SetBandwidthHz(pTuner, BandwidthHz) != FUNCTION_SUCCESS)
		goto error_status_execute_function;

	// Disable demod DVBT_IIC_REPEAT.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS)
		goto error_status_set_registers;


	// Set demod bandwidth mode.
	if(pDemod->SetBandwidthMode(pDemod, BandwidthMode) != FUNCTION_SUCCESS)
		goto error_status_execute_function;

	// Reset demod particular registers.
	if(pDemod->ResetFunction(pDemod) != FUNCTION_SUCCESS)
		goto error_status_execute_function;


	// Reset demod by software reset.
	if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS)
		goto error_status_execute_function;

	// Enable demod DVBT_IIC_REPEAT.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS)
		goto error_status_set_registers;

	// Reset MT2266 update procedure.
	Status = demod_pdcontrol_reset(pDemod, Mt2266Handle, &pRtl2832Mt2266Extra->AgcCurrentState);

	if(MT_IS_ERROR(Status))
		goto error_status_execute_function;

	// Disable demod DVBT_IIC_REPEAT.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS)
		goto error_status_set_registers;


	return FUNCTION_SUCCESS;


error_status_execute_function:
error_status_set_registers:
	return FUNCTION_ERROR;
}
/**

@see   DVBT_NIM_FP_UPDATE_FUNCTION

*/
int
rtl2832_mt2266_UpdateFunction(
	DVBT_NIM_MODULE *pNim
	)
{
	TUNER_MODULE *pTuner;
	DVBT_DEMOD_MODULE *pDemod;
	MT2266_EXTRA_MODULE *pTunerExtra;
	RTL2832_MT2266_EXTRA_MODULE *pNimExtra;

	Handle_t Mt2266Handle;
	UData_t Status;
	


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

	// Get tuner extra module and tuner handle.
	pTunerExtra = &(pTuner->Extra.Mt2266);
	pTunerExtra->GetHandle(pTuner, &Mt2266Handle);

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


	// Update demod particular registers.
	if(pDemod->UpdateFunction(pDemod) != FUNCTION_SUCCESS)
		goto error_status_execute_function;


	// Enable demod DVBT_IIC_REPEAT.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS)
		goto error_status_set_registers;

	// Update demod and tuner register setting.
	Status = demod_pdcontrol(
		pDemod,
		Mt2266Handle,
		&pNimExtra->LnaConfig,
		&pNimExtra->UhfSens,
		&pNimExtra->AgcCurrentState,
		&pNimExtra->LnaGainOld
		);

/*
	handle_t demod_handle,
	handle_t tuner_handle,
	unsigned char* lna_config,
	unsigned char* uhf_sens,
	unsigned char *agc_current_state,
	unsigned long *lna_gain_old
	
	unsigned char LnaConfig;
	unsigned char UhfSens;
	unsigned char AgcCurrentState;
	unsigned long LnaGainOld;	
	
*/

	if(MT_IS_ERROR(Status))
		goto error_status_execute_function;

	// Disable demod DVBT_IIC_REPEAT.
	if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS)
		goto error_status_set_registers;


	return FUNCTION_SUCCESS;


error_status_execute_function:
error_status_set_registers:
	return FUNCTION_ERROR;
}