[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8873 - gnuradio/branches/developers/trondeau/dbs/gr-u
From: |
trondeau |
Subject: |
[Commit-gnuradio] r8873 - gnuradio/branches/developers/trondeau/dbs/gr-usrp/src |
Date: |
Sun, 13 Jul 2008 11:17:37 -0600 (MDT) |
Author: trondeau
Date: 2008-07-13 11:17:36 -0600 (Sun, 13 Jul 2008)
New Revision: 8873
Added:
gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.cc
gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.h
gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.i
Log:
wip: adding c++ daughterboard base class
Added: gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.cc
===================================================================
--- gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.cc
(rev 0)
+++ gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.cc
2008-07-13 17:17:36 UTC (rev 8873)
@@ -0,0 +1,322 @@
+//
+// Copyright 2008 Free Software Foundation, Inc.
+//
+// This file is part of GNU Radio
+//
+// GNU Radio is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either asversion 3, or (at your option)
+// any later version.
+//
+// GNU Radio is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with GNU Radio; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street,
+// Boston, MA 02110-1301, USA.
+//
+
+#include <db_base.h>
+#include <usrp1_base.h>
+
+tune_result::tune_result(float baseband, float dxc, float residual, bool inv)
+ : ok(false), baseband_freq(baseband), dxc_freq(dxc),
+ residual_freq(residual), inverted(inv)
+{
+}
+
+tune_result::~tune_result()
+{
+}
+
+
+/******************************************************************************/
+
+db_base::db_base(usrp1_base *usrp, int which, bool tx)
+{
+ d_which = which;
+ d_tx = tx;
+ d_usrp = usrp;
+}
+
+int db_base::dbid()
+{
+ return d_usrp->daughterboard_id(d_which);
+}
+
+std::string db_base::name()
+{
+ //return "testing";
+ return usrp_dbid_to_string(dbid());
+}
+
+std::string db_base::side_and_name()
+{
+ if(d_which == 0)
+ return "A: " + name();
+ else
+ return "B: " + name();
+}
+
+
+// Function to bypass ADC buffers. Any board which is DC-coupled should bypass
the buffers
+void
+db_base::bypass_adc_buffers(bool bypass)
+{
+ if(d_tx) {
+ throw "TX Board has no adc buffers";
+ }
+ if(d_which==0) {
+ d_usrp->set_adc_buffer_bypass(0, bypass);
+ d_usrp->set_adc_buffer_bypass(1, bypass);
+ }
+ else {
+ d_usrp->set_adc_buffer_bypass(2, bypass);
+ d_usrp->set_adc_buffer_bypass(3, bypass);
+ }
+}
+
+bool db_base::set_atr_mask(int v)
+{
+ // Set Auto T/R mask.
+ return d_usrp->_write_fpga_reg(FR_ATR_MASK_0 + 3 * d_slot, v);
+}
+
+bool db_base::set_atr_txval(int v)
+{
+ // Set Auto T/R register value to be used when transmitting.
+ return d_usrp->_write_fpga_reg(FR_ATR_TXVAL_0 + 3 * d_slot, v);
+}
+
+bool db_base::set_atr_rxval(int v)
+{
+ // Set Auto T/R register value to be used when receiving.
+ return d_usrp->_write_fpga_reg(FR_ATR_RXVAL_0 + 3 * d_slot, v);
+}
+
+bool db_base::set_atr_tx_delay(int v)
+{
+ // Set Auto T/R delay (in clock ticks) from when Tx fifo gets data to
+ // when T/R switches.
+ return d_usrp->_write_fpga_reg(FR_ATR_TX_DELAY, v);
+}
+
+bool db_base::set_atr_rx_delay(int v)
+{
+ // Set Auto T/R delay (in clock ticks) from when Tx fifo goes empty to
+ // when T/R switches.
+ return d_usrp->_write_fpga_reg(FR_ATR_RX_DELAY, v);
+}
+
+std::vector<float> db_base::freq_range()
+{
+ // Return range of frequencies in Hz that can be tuned by this d'board.
+
+ // @returns (min_freq, max_freq, step_size)
+ // @rtype tuple
+ throw 0;
+}
+
+//bool db_base::set_freq(float target_freq, float &baseband_freq)
+std::vector<float> db_base::set_freq(float target_freq)
+{
+ // Set the frequency.
+ //
+ // @param freq: target RF frequency in Hz
+ // @type freq: float
+ //
+ // @returns (ok, actual_baseband_freq) where:
+ // ok is True or False and indicates success or failure,
+ // actual_baseband_freq is the RF frequency that corresponds to DC in the
IF.
+ printf("db_base::set_freq\n");
+ throw 0;
+}
+
+std::vector<float> db_base::gain_range()
+{
+ // Return range of gain that can be set by this d'board.
+ //
+ // @returns (min_gain, max_gain, step_size)
+ // Where gains are expressed in decibels (your mileage may vary)
+ printf("db_base::set_gain_range\n");
+ throw 0;
+}
+
+bool db_base::set_gain(float gain)
+{
+ // Set the gain.
+ //
+ // @param gain: gain in decibels
+ // @returns True/False
+ printf("db_base::set_gain\n");
+ throw 0;
+}
+
+bool db_base::is_quadrature()
+{
+ // Return True if this daughterboard does quadrature up or down conversion.
+ // That is, return True if this board requires both I & Q analog channels.
+ //
+ // This bit of info is useful when setting up the USRP Rx mux register.
+ throw 0;
+}
+
+bool db_base::i_and_q_swapped()
+{
+ // Return True if this is a quadrature device and (for RX) ADC 0 is Q
+ // or (for TX) DAC 0 is Q
+ return false;
+}
+
+bool db_base::spectrum_inverted()
+{
+ // Return True if the dboard gives an inverted spectrum
+
+ return false;
+}
+
+void db_base::set_enable(bool on)
+{
+ // For tx daughterboards, this controls the transmitter enable.
+}
+
+void db_base::set_auto_tr(bool on)
+{
+ // Enable automatic Transmit/Receive switching (ATR).
+ //
+ // Should be overridden in subclasses that care. This will typically
+ // set the atr_mask, txval and rxval.
+}
+
+void db_base::set_lo_offset(float offset)
+{
+ // Set how much LO is offset from requested frequency
+ //
+ // Should be overriden by daughterboards that care.
+}
+
+float db_base::lo_offset(float offset)
+{
+ // Get how much LO is offset from requested frequency
+ //
+ // Should be overriden by daughterboards that care.
+ return 0.0;
+}
+
+void db_base::select_rx_antenna(int which_antenna)
+{
+ // Specify which antenna port to use for reception.
+ // Should be overriden by daughterboards that care.
+}
+
+
+// Reference Clock section
+//
+// Control whether a reference clock is sent to the daughterboards,
+// and what frequency
+//
+// Bit 7 -- 1 turns on refclk, 0 allows IO use
+// Bits 6:0 Divider value
+//
+
+float
+db_base::_refclk_freq()
+{
+ return d_usrp->fpga_master_clock_freq() / _refclk_divisor();
+}
+
+void
+db_base::_enable_refclk(bool enable)
+{
+ int CLOCK_OUT = 1; // Clock is on lowest bit
+ int REFCLK_ENABLE = 0x80;
+ int REFCLK_DIVISOR_MASK = 0x7f;
+ if(enable) {
+ d_usrp->_write_oe(d_which, CLOCK_OUT, CLOCK_OUT); // output enable
+ d_usrp->_write_fpga_reg(d_refclk_reg,
+ ((_refclk_divisor() & REFCLK_DIVISOR_MASK)
+ | REFCLK_ENABLE));
+ }
+ else {
+ d_usrp->_write_fpga_reg(d_refclk_reg, 0);
+ }
+}
+
+int
+db_base::_refclk_divisor()
+{
+ // Return value to stick in REFCLK_DIVISOR register
+ throw 0;
+}
+
+tune_result db_base::tune(int chan, float 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;
+ float baseband_freq;
+ std::vector<float> freq = set_freq(target_freq);
+ ok = (bool)freq[0];
+ baseband_freq = freq[1];
+
+ bool inverted;
+ float dxc_freq = calc_dxc_freq(target_freq, baseband_freq,
d_usrp->converter_rate(), 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(spectrum_inverted()) {
+ inverted = !(inverted);
+ }
+
+ if(inverted && (!is_quadrature())) {
+ dxc_freq = -dxc_freq;
+ inverted = !(inverted);
+ }
+
+ if (!d_tx) {
+ ok = ok && d_usrp->set_rx_freq(chan, dxc_freq);
+ }
+ else {
+ dxc_freq = -dxc_freq;
+ ok = ok && d_usrp->set_tx_freq(chan, dxc_freq);
+ }
+
+ if(!ok) {
+ return tune_result(0, 0, 0, 0);
+ }
+
+ // residual_freq is the offset left over because of dxc tuning step size
+ float residual_freq;
+ if(!d_tx) {
+ residual_freq = dxc_freq - d_usrp->rx_freq(chan);
+ }
+ else {
+ // FIXME 50-50 chance this has the wrong sign...
+ residual_freq = dxc_freq - d_usrp->tx_freq(chan);
+ }
+
+ tune_result res = tune_result(baseband_freq, dxc_freq, residual_freq,
inverted);
+ res.ok = true;
+
+ return res;
+}
Added: gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.h
===================================================================
--- gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.h
(rev 0)
+++ gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.h
2008-07-13 17:17:36 UTC (rev 8873)
@@ -0,0 +1,103 @@
+/* -*- c++ -*- */
+//
+// Copyright 2008 Free Software Foundation, Inc.
+//
+// This file is part of GNU Radio
+//
+// GNU Radio is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either asversion 3, or (at your option)
+// any later version.
+//
+// GNU Radio is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with GNU Radio; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street,
+// Boston, MA 02110-1301, USA.
+//
+
+#ifndef DB_BASE_H
+#define DB_BASE_H
+
+#include <fpga_regs_standard.h>
+#include <fpga_regs_common.h>
+#include <vector>
+#include <usrp_prims.h>
+
+class usrp1_base;
+
+#define NUM_DAUGHTERBOARDS 1
+
+
+class tune_result
+{
+public:
+ tune_result(float baseband=0, float dxc=0,
+ float residual=0, bool inv=0);
+ ~tune_result();
+
+ bool ok;
+ float baseband_freq;
+ float dxc_freq;
+ float residual_freq;
+ bool inverted;
+};
+
+
+/******************************************************************************/
+
+class db_base
+{
+ public:
+ db_base(usrp1_base *usrp, int which, bool tx=true);
+ ~db_base() {}
+
+ int dbid();
+
+ std::string name();
+ std::string side_and_name();
+
+ void bypass_adc_buffers(bool bypass);
+ bool set_atr_mask(int v);
+ bool set_atr_txval(int v);
+ bool set_atr_rxval(int v);
+ bool set_atr_tx_delay(int v);
+ bool set_atr_rx_delay(int v);
+
+ ////////////////////////////////////////////////////////
+ // derived classes should override the following methods
+
+ virtual std::vector<float> freq_range();
+ virtual std::vector<float> set_freq(float target_freq);
+ virtual std::vector<float> gain_range();
+ virtual bool set_gain(float gain);
+ virtual bool is_quadrature();
+ virtual bool i_and_q_swapped();
+ virtual bool spectrum_inverted();
+ virtual void set_enable(bool on);
+ virtual void set_auto_tr(bool on);
+ virtual void set_lo_offset(float offset);
+ virtual float lo_offset(float offset);
+ virtual void select_rx_antenna(int which_antenna);
+
+ tune_result tune(int chan, float target_freq);
+
+ protected:
+ float _refclk_freq();
+ void _enable_refclk(bool enable);
+ virtual int _refclk_divisor();
+
+ int d_which;
+ usrp1_base *d_usrp;
+ int d_refclk_reg;
+ bool d_tx;
+ int d_slot;
+};
+
+#endif
+
+
Added: gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.i
===================================================================
--- gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.i
(rev 0)
+++ gnuradio/branches/developers/trondeau/dbs/gr-usrp/src/db_base.i
2008-07-13 17:17:36 UTC (rev 8873)
@@ -0,0 +1,112 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+%{
+#include "db_base.h"
+%}
+
+
+// ================================================================
+// abstract classes
+// ================================================================
+
+
+class db_base
+{
+public:
+ db_base(usrp1_base *usrp, int which, bool tx=true);
+ ~db_base();
+
+ int dbid();
+
+ std::string name();
+ std::string side_and_name();
+
+ void bypass_adc_buffers(bool bypass);
+ bool set_atr_mask(int v);
+ bool set_atr_txval(int v);
+ bool set_atr_rxval(int v);
+ bool set_atr_tx_delay(int v);
+ bool set_atr_rx_delay(int v);
+
+ ////////////////////////////////////////////////////////
+ // derived classes should override the following methods
+
+ virtual std::vector<float> freq_range();
+ //virtual bool set_freq(float target_freq, float &baseband_freq);
+ virtual std::vector<float> set_freq(float target_freq);
+ virtual std::vector<float> gain_range();
+ bool set_gain(float gain);
+ virtual bool is_quadrature();
+ virtual bool i_and_q_swapped();
+ virtual bool spectrum_inverted();
+ virtual void set_enable(bool on);
+ virtual void set_auto_tr(bool on);
+ virtual void set_lo_offset(float offset);
+ virtual float lo_offset(float offset);
+ virtual void select_rx_antenna(int which_antenna);
+
+ tune_result tune(int chan, float target_freq);
+
+ protected:
+ float _refclk_freq();
+ void _enable_refclk(bool enable);
+ virtual int _refclk_divisor();
+
+ int d_which;
+ usrp1_base *d_usrp;
+ int d_refclk_reg;
+ bool d_tx;
+ int d_slot;
+};
+
+
+// ================================================================
+// ================================================================
+
+
+struct subdev_spec pick_rx_subdevice(usrp1_base &u);
+
+class tune_result
+{
+private:
+ float d_baseband_freq;
+ float d_dxc_freq;
+ float d_residual_freq;
+ bool d_inverted;
+
+public:
+ tune_result(float baseband=0, float dxc=0,
+ float residual=0, bool inv=0);
+ ~tune_result();
+
+ bool ok;
+ float baseband_freq;
+ float dxc_freq;
+ float residual_freq;
+ bool inverted;
+};
+
+
+//bool tune(usrp1_base *u, int chan, db_base *subdev, float target_freq,
tune_result_sptr res);
+//bool tune(usrp1_base *u, int chan, db_base *subdev, float target_freq);
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8873 - gnuradio/branches/developers/trondeau/dbs/gr-usrp/src,
trondeau <=