/*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008,2009 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <memory_map.h>
#include <db_base.h>
#include <hal_io.h>
-#include <ad9510.h>
#include <stdio.h>
#include <mdelay.h>
#include <lsdac.h>
unsigned char CP1;
unsigned char CP2;
int freq_mult;
- int spi_mask;
+ int spi_mask;
};
struct db_rfx_dummy {
.base.is_tx = false,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(400e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(500e6),
+ .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
+ .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(45),
+ .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.022),
.base.is_quadrature = true,
- .base.i_and_q_swapped = false,
+ .base.i_and_q_swapped = true,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
.base.init = rfx_init_rx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_rx,
.base.atr_rxval = POWER_UP|MIX_EN,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 0,
.common.CP1 = 7,
.common.CP2 = 7,
.base.is_tx = true,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(400e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(500e6),
//.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
.base.is_quadrature = true,
.base.i_and_q_swapped = false,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
.base.init = rfx_init_tx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_tx,
.base.atr_rxval = POWER_UP|ANT_SW,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 1,
.common.CP1 = 7,
.common.CP2 = 7,
.base.is_tx = false,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(750e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1050e6),
+ .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
+ .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
+ .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
.base.is_quadrature = true,
- .base.i_and_q_swapped = false,
+ .base.i_and_q_swapped = true,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
.base.init = rfx_init_rx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_rx,
.base.atr_rxval = MIX_EN,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 1,
.common.CP1 = 7,
.common.CP2 = 7,
.base.is_tx = true,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(750e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1050e6),
//.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
.base.is_quadrature = true,
.base.i_and_q_swapped = false,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
.base.init = rfx_init_tx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_tx,
.base.atr_rxval = ANT_SW,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 1,
.common.CP1 = 7,
.common.CP2 = 7,
.base.is_tx = false,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1150e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1450e6),
+ .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
+ .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
+ .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
.base.is_quadrature = true,
- .base.i_and_q_swapped = false,
+ .base.i_and_q_swapped = true,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
.base.init = rfx_init_rx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_rx,
.base.atr_rxval = MIX_EN,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 1,
.common.CP1 = 7,
.common.CP2 = 7,
.base.is_tx = true,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1150e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1450e6),
//.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
.base.is_quadrature = true,
.base.i_and_q_swapped = false,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
.base.init = rfx_init_tx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_tx,
.base.atr_rxval = ANT_SW,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 1,
.common.CP1 = 7,
.common.CP2 = 7,
.base.is_tx = false,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1500e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2100e6),
+ .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
+ .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
+ .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
.base.is_quadrature = true,
- .base.i_and_q_swapped = false,
+ .base.i_and_q_swapped = true,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
.base.init = rfx_init_rx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_rx,
.base.atr_rxval = MIX_EN,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 0,
.common.CP1 = 7,
.common.CP2 = 7,
.base.is_tx = true,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1500e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2100e6),
//.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
.base.is_quadrature = true,
.base.i_and_q_swapped = false,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
.base.init = rfx_init_tx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_tx,
.base.atr_rxval = ANT_SW,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 0,
.common.CP1 = 7,
.common.CP2 = 7,
.common.spi_mask = SPI_SS_TX_DB,
- .common.freq_mult = 1
+ .common.freq_mult = 1
};
.base.is_tx = false,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
- //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(2300e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2900e6),
+ .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
+ .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
+ .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
.base.is_quadrature = true,
- .base.i_and_q_swapped = false,
+ .base.i_and_q_swapped = true,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
.base.init = rfx_init_rx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_rx,
.base.atr_rxval = MIX_EN,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 0,
.common.CP1 = 7,
.common.CP2 = 7,
.base.is_tx = true,
.base.output_enables = 0x00E0,
.base.used_pins = 0x00FF,
- //.base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(xxx),
- //.base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(xxx),
+ .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(2300e6),
+ .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2900e6),
//.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
//.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
.base.is_quadrature = true,
.base.i_and_q_swapped = false,
.base.spectrum_inverted = false,
- //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+ .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
.base.init = rfx_init_tx,
.base.set_freq = rfx_set_freq,
.base.set_gain = rfx_set_gain_tx,
.base.atr_rxval = ANT_SW,
// .base.atr_tx_delay =
// .base.atr_rx_delay =
+ .base.set_antenna = 0,
.common.DIV2 = 0,
.common.CP1 = 7,
.common.CP2 = 7,
{
//struct db_rfx_dummy *db = (struct db_rfx_dummy *) dbb;
clocks_enable_tx_dboard(true, 0);
+
+ // Set the freq now to get the one time 10ms delay out of the way.
+ u2_fxpt_freq_t dc;
+ dbb->set_freq(dbb, dbb->freq_min, &dc);
return true;
}
// test gain
dbb->set_gain(dbb,U2_DOUBLE_TO_FXPT_GAIN(45.0));
- printf("set the gain\n");
+
+ // Set the freq now to get the one time 10ms delay out of the way.
+ u2_fxpt_freq_t dc;
+ dbb->set_freq(dbb, dbb->freq_min, &dc);
+
return true;
}
bool
rfx_set_freq(struct db_base *dbb, u2_fxpt_freq_t freq, u2_fxpt_freq_t *dc)
{
+ static unsigned char first = true;
+
*dc = 0;
struct db_rfx_dummy *db = (struct db_rfx_dummy *) dbb;
- //u2_fxpt_freq_t desired_n = db->common.freq_mult*freq/phdet_freq;
- //int N_DIV = u2_fxpt_freq_round_to_int(desired_n);
- u2_fxpt_freq_t desired_n = ((1LL<<20) * db->common.freq_mult*freq)/phdet_freq;
+ u2_fxpt_freq_t desired_n = (U2_DOUBLE_TO_FXPT_FREQ(1.0)*db->common.freq_mult*freq)/phdet_freq;
int N_DIV = u2_fxpt_freq_round_to_int(desired_n);
int B = N_DIV/PRESCALER;
int A = N_DIV - PRESCALER*B;
spi_transact(SPI_TXONLY,db->common.spi_mask,R,24,SPIF_PUSH_FALL);
spi_transact(SPI_TXONLY,db->common.spi_mask,C,24,SPIF_PUSH_FALL);
- mdelay(10);
+ if (first){
+ first = false;
+ mdelay(10);
+ }
spi_transact(SPI_TXONLY,db->common.spi_mask,N,24,SPIF_PUSH_FALL);
- printf("A = %d, B = %d, N_DIV = %d\n",A, B, N_DIV);
+ //printf("A = %d, B = %d, N_DIV = %d\n",A, B, N_DIV);
*dc = (N_DIV * phdet_freq) / db->common.freq_mult;
return true;
}
{
struct db_rfx_dummy *db = (struct db_rfx_dummy *) dbb;
- u2_fxpt_gain_t MAXGAIN = U2_DOUBLE_TO_FXPT_GAIN(70.0);
-
int offset_q8 = (int)(1.2/3.3*4096*(1<<15));
- int slope_q8 = (int)(-1.0/45.0*4096/3.3*256);
+ int range_q15 = (int)(-1.0*4096/3.3*256*128);
+ int slope_q8 = range_q15/db->base.gain_max;
+
int dacword = ((slope_q8 * gain) + offset_q8)>>15;
- printf("DACWORD %d\n",dacword);
+ //printf("DACWORD %d\n",dacword);
lsdac_write_rx(1,dacword);
return true;
- /*
- def set_gain(self, gain):
- """
- Set the gain.
-
- @param gain: gain in decibels
- @returns True/False
- """
- maxgain = self.gain_range()[1] - self._u.pga_max()
- mingain = self.gain_range()[0]
- if gain > maxgain:
- pga_gain = gain-maxgain
- assert pga_gain <= self._u.pga_max()
- agc_gain = maxgain
- else:
- pga_gain = 0
- agc_gain = gain
- V_maxgain = .2
- V_mingain = 1.2
- V_fullscale = 3.3
- dac_value = (agc_gain*(V_maxgain-V_mingain)/(maxgain-mingain) + V_mingain)*4096/V_fullscale
- assert dac_value>=0 and dac_value<4096
- return self._u.write_aux_dac(self._which, 0, int(dac_value)) and \
- self._set_pga(int(pga_gain))
-
- def gain_range(self):
- return (self._u.pga_min(), self._u.pga_max() + 70, 0.05) -- For 900-2400
- return (self._u.pga_min(), self._u.pga_max() + 45, 0.035) -- For 400
- */
}