usrp1_sink_base.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2004,2006 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_SINK_BASE_H
00024 #define INCLUDED_USRP1_SINK_BASE_H
00025 
00026 #include <gr_sync_block.h>
00027 #include <stdexcept>
00028 
00029 class usrp_standard_tx;
00030 
00031 
00035 class usrp1_sink_base : public gr_sync_block {
00036  private:
00037   usrp_standard_tx      *d_usrp;
00038   int                    d_nunderruns;
00039   
00040  protected:
00041   usrp1_sink_base (const std::string &name,
00042                    gr_io_signature_sptr input_signature,
00043                    int which_board,
00044                    unsigned int interp_rate,
00045                    int nchan,
00046                    int mux,
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 
00064   virtual void copy_to_usrp_buffer (gr_vector_const_void_star &input_items,
00065                                     int  input_index,
00066                                     int  input_items_available,
00067                                     int  &input_items_consumed,
00068                                     void *usrp_buffer,
00069                                     int  usrp_buffer_length,
00070                                     int  &bytes_written) = 0;
00071 
00072  public:
00074   static const int READ_FAILED = -99999;
00075 
00076 
00077   ~usrp1_sink_base ();
00078 
00079   int work (int noutput_items,
00080             gr_vector_const_void_star &input_items,
00081             gr_vector_void_star &output_items);
00082 
00083   bool start();
00084   bool stop();
00085 
00092   bool set_interp_rate (unsigned int rate);
00093   bool set_nchannels (int nchan);
00094   bool set_mux (int mux);
00095 
00103   bool set_tx_freq (int channel, double freq);
00104 
00105   void set_verbose (bool verbose);
00106 
00121   bool set_pga (int which, double gain_in_db);
00122 
00128   double pga (int which) const;
00129 
00133   double pga_min () const;
00134 
00138   double pga_max () const;
00139 
00143   double pga_db_per_step () const;
00144 
00145 
00146   // ACCESSORS
00147 
00148   long fpga_master_clock_freq() const;
00149   long converter_rate() const;
00150   long dac_rate() const { return converter_rate(); }    // alias
00151   long dac_freq() const { return converter_rate(); }    // deprecated alias
00152 
00153   unsigned int interp_rate () const;
00154   int nchannels () const;
00155   int mux () const;
00156   double tx_freq (int channel) const;
00157   int nunderruns () const { return d_nunderruns; }
00158 
00166   int daughterboard_id (int which_dboard) const;
00167 
00178   bool write_aux_dac (int which_board, int which_dac, int value);
00179 
00187   int read_aux_adc (int which_dboard, int which_adc);
00188 
00196   bool write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf);
00197 
00205   std::string read_eeprom (int i2c_addr, int eeprom_offset, int len);
00206 
00214   bool write_i2c (int i2c_addr, const std::string buf);
00215 
00223   std::string read_i2c (int i2c_addr, int len);
00224 
00230   bool set_adc_offset (int which, int offset);
00231 
00239   bool set_dac_offset (int which, int offset, int offset_pin);
00240 
00247   bool set_adc_buffer_bypass (int which, bool bypass);
00248 
00254   std::string serial_number();
00255 
00271   bool _write_oe (int which_dboard, int value, int mask);
00272 
00280   bool write_io (int which_dboard, int value, int mask);
00281 
00288   int read_io (int which_dboard);
00289 
00290   //
00291   // internal routines...
00292   // You probably shouldn't be using these...
00293   //
00300   bool _write_fpga_reg (int regno, int value);  //< 7-bit regno, 32-bit value
00301 
00307   int  _read_fpga_reg (int regno);
00308 
00316   bool _write_9862 (int which_codec, int regno, unsigned char value);
00317 
00324   int  _read_9862 (int which_codec, int regno) const;
00325 
00339   bool _write_spi (int optional_header, int enables, int format, std::string buf);
00340 
00341   /*
00342    * \brief Read data from SPI bus peripheral.
00343    *
00344    * \param optional_header     0,1 or 2 bytes to write before buf.
00345    * \param enables             bitmask of peripheral to read. See usrp_spi_defs.h
00346    * \param format              transaction format.  See usrp_spi_defs.h SPI_FMT_*
00347    * \param len                 number of bytes to read.  Must be in [0,64].
00348    * \returns the data read if sucessful, else a zero length string.
00349    *
00350    * Reads are limited to a maximum of 64 bytes.
00351    *
00352    * If \p format specifies that optional_header bytes are present, they
00353    * are written to the peripheral first.  Then \p len bytes are read from
00354    * the peripheral and returned.
00355    */
00356   std::string _read_spi (int optional_header, int enables, int format, int len);
00357 };
00358 
00359 #endif /* INCLUDED_USRP1_SINK_BASE_H */

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