switch source package format to 3.0 quilt
[debian/gnuradio] / usrp / host / lib / legacy / usrp_standard.h
index 93a8aa56d980efa088719415fd423fb7e2134f6e..734fff4b5bcffb716a07bbb3b818a4bb0bac5cb3 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
 #define INCLUDED_USRP_STANDARD_H
 
 #include <usrp_basic.h>
+#include <boost/shared_ptr.hpp>
+#include <usrp_tune_result.h>
 
+class usrp_standard_tx;
+class usrp_standard_rx;
+
+typedef boost::shared_ptr<usrp_standard_tx> usrp_standard_tx_sptr;
+typedef boost::shared_ptr<usrp_standard_rx> usrp_standard_rx_sptr;
+
+/*!
+ * \ingroup usrp
+ */
 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);
@@ -56,14 +67,28 @@ public:
    * 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, double fs,
+                           double *dxc_freq, bool *inverted);
 };
 
 /*!
- * \brief standard usrp RX class.  
+ * \brief The C++ interface the receive side of the USRP
+ * \ingroup usrp
  *
- * Assumes digital down converter in FPGA
+ * This is the recommended interface to USRP receive functionality
+ * for applications that use the USRP but not GNU Radio.
  */
-class usrp_standard_rx : public usrp_basic_rx, usrp_standard_common
+class usrp_standard_rx : public usrp_basic_rx, public usrp_standard_common
 {
  private:
   static const int     MAX_CHAN = 4;
@@ -99,23 +124,29 @@ class usrp_standard_rx : public usrp_basic_rx, usrp_standard_common
   ~usrp_standard_rx ();
 
   /*!
-   * \brief invokes constructor, returns instance or 0 if trouble
+   * \brief invokes constructor, returns shared_ptr or shared_ptr equivalent of 0 if trouble
    *
    * \param which_board             Which USRP board on usb (not particularly useful; use 0)
+   * \param decim_rate      decimation factor
+   * \param nchan           number of channels
+   * \param mux                     Rx mux setting, \sa set_mux
+   * \param mode            mode
    * \param fusb_block_size  fast usb xfer block size.  Must be a multiple of 512. 
    *                         Use zero for a reasonable default.
    * \param fusb_nblocks     number of fast usb URBs to allocate.  Use zero for a reasonable default. 
+   * \param fpga_filename    Name of rbf file to load
+   * \param firmware_filename Name of ihx file to load
    */
-  static usrp_standard_rx *make (int which_board,
-                                unsigned int decim_rate,
-                                int nchan = 1,
-                                int mux = -1,
-                                int mode = 0,
-                                int fusb_block_size = 0,
-                                int fusb_nblocks = 0,
-                                const std::string fpga_filename = "",
-                                const std::string firmware_filename = ""
-                                );
+  static usrp_standard_rx_sptr make(int which_board,
+                                   unsigned int decim_rate,
+                                   int nchan = 1,
+                                   int mux = -1,
+                                   int mode = 0,
+                                   int fusb_block_size = 0,
+                                   int fusb_nblocks = 0,
+                                   const std::string fpga_filename = "",
+                                   const std::string firmware_filename = ""
+                                   );
   /*!
    * \brief Set decimator rate.  \p rate MUST BE EVEN and in [8, 256].
    *
@@ -154,6 +185,13 @@ class usrp_standard_rx : public usrp_basic_rx, usrp_standard_common
    */
   bool set_mux  (int mux);
 
+  /*!
+   * Determine the appropriate Rx mux value as a function of the subdevice choosen
+   * and the characteristics of the respective daughterboard.
+   */
+  int determine_rx_mux_value(const usrp_subdev_spec &ss);
+  int determine_rx_mux_value(const usrp_subdev_spec &ss_a, const usrp_subdev_spec &ss_b);
+
   /*!
    * \brief set the frequency of the digital down converter.
    *
@@ -214,6 +252,22 @@ class usrp_standard_rx : public usrp_basic_rx, usrp_standard_common
   static bool format_want_q(unsigned int format);
   static bool format_bypass_halfband(unsigned int format);
 
+  /*!
+   * \brief High-level "tune" method.  Works for the single channel case.
+   *
+   * This method adjusts both the daughterboard LO and the DDC so that
+   * target_freq ends up at DC in the complex baseband samples.
+   *
+   * \param chan  which DDC channel we're controlling (almost always 0).
+   * \param db    the daughterboard we're controlling.
+   * \param target_freq the RF frequency we want at DC in the complex baseband.
+   * \param[out] result details how the hardware was configured.
+   *
+   * \returns true iff everything was successful.
+   */
+  bool tune(int chan, db_base_sptr db, double target_freq, usrp_tune_result *result);
+  
+
   // ACCESSORS
   unsigned int decim_rate () const;
   double rx_freq (int channel) const;
@@ -229,11 +283,15 @@ class usrp_standard_rx : public usrp_basic_rx, usrp_standard_common
 // ----------------------------------------------------------------
 
 /*!
- * \brief standard usrp TX class.
+ * \brief The C++ interface the transmit side of the USRP
+ * \ingroup usrp
+ *
+ * This is the recommended interface to USRP transmit functionality
+ * for applications that use the USRP but not GNU Radio.
  *
  * Uses digital upconverter (coarse & fine modulators) in AD9862...
  */
-class usrp_standard_tx : public usrp_basic_tx, usrp_standard_common
+class usrp_standard_tx : public usrp_basic_tx, public usrp_standard_common
 {
  public:
   enum coarse_mod_t {
@@ -274,22 +332,27 @@ class usrp_standard_tx : public usrp_basic_tx, usrp_standard_common
   ~usrp_standard_tx ();
 
   /*!
-   * \brief invokes constructor, returns instance or 0 if trouble
+   * \brief invokes constructor, returns shared_ptr or shared_ptr equivalent of 0 if trouble
    *
    * \param which_board             Which USRP board on usb (not particularly useful; use 0)
+   * \param interp_rate             interpolation factor
+   * \param nchan           number of channels
+   * \param mux                     Tx mux setting, \sa set_mux
    * \param fusb_block_size  fast usb xfer block size.  Must be a multiple of 512. 
    *                         Use zero for a reasonable default.
    * \param fusb_nblocks     number of fast usb URBs to allocate.  Use zero for a reasonable default. 
+   * \param fpga_filename    Name of rbf file to load
+   * \param firmware_filename Name of ihx file to load
    */
-  static usrp_standard_tx *make (int which_board,
-                                unsigned int interp_rate,
-                                int nchan = 1,
-                                int mux = -1,
-                                int fusb_block_size = 0,
-                                int fusb_nblocks = 0,
-                                const std::string fpga_filename = "",
-                                const std::string firmware_filename = ""
-                                );
+  static usrp_standard_tx_sptr make(int which_board,
+                                   unsigned int interp_rate,
+                                   int nchan = 1,
+                                   int mux = -1,
+                                   int fusb_block_size = 0,
+                                   int fusb_nblocks = 0,
+                                   const std::string fpga_filename = "",
+                                   const std::string firmware_filename = ""
+                                   );
 
   /*!
    * \brief Set interpolator rate.  \p rate must be in [4, 512] and a multiple of 4.
@@ -342,6 +405,13 @@ class usrp_standard_tx : public usrp_basic_tx, usrp_standard_common
    */
   bool set_mux  (int mux);
 
+  /*!
+   * Determine the appropriate Tx mux value as a function of the subdevice choosen
+   * and the characteristics of the respective daughterboard.
+   */
+  int determine_tx_mux_value(const usrp_subdev_spec &ss);
+  int determine_tx_mux_value(const usrp_subdev_spec &ss_a, const usrp_subdev_spec &ss_b);
+
   /*!
    * \brief set the frequency of the digital up converter.
    *
@@ -358,6 +428,22 @@ class usrp_standard_tx : public usrp_basic_tx, usrp_standard_common
   int nchannels () const;
   int mux () const;
 
+  /*!
+   * \brief High-level "tune" method.  Works for the single channel case.
+   *
+   * This method adjusts both the daughterboard LO and the DUC so that
+   * DC in the complex baseband samples ends up at RF target_freq.
+   *
+   * \param chan  which DUC channel we're controlling (usually == which_side).
+   * \param db    the daughterboard we're controlling.
+   * \param target_freq the RF frequency we want our baseband translated to.
+   * \param[out] result details how the hardware was configured.
+   *
+   * \returns true iff everything was successful.
+   */
+  bool tune(int chan, db_base_sptr db, double target_freq, usrp_tune_result *result);
+
+
   // called in base class to derived class order
   bool start ();
   bool stop ();