usrp1_source_base.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2004 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_USRP1_SOURCE_BASE_H
00024 #define INCLUDED_USRP1_SOURCE_BASE_H
00025 
00026 #include <gr_sync_block.h>
00027 #include <stdexcept>
00028 
00029 class usrp_standard_rx;
00030 
00034 class usrp1_source_base : public gr_sync_block {
00035  private:
00036   usrp_standard_rx      *d_usrp;
00037   int                    d_noverruns;
00038   
00039  protected:
00040   usrp1_source_base (const std::string &name,
00041                      gr_io_signature_sptr output_signature,
00042                      int which_board,
00043                      unsigned int decim_rate,
00044                      int nchan,
00045                      int mux,
00046                      int mode,
00047                      int fusb_block_size,
00048                      int fusb_nblocks,
00049                      const std::string fpga_filename,
00050                      const std::string firmware_filename
00051                      ) throw (std::runtime_error);
00052 
00056   virtual int ninput_bytes_reqd_for_noutput_items (int noutput_items) = 0;
00057 
00061   unsigned int sizeof_basic_sample() const;
00062 
00077   virtual void copy_from_usrp_buffer (gr_vector_void_star &output_items,
00078                                       int output_index,
00079                                       int output_items_available,
00080                                       int &output_items_produced,
00081                                       const void *usrp_buffer,
00082                                       int usrp_buffer_length,
00083                                       int &bytes_read) = 0;
00084 
00085  public:
00087   static const int READ_FAILED = -99999;
00088 
00089   ~usrp1_source_base ();
00090 
00091   int work (int noutput_items,
00092             gr_vector_const_void_star &input_items,
00093             gr_vector_void_star &output_items);
00094 
00095   bool start();
00096   bool stop();
00097 
00104   bool set_decim_rate (unsigned int rate);
00105   bool set_nchannels (int nchan);
00106   bool set_mux (int mux);
00107 
00115   bool set_rx_freq (int channel, double freq);
00116 
00120   bool set_fpga_mode (int mode);
00121 
00122   void set_verbose (bool verbose);
00123 
00130   bool set_ddc_phase(int channel, int phase);
00131 
00144   bool set_pga (int which, double gain_in_db);
00145 
00151   double pga (int which) const;
00152 
00156   double pga_min () const;
00157 
00161   double pga_max () const;
00162 
00166   double pga_db_per_step () const;
00167 
00168   // ACCESSORS
00169 
00170   long fpga_master_clock_freq() const;
00171   long converter_rate() const;
00172   long adc_rate() const { return converter_rate(); }   // alias
00173   long adc_freq() const { return converter_rate(); }   // deprecated alias
00174 
00175   unsigned int decim_rate () const;
00176   int nchannels () const;
00177   int mux () const;
00178   double rx_freq (int channel) const;
00179   int noverruns () const { return d_noverruns; }
00180 
00188   int daughterboard_id (int which_dboard) const;
00189 
00200   bool write_aux_dac (int which_board, int which_dac, int value);
00201 
00209   int read_aux_adc (int which_dboard, int which_adc);
00210 
00218   bool write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf);
00219 
00227   std::string read_eeprom (int i2c_addr, int eeprom_offset, int len);
00228 
00236   bool write_i2c (int i2c_addr, const std::string buf);
00237 
00245   std::string read_i2c (int i2c_addr, int len);
00246 
00252   bool set_adc_offset (int which, int offset);
00253 
00261   bool set_dac_offset (int which, int offset, int offset_pin);
00262 
00269   bool set_adc_buffer_bypass (int which, bool bypass);
00270 
00276   std::string serial_number();
00277 
00293   bool _write_oe (int which_dboard, int value, int mask);
00294 
00302   bool write_io (int which_dboard, int value, int mask);
00303 
00310   int read_io (int which_dboard);
00311 
00332   bool set_dc_offset_cl_enable(int bits, int mask);
00333 
00362   bool set_format(unsigned int format);
00363 
00367   unsigned int format () const;
00368 
00369   static unsigned int make_format(int width=16, int shift=0,
00370                                   bool want_q=true, bool bypass_halfband=false);
00371   static int format_width(unsigned int format);
00372   static int format_shift(unsigned int format);
00373   static bool format_want_q(unsigned int format);
00374   static bool format_bypass_halfband(unsigned int format);
00375 
00376   // ----------------------------------------------------------------
00377   // internal routines...  
00378   // You probably shouldn't be using these...
00379   // ----------------------------------------------------------------
00380 
00387   bool _write_fpga_reg (int regno, int value);  //< 7-bit regno, 32-bit value
00388 
00396   bool _write_fpga_reg_masked (int regno, int value, int mask); //< 7-bit regno, 16-bit value, 16-bit mask
00397 
00403   int  _read_fpga_reg (int regno);
00404 
00412   bool _write_9862 (int which_codec, int regno, unsigned char value);
00413 
00420   int  _read_9862 (int which_codec, int regno) const;
00421 
00435   bool _write_spi (int optional_header, int enables, int format, std::string buf);
00436 
00437   /*
00438    * \brief Read data from SPI bus peripheral.
00439    *
00440    * \param optional_header     0,1 or 2 bytes to write before buf.
00441    * \param enables             bitmask of peripheral to read. See usrp_spi_defs.h
00442    * \param format              transaction format.  See usrp_spi_defs.h SPI_FMT_*
00443    * \param len                 number of bytes to read.  Must be in [0,64].
00444    * \returns the data read if sucessful, else a zero length string.
00445    *
00446    * Reads are limited to a maximum of 64 bytes.
00447    *
00448    * If \p format specifies that optional_header bytes are present, they
00449    * are written to the peripheral first.  Then \p len bytes are read from
00450    * the peripheral and returned.
00451    */
00452   std::string _read_spi (int optional_header, int enables, int format, int len);
00453 };
00454 
00455 #endif /* INCLUDED_USRP1_SOURCE_BASE_H */

Generated on Thu Mar 5 09:01:19 2009 for GNU Radio 3.1.3 by  doxygen 1.5.8