GNU Radio 3.3.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2004,2008,2009 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_USRP_SOURCE_BASE_H 00024 #define INCLUDED_USRP_SOURCE_BASE_H 00025 00026 #include <usrp_base.h> 00027 #include <stdexcept> 00028 #include <usrp/usrp_tune_result.h> 00029 #include <usrp/usrp_dbid.h> 00030 00031 class usrp_standard_rx; 00032 00033 /*! 00034 * \brief abstract interface to Universal Software Radio Peripheral Rx path (Rev 1) 00035 */ 00036 class usrp_source_base : public usrp_base { 00037 private: 00038 boost::shared_ptr<usrp_standard_rx> d_usrp; 00039 int d_noverruns; 00040 00041 protected: 00042 usrp_source_base (const std::string &name, 00043 gr_io_signature_sptr output_signature, 00044 int which_board, 00045 unsigned int decim_rate, 00046 int nchan, 00047 int mux, 00048 int mode, 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 return number of usrp input bytes required to produce noutput items. 00057 */ 00058 virtual int ninput_bytes_reqd_for_noutput_items (int noutput_items) = 0; 00059 00060 /*! 00061 * \brief number of bytes in a low-level sample 00062 */ 00063 unsigned int sizeof_basic_sample() const; 00064 00065 /*! 00066 * \brief convert between native usrp format and output item format 00067 * 00068 * \param[out] output_items stream(s) of output items 00069 * \param[in] output_index starting index in output_items 00070 * \param[in] output_items_available number of empty items available at item[index] 00071 * \param[out] output_items_produced number of items produced by copy 00072 * \param[in] usrp_buffer source buffer 00073 * \param[in] usrp_buffer_length number of bytes available in \p usrp_buffer 00074 * \param[out] bytes_read number of bytes read from \p usrp_buffer 00075 * 00076 * The copy must consume all bytes available. That is, \p bytes_read must equal 00077 * \p usrp_buffer_length. 00078 */ 00079 virtual void copy_from_usrp_buffer (gr_vector_void_star &output_items, 00080 int output_index, 00081 int output_items_available, 00082 int &output_items_produced, 00083 const void *usrp_buffer, 00084 int usrp_buffer_length, 00085 int &bytes_read) = 0; 00086 00087 public: 00088 ~usrp_source_base (); 00089 00090 int work (int noutput_items, 00091 gr_vector_const_void_star &input_items, 00092 gr_vector_void_star &output_items); 00093 00094 /*! 00095 * \brief Set decimator rate. \p rate must be EVEN and in [8, 256]. 00096 * 00097 * The final complex sample rate across the USB is 00098 * adc_freq () / decim_rate () 00099 */ 00100 bool set_decim_rate (unsigned int rate); 00101 bool set_nchannels (int nchan); 00102 bool set_mux (int mux); 00103 int determine_rx_mux_value(usrp_subdev_spec ss); 00104 int determine_rx_mux_value(usrp_subdev_spec ss_a, usrp_subdev_spec ss_b); 00105 00106 /*! 00107 * \brief set the center frequency of the digital down converter. 00108 * 00109 * \p channel must be 0. \p freq is the center frequency in Hz. 00110 * It must be in the range [-FIXME, FIXME]. The frequency specified is 00111 * quantized. Use rx_freq to retrieve the actual value used. 00112 */ 00113 bool set_rx_freq (int channel, double freq); 00114 00115 /*! 00116 * \brief set fpga special modes 00117 */ 00118 bool set_fpga_mode (int mode); 00119 00120 /*! 00121 * \brief Set the digital down converter phase register. 00122 * 00123 * \param channel which ddc channel [0, 3] 00124 * \param phase 32-bit integer phase value. 00125 */ 00126 bool set_ddc_phase(int channel, int phase); 00127 00128 long adc_rate() const { return converter_rate(); } // alias 00129 long adc_freq() const { return converter_rate(); } // deprecated alias 00130 00131 unsigned int decim_rate () const; 00132 int nchannels () const; 00133 int mux () const; 00134 double rx_freq (int channel) const; 00135 int noverruns () const { return d_noverruns; } 00136 00137 bool has_rx_halfband(); 00138 bool has_tx_halfband(); 00139 int nddcs(); 00140 int nducs(); 00141 00142 /*! 00143 * \brief Called to enable drivers, etc for i/o devices. 00144 * 00145 * This allows a block to enable an associated driver to begin 00146 * transfering data just before we start to execute the scheduler. 00147 * The end result is that this reduces latency in the pipeline when 00148 * dealing with audio devices, usrps, etc. 00149 */ 00150 bool start(); 00151 00152 /*! 00153 * \brief Called to disable drivers, etc for i/o devices. 00154 */ 00155 bool stop(); 00156 00157 /*! 00158 * \brief Specify Rx data format. 00159 * 00160 * \param format format specifier 00161 * 00162 * Rx data format control register 00163 * 00164 * 3 2 1 00165 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 00166 * +-----------------------------------------+-+-+---------+-------+ 00167 * | Reserved (Must be zero) |B|Q| WIDTH | SHIFT | 00168 * +-----------------------------------------+-+-+---------+-------+ 00169 * 00170 * SHIFT specifies arithmetic right shift [0, 15] 00171 * WIDTH specifies bit-width of I & Q samples across the USB [1, 16] (not all valid) 00172 * Q if set deliver both I & Q, else just I 00173 * B if set bypass half-band filter. 00174 * 00175 * Right now the acceptable values are: 00176 * 00177 * B Q WIDTH SHIFT 00178 * 0 1 16 0 00179 * 0 1 8 8 00180 * 00181 * More valid combos to come. 00182 * 00183 * Default value is 0x00000300 16-bits, 0 shift, deliver both I & Q. 00184 */ 00185 bool set_format(unsigned int format); 00186 00187 /*! 00188 * \brief return current format 00189 */ 00190 unsigned int format () const; 00191 00192 static unsigned int make_format(int width=16, int shift=0, 00193 bool want_q=true, bool bypass_halfband=false); 00194 static int format_width(unsigned int format); 00195 static int format_shift(unsigned int format); 00196 static bool format_want_q(unsigned int format); 00197 static bool format_bypass_halfband(unsigned int format); 00198 00199 /*! 00200 * \brief High-level "tune" method. Works for the single channel case. 00201 * 00202 * This method adjusts both the daughterboard LO and the DDC so that 00203 * target_freq ends up at DC in the complex baseband samples. 00204 * 00205 * \param chan which DDC channel we're controlling (almost always 0). 00206 * \param db the daughterboard we're controlling. 00207 * \param target_freq the RF frequency we want at DC in the complex baseband. 00208 * \param[out] result details how the hardware was configured. 00209 * 00210 * \returns true iff everything was successful. 00211 */ 00212 bool tune(int chan, db_base_sptr db, double target_freq, usrp_tune_result *result); 00213 00214 /*! 00215 * \brief Select suitable Rx daughterboard 00216 */ 00217 usrp_subdev_spec pick_rx_subdevice(); 00218 }; 00219 00220 #endif /* INCLUDED_USRP_SOURCE_BASE_H */