Esempio n. 1
0
/***************************************************************************//**
 * @brief Writes parameters to the AD9122.
 *
 * @return Returns negative error code or 0 in case of success.
*******************************************************************************/
 int32_t ad9122_write_raw(uint32_t channel,
						  int32_t val,
						  int32_t val2,
						  int32_t mask)
{
	struct cf_axi_converter *conv = &dds_conv;
	uint32_t rate;
	int32_t ret;
	uint32_t ctrl_reg_1;
	uint32_t ctrl_reg_2;

	DAC_Core_Read(ADI_REG_CNTRL_1, &ctrl_reg_1);
	DAC_Core_Read(ADI_REG_CNTRL_2, &ctrl_reg_2);
	switch (mask) {
	case IIO_CHAN_INFO_SAMP_FREQ:
		rate = ad9122_get_data_clk(conv);
		ret = ad9122_set_data_clk(conv, val);
		if (ret < 0) {
			return ret;
		}

		if (val != rate) {
			ret = ad9122_tune_dci(conv);
		}
		break;
	default:
		return -1;
	}
	DAC_Core_Write(ADI_REG_CNTRL_1, ctrl_reg_1);
	DAC_Core_Write(ADI_REG_CNTRL_2, ctrl_reg_2);

	return ret;
}
Esempio n. 2
0
/***************************************************************************//**
 * @brief Writes parameters to the AD9122.
 *
 * @return Returns negative error code or 0 in case of success.
*******************************************************************************/
 int32_t ad9122_write_raw(uint32_t channel,
						  int32_t val,
						  int32_t val2,
						  int32_t mask)
{
	struct cf_axi_converter *conv = &dds_conv;
	uint32_t rate;
	int32_t ret;

	switch (mask) {
	case IIO_CHAN_INFO_SAMP_FREQ:
		rate = ad9122_get_data_clk(conv);
		ret = ad9122_set_data_clk(conv, val);
		if (ret < 0) {
			return ret;
		}

		if (val != rate) {
			ad9122_tune_dci(conv);
		}
		break;
	default:
		return -1;
	}

	return 0;
}
Esempio n. 3
0
/***************************************************************************//**
 * @brief Sets the interpolation frequency.
 *
 * @param conv - Pointer to a cf_axi_converter struct.
 * @param freq - Interpolation frequency in Hz
 *
 * @return Returns negative error code or 0 in case of success.
*******************************************************************************/
static int32_t ad9122_set_interpol_freq(struct cf_axi_converter *conv,
										uint32_t freq)
{
	uint32_t dat_freq;
	int32_t ret;

	dat_freq = ad9122_get_data_clk(conv);
	ret = ad9122_set_interpol(conv, freq / dat_freq,
							  conv->fcenter_shift, 0);
	ad9122_update_avail_fcent_modes(conv, dat_freq);

	return ret;
}
Esempio n. 4
0
/***************************************************************************//**
 * @brief Reads parameters from the AD9122.
 *
 * @return Returns negative error code or 0 in case of success.
*******************************************************************************/
int32_t ad9122_read_raw(uint32_t channel,
		    	   	   	int32_t *val,
			   	   	   	int32_t *val2,
			   	   	   	int32_t m)
{
	struct cf_axi_converter *conv = &dds_conv;

	switch (m) {
	case IIO_CHAN_INFO_SAMP_FREQ:

		*val = ad9122_get_data_clk(conv);
		return 0;

	}
	return -1;
}
Esempio n. 5
0
/***************************************************************************//**
 * @brief Sets the AD9122 data rate.
 *
 * @param rate - Desired data rate in Hz
 *
 * @return Returns the set data rate.
*******************************************************************************/
int32_t ad9122_set_data_rate(uint32_t rate)
{
	struct cf_axi_converter* conv = &dds_conv;
	int32_t ret = 0;

#ifdef CF_AXI_DDS
	ret = cf_axi_dds_write_raw(0, 0,
							  (int32_t)rate, 0,
							  IIO_CHAN_INFO_SAMP_FREQ);
#else
	ret = ad9122_write_raw(0,
						   (int32_t)rate, 0,
					   	   IIO_CHAN_INFO_SAMP_FREQ);
#endif

	if(ret < 0)
		return ret;

	return ad9122_get_data_clk(conv);
}
Esempio n. 6
0
/***************************************************************************//**
 * @brief Returns the center frequency shift.
 *
 * @param conv - Pointer to a cf_axi_converter struct.
 *
 * @return Returns negative error code or the center frequency shift.
*******************************************************************************/
static uint32_t ad9122_get_interpol_fcent_freq(struct cf_axi_converter *conv)
{
	return (ad9122_get_data_clk(conv) * conv->fcenter_shift) / 2;
}
Esempio n. 7
0
/***************************************************************************//**
 * @brief Returns the interpolation frequency.
 *
 * @param conv - Pointer to a cf_axi_converter struct.
 *
 * @return Returns negative error code or the interpolation frequency.
*******************************************************************************/
static uint32_t ad9122_get_interpol_freq(struct cf_axi_converter *conv)
{
	return ad9122_get_data_clk(conv) * conv->interp_factor;
}
Esempio n. 8
0
/***************************************************************************//**
 * @brief Sets the interpolation center frequency shift.
 *
 * @param conv - Pointer to a cf_axi_converter struct.
 * @param freq - Center frequency shift in Hz
 *
 * @return Returns negative error code or 0 in case of success.
*******************************************************************************/
static int32_t ad9122_set_interpol_fcent_freq(struct cf_axi_converter *conv,
											  uint32_t freq)
{
	return ad9122_set_interpol(conv, conv->interp_factor,
							  (freq * 2) / ad9122_get_data_clk(conv), 0);
}
Esempio n. 9
0
/***************************************************************************//**
 * @brief Sets the interpolation factor and the center shift frequency.
 *
 * @param conv - Pointer to a cf_axi_converter struct.
 * @param interp - Interpolation factor
 * @param fcent_shift - Center frequency shift as a multiplier of fData / 2. 
*               		The shift values should be in the range [0, 15]
 * @param data_rate - Data rate in Hz
 *
 * @return Returns negative error code or 0 in case of success.
*******************************************************************************/
static int32_t ad9122_set_interpol(struct cf_axi_converter *conv,
								   uint32_t interp,
								   uint32_t fcent_shift,
								   uint32_t data_rate)
{
	uint32_t hb1, hb2, hb3, tmp;
	int32_t ret, cached;

	hb1 = AD9122_HB1_CTRL_BYPASS_HB1;
	hb2 = AD9122_HB2_CTRL_BYPASS_HB2;
	hb3 = AD9122_HB3_CTRL_BYPASS_HB3;

	switch (interp) {
		case 1:
			break;
		case 2:
			if (fcent_shift > 3)
				return -1;
			hb1 = AD9122_HB1_INTERP(fcent_shift);
			break;
		case 4:
			if (fcent_shift > 7)
				return -1;
			hb1 = AD9122_HB1_INTERP(fcent_shift % 4);
			hb2 = AD9122_HB23_INTERP(fcent_shift);
			break;
		case 8:
			if (fcent_shift > 15)
				return -1;
			hb1 = AD9122_HB1_INTERP(fcent_shift % 4);
			hb2 = AD9122_HB23_INTERP(fcent_shift % 8);
			hb3 = AD9122_HB23_INTERP(fcent_shift / 2);
			break;
		default:
			return -1;
	}

	cached = conv->interp_factor;
	conv->interp_factor = interp;
	ret = ad9122_set_data_clk(conv, data_rate ?
				 data_rate : ad9122_get_data_clk(conv));

	if (ret < 0) {
		conv->interp_factor = cached;

		return ret;
	}

	tmp = ad9122_read(AD9122_REG_DATAPATH_CTRL);
	switch (hb1) {
		case AD9122_HB1_INTERP(1):
		case AD9122_HB1_INTERP(3):
			tmp &= ~AD9122_DATAPATH_CTRL_BYPASS_PREMOD;
			break;
		default:
			tmp |= AD9122_DATAPATH_CTRL_BYPASS_PREMOD;
	}

	ad9122_write(AD9122_REG_DATAPATH_CTRL, tmp);
	ad9122_write(AD9122_REG_HB1_CTRL, hb1);
	ad9122_write(AD9122_REG_HB2_CTRL, hb2);
	ad9122_write(AD9122_REG_HB3_CTRL, hb3);
	conv->fcenter_shift = fcent_shift;

	return 0;
}
Esempio n. 10
0
/***************************************************************************//**
 * @brief Sets the interpolation frequency.
 *
 * @param conv - Pointer to a cf_axi_dds_converter struct.
 * @param freq - Interpolation frequency in Hz
 *
 * @return Returns negative error code or 0 in case of success.
*******************************************************************************/
static int32_t ad9122_set_interpol_freq(struct cf_axi_dds_converter *conv,
										uint32_t freq)
{
	return ad9122_set_interpol(conv, freq / ad9122_get_data_clk(conv),
							   conv->fcenter_shift, 0);
}