[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9955 - gnuradio/branches/developers/eb/cppdb-wip/usrp
From: |
eb |
Subject: |
[Commit-gnuradio] r9955 - gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy |
Date: |
Fri, 7 Nov 2008 19:39:57 -0700 (MST) |
Author: eb
Date: 2008-11-07 19:39:56 -0700 (Fri, 07 Nov 2008)
New Revision: 9955
Modified:
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/db_base.cc
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/db_base.h
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_standard.cc
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_standard.h
Log:
Work-in-progress adding high-level "tune" method to usrp_standard.
Modified:
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/db_base.cc
===================================================================
--- gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/db_base.cc
2008-11-07 21:51:36 UTC (rev 9954)
+++ gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/db_base.cc
2008-11-08 02:39:56 UTC (rev 9955)
@@ -225,82 +225,3 @@
os << x.side_and_name();
return os;
}
-
-
-
-
-#if 0 // FIXME tune shouldn't be a method of db_base
-tune_result
-db_base::tune(int chan, double target_freq)
-{
- /*
- Set the center frequency we're interested in.
-
- @param u: instance of usrp.source_* or usrp.sink_*
- @param chan: DDC/DUC channel
- @type chan: int
- @param subdev: daughterboard subdevice
- @param target_freq: frequency in Hz
- @returns False if failure else tune_result
-
- Tuning is a two step process. First we ask the front-end to
- tune as close to the desired frequency as it can. Then we use
- the result of that operation and our target_frequency to
- determine the value for the digital down converter.
- */
-
- // Set the daughterboard frequency
- bool ok=true;
- double baseband_freq;
- struct freq_result_t freq = set_freq(target_freq);
- ok = freq.ok;
- baseband_freq = freq.baseband_freq;
-
- struct dxc_freq_t dxc_freq = calc_dxc_freq(target_freq, baseband_freq,
- usrp()->converter_rate());
-
- // If the spectrum is inverted, and the daughterboard doesn't do
- // quadrature downconversion, we can fix the inversion by flipping the
- // sign of the dxc_freq... (This only happens using the basic_rx board)
-
- if(spectrum_inverted()) {
- dxc_freq.inverted = !(dxc_freq.inverted);
- }
-
- if(dxc_freq.inverted && (!is_quadrature())) {
- dxc_freq.ddc_freq = -dxc_freq.ddc_freq;
- dxc_freq.inverted = !(dxc_freq.inverted);
- }
-
- if (!d_tx) {
- ok = ok && ((usrp_standard_rx*)usrp())->set_rx_freq(chan,
- dxc_freq.ddc_freq);
- }
- else {
- dxc_freq.ddc_freq = -dxc_freq.ddc_freq;
- ok = ok && ((usrp_standard_tx*)usrp())->set_tx_freq(chan,
- dxc_freq.ddc_freq);
- }
-
- if(!ok) {
- return tune_result(0, 0, 0, 0);
- }
-
- // residual_freq is the offset left over because of dxc tuning step size
- double residual_freq;
- if(!d_tx) {
- residual_freq = dxc_freq.ddc_freq -
((usrp_standard_rx*)usrp())->rx_freq(chan);
- }
- else {
- // FIXME 50-50 chance this has the wrong sign...
- residual_freq = dxc_freq.ddc_freq -
((usrp_standard_tx*)usrp())->tx_freq(chan);
- }
-
- tune_result res = tune_result(baseband_freq, dxc_freq.ddc_freq,
- residual_freq, dxc_freq.inverted);
- res.ok = true;
-
- return res;
-}
-#endif
-
Modified:
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/db_base.h
===================================================================
--- gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/db_base.h
2008-11-07 21:51:36 UTC (rev 9954)
+++ gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/db_base.h
2008-11-08 02:39:56 UTC (rev 9955)
@@ -34,22 +34,6 @@
class usrp_basic;
typedef boost::shared_ptr<usrp_basic> usrp_basic_sptr;
-#if 0
-class tune_result
-{
-public:
- tune_result(double baseband=0, double dxc=0,
- double residual=0, bool inv=0);
- ~tune_result();
-
- bool ok;
- double baseband_freq;
- double dxc_freq;
- double residual_freq;
- bool inverted;
-};
-#endif
-
struct freq_result_t
{
bool ok;
@@ -80,6 +64,7 @@
int dbid();
std::string name();
std::string side_and_name();
+ int which() { return d_which; }
bool bypass_adc_buffers(bool bypass);
bool set_atr_mask(int v);
@@ -107,11 +92,6 @@
virtual bool set_auto_tr(bool on);
virtual bool select_rx_antenna(int which_antenna);
- // FIXME tune shouldn't be a method of db_base
- // tune_result tune(int chan, double target_freq);
-
- int which() { return d_which; }
-
};
Modified:
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_standard.cc
===================================================================
---
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_standard.cc
2008-11-07 21:51:36 UTC (rev 9954)
+++
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_standard.cc
2008-11-08 02:39:56 UTC (rev 9955)
@@ -44,6 +44,154 @@
#define NELEM(x) (sizeof (x) / sizeof (x[0]))
+void
+usrp_standard_common::calc_dxc_freq(double target_freq, double baseband_freq,
long fs,
+ double *dxc_freq, bool *inverted)
+{
+ /*
+ Calculate the frequency to use for setting the digital up or down
converter.
+
+ @param target_freq: desired RF frequency (Hz)
+ @param baseband_freq: the RF frequency that corresponds to DC in the IF.
+ @param fs: converter sample rate
+
+ @returns: 2-tuple (ddc_freq, inverted) where ddc_freq is the value
+ for the ddc and inverted is True if we're operating in an inverted
+ Nyquist zone.
+ */
+
+ double delta = target_freq - baseband_freq;
+
+ if(delta >= 0) {
+ while(delta > fs) {
+ delta -= fs;
+ }
+ if(delta <= fs/2) { // non-inverted region
+ *dxc_freq = -delta;
+ *inverted = false;
+ }
+ else { // inverted region
+ *dxc_freq = delta - fs;
+ *inverted = true;
+ }
+ }
+ else {
+ while(delta < -fs) {
+ delta += fs;
+ }
+ if(delta >= -fs/2) {
+ *dxc_freq = -delta; // non-inverted region
+ *inverted = false;
+ }
+ else { // inverted region
+ *dxc_freq = delta + fs;
+ *inverted = true;
+ }
+ }
+}
+
+
+/*
+ * Real lambda expressions would be _so_ much easier...
+ */
+class dxc_control {
+public:
+ virtual bool is_tx() = 0;
+ virtual bool set_dxc_freq(double dxc_freq) = 0;
+ virtual double dxc_freq() = 0;
+};
+
+class ddc_control : public dxc_control {
+ usrp_standard_rx_sptr d_u;
+ int d_chan;
+
+ ddc_control(usrp_standard_rx_sptr u, int chan)
+ : d_u(u), d_chan(chan) {}
+
+ bool is_tx(){ return false; }
+ bool set_dxc_freq(double dxc_freq){ return d_u->set_rx_freq(d_chan,
dxc_freq); }
+ double dxc_freq(){ return d_u->rx_freq(d_chan); }
+};
+
+class duc_control : public dxc_control {
+ usrp_standard_tx_sptr d_u;
+ int d_chan;
+
+ duc_control(usrp_standard_tx_sptr u, int chan)
+ : d_u(u), d_chan(chan) {}
+
+ bool is_tx(){ return true; }
+ bool set_dxc_freq(double dxc_freq){ return d_u->set_tx_freq(d_chan,
dxc_freq); }
+ double dxc_freq() { return d_u->tx_freq(d_chan); }
+};
+
+
+/*!
+ * \brief Tune such that target_frequency ends up at DC in the complex baseband
+ *
+ * \param db the daughterboard to use
+ * \param target_freq the center frequency we want at baseband (DC)
+ * \param fs the sample rate
+ * \param dxc DDC or DUC access and control object
+ * \param[out] result details of what we did
+ *
+ * \returns true iff operation was successful
+ *
+ * Tuning is a two step process. First we ask the front-end to
+ * tune as close to the desired frequency as it can. Then we use
+ * the result of that operation and our target_frequency to
+ * determine the value for the digital down converter.
+ */
+static bool
+tune_a_helper(db_base_sptr db, double target_freq, double fs,
+ dxc_control &dxc, usrp_tune_result *result)
+{
+ bool inverted = false;
+ double dxc_freq;
+ double actual_dxc_freq;
+
+ // Ask the d'board to tune as closely as it can to target_freq
+#if 0
+ bool ok = db->set_freq(target_freq, &result->baseband_freq);
+#else
+ bool ok;
+ {
+ freq_result_t fr = db->set_freq(target_freq);
+ ok = fr.ok;
+ result->baseband_freq = fr.baseband_freq;
+ }
+#endif
+
+ // Calculate the DDC setting that will downconvert the baseband from the
+ // daughterboard to our target frequency.
+ usrp_standard_common::calc_dxc_freq(target_freq, result->baseband_freq, fs,
+ &dxc_freq, &inverted);
+
+ // If the spectrum is inverted, and the daughterboard doesn't do
+ // quadrature downconversion, we can fix the inversion by flipping the
+ // sign of the dxc_freq... (This only happens using the basic_rx board)
+
+ if(db->spectrum_inverted())
+ inverted = !inverted;
+
+ if(inverted && !db->is_quadrature()){
+ dxc_freq = -dxc_freq;
+ inverted = !inverted;
+ }
+
+ if (dxc.is_tx()) // down conversion versus up conversion
+ dxc_freq = -dxc_freq;
+
+ ok &= dxc.set_dxc_freq(dxc_freq);
+ actual_dxc_freq = dxc.dxc_freq();
+
+ result->dxc_freq = dxc_freq;
+ result->residual_freq = dxc_freq - actual_dxc_freq;
+ result->spectrum_inverted = inverted;
+ return ok;
+}
+
+
static unsigned int
compute_freq_control_word_fpga (double master_freq, double target_freq,
double *actual_freq, bool verbose)
Modified:
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_standard.h
===================================================================
---
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_standard.h
2008-11-07 21:51:36 UTC (rev 9954)
+++
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_standard.h
2008-11-08 02:39:56 UTC (rev 9955)
@@ -32,10 +32,30 @@
typedef boost::shared_ptr<usrp_standard_tx> usrp_standard_tx_sptr;
typedef boost::shared_ptr<usrp_standard_rx> usrp_standard_rx_sptr;
+class usrp_tune_result
+{
+public:
+ // RF frequency that corresponds to DC in the IF
+ double baseband_freq;
+ // frequency programmed into the DDC/DUC
+ double dxc_freq;
+
+ // residual frequency (typically < 0.01 Hz)
+ double residual_freq;
+
+ // is the spectrum inverted?
+ bool spectrum_inverted;
+
+ usrp_tune_result(double baseband=0, double dxc=0, double residual=0, bool
inverted=false)
+ : baseband_freq(baseband), dxc_freq(dxc),
+ residual_freq(residual), spectrum_inverted(inverted) {}
+};
+
+
class usrp_standard_common
{
- int d_fpga_caps; // capability register val
+ int d_fpga_caps; // capability register val
protected:
usrp_standard_common(usrp_basic *parent);
@@ -64,6 +84,19 @@
* This will be 0, 1, or 2.
*/
int nducs() const;
+
+
+ /*!
+ * \brief Calculate the frequency to use for setting the digital up or down
converter.
+ *
+ * \param target_freq is the desired RF frequency (Hz).
+ * \param baseband_freq is the RF frequency that corresponds to DC in the IF
coming from the d'board.
+ * \param fs is the sampling frequency.
+ * \param[out] dxc_freq the frequency to program into the DDC (or DUC).
+ * \param[out] inverted is true if we're operating in an inverted Nyquist
zone.
+ */
+ static void calc_dxc_freq(double target_freq, double baseband_freq, long fs,
+ double *dxc_freq, bool *inverted);
};
/*!
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9955 - gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy,
eb <=