GNU Radio 3.4.2 C++ API
usrp_sink_base.h
Go to the documentation of this file.
00001 
00002 /* -*- c++ -*- */
00003 /*
00004  * Copyright 2004,2006,2008,2009 Free Software Foundation, Inc.
00005  * 
00006  * This file is part of GNU Radio
00007  * 
00008  * GNU Radio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 3, or (at your option)
00011  * any later version.
00012  * 
00013  * GNU Radio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with GNU Radio; see the file COPYING.  If not, write to
00020  * the Free Software Foundation, Inc., 51 Franklin Street,
00021  * Boston, MA 02110-1301, USA.
00022  */
00023 
00024 #ifndef INCLUDED_USRP_SINK_BASE_H
00025 #define INCLUDED_USRP_SINK_BASE_H
00026 
00027 #include <usrp_base.h>
00028 #include <stdexcept>
00029 #include <usrp/usrp_tune_result.h>
00030 #include <usrp/usrp_dbid.h>
00031 
00032 class usrp_standard_tx;
00033 
00034 /*!
00035  * \brief abstract interface to Universal Software Radio Peripheral Tx path (Rev 1)
00036  */
00037 class usrp_sink_base : public usrp_base {
00038  private:
00039   boost::shared_ptr<usrp_standard_tx>   d_usrp;
00040   int                    d_nunderruns;
00041   
00042  protected:
00043   usrp_sink_base (const std::string &name,
00044                    gr_io_signature_sptr input_signature,
00045                    int which_board,
00046                    unsigned int interp_rate,
00047                    int nchan,
00048                    int mux,
00049                    int fusb_block_size,
00050                    int fusb_nblocks,
00051                    const std::string fpga_filename,
00052                    const std::string firmware_filename
00053                    ) throw (std::runtime_error);
00054 
00055   /*!
00056    * \brief convert between input item format and usrp native format
00057    *
00058    * \param[in] input_items             stream(s) of input items
00059    * \param[in] input_index             starting index in input_items
00060    * \param[in] input_items_available   number of items available starting at item[index]
00061    * \param[out] input_items_consumed   number of input items consumed by copy
00062    * \param[out] usrp_buffer            destination buffer
00063    * \param[in] usrp_buffer_length      \p usrp_buffer length in bytes
00064    * \param[out] bytes_written          number of bytes written into \p usrp_buffer
00065    */
00066   virtual void copy_to_usrp_buffer (gr_vector_const_void_star &input_items,
00067                                     int  input_index,
00068                                     int  input_items_available,
00069                                     int  &input_items_consumed,
00070                                     void *usrp_buffer,
00071                                     int  usrp_buffer_length,
00072                                     int  &bytes_written) = 0;
00073 
00074  public:
00075   ~usrp_sink_base ();
00076 
00077   int work (int noutput_items,
00078             gr_vector_const_void_star &input_items,
00079             gr_vector_void_star &output_items);
00080 
00081   /*!
00082    * \brief Set interpolator rate.  \p rate must be in [4, 1024] and a multiple of 4.
00083    *
00084    * The final complex sample rate across the USB is
00085    *   dac_freq () / interp_rate () * nchannels ()
00086    */
00087   bool set_interp_rate (unsigned int rate);
00088   bool set_nchannels (int nchan);
00089   bool set_mux (int mux);
00090   int determine_tx_mux_value(usrp_subdev_spec ss);
00091   int determine_tx_mux_value(usrp_subdev_spec ss_a, usrp_subdev_spec ss_b);
00092 
00093   /*!
00094    * \brief set the frequency of the digital up converter.
00095    *
00096    * \p channel must be 0.  \p freq is the center frequency in Hz.
00097    * It must be in the range [-44M, 44M].  The frequency specified is
00098    * quantized.  Use tx_freq to retrieve the actual value used.
00099    */
00100   bool set_tx_freq (int channel, double freq);
00101 
00102   long dac_rate() const { return converter_rate(); }    // alias
00103   long dac_freq() const { return converter_rate(); }    // deprecated alias
00104 
00105   unsigned int interp_rate () const;
00106   int nchannels () const;
00107   int mux () const;
00108   double tx_freq (int channel) const;
00109   int nunderruns () const { return d_nunderruns; }
00110 
00111   bool has_rx_halfband();
00112   bool has_tx_halfband();
00113   int nddcs();
00114   int nducs();
00115 
00116   /*!
00117    * \brief Called to enable drivers, etc for i/o devices.
00118    *
00119    * This allows a block to enable an associated driver to begin
00120    * transfering data just before we start to execute the scheduler.
00121    * The end result is that this reduces latency in the pipeline when
00122    * dealing with audio devices, usrps, etc.
00123    */
00124   bool start();
00125 
00126   /*!
00127    * \brief Called to disable drivers, etc for i/o devices.
00128    */
00129   bool stop();
00130 
00131   /*!
00132    * \brief High-level "tune" method.  Works for the single channel case.
00133    *
00134    * This method adjusts both the daughterboard LO and the DUC so that
00135    * DC in the complex baseband samples ends up at RF target_freq.
00136    *
00137    * \param chan  which DUC channel we're controlling (usually == which_side).
00138    * \param db    the daughterboard we're controlling.
00139    * \param target_freq the RF frequency we want our baseband translated to.
00140    * \param[out] result details how the hardware was configured.
00141    *
00142    * \returns true iff everything was successful.
00143    */
00144   bool tune(int chan, db_base_sptr db, double target_freq, usrp_tune_result *result);
00145 
00146   /*!
00147    * \brief Select suitable Tx daughterboard
00148    */
00149   usrp_subdev_spec pick_tx_subdevice();
00150 };
00151 
00152 #endif /* INCLUDED_USRP_SINK_BASE_H */