3 * Copyright 2004,2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef INCLUDED_USRP_SOURCE_BASE_H
24 #define INCLUDED_USRP_SOURCE_BASE_H
26 #include <usrp_base.h>
28 #include <usrp_tune_result.h>
29 #include <usrp_dbid.h>
31 class usrp_standard_rx;
34 * \brief abstract interface to Universal Software Radio Peripheral Rx path (Rev 1)
36 class usrp_source_base : public usrp_base {
38 boost::shared_ptr<usrp_standard_rx> d_usrp;
42 usrp_source_base (const std::string &name,
43 gr_io_signature_sptr output_signature,
45 unsigned int decim_rate,
51 const std::string fpga_filename,
52 const std::string firmware_filename
53 ) throw (std::runtime_error);
56 * \brief return number of usrp input bytes required to produce noutput items.
58 virtual int ninput_bytes_reqd_for_noutput_items (int noutput_items) = 0;
61 * \brief number of bytes in a low-level sample
63 unsigned int sizeof_basic_sample() const;
66 * \brief convert between native usrp format and output item format
68 * \param[out] output_items stream(s) of output items
69 * \param[in] output_index starting index in output_items
70 * \param[in] output_items_available number of empty items available at item[index]
71 * \param[out] output_items_produced number of items produced by copy
72 * \param[in] usrp_buffer source buffer
73 * \param[in] usrp_buffer_length number of bytes available in \p usrp_buffer
74 * \param[out] bytes_read number of bytes read from \p usrp_buffer
76 * The copy must consume all bytes available. That is, \p bytes_read must equal
77 * \p usrp_buffer_length.
79 virtual void copy_from_usrp_buffer (gr_vector_void_star &output_items,
81 int output_items_available,
82 int &output_items_produced,
83 const void *usrp_buffer,
84 int usrp_buffer_length,
90 int work (int noutput_items,
91 gr_vector_const_void_star &input_items,
92 gr_vector_void_star &output_items);
95 * \brief Set decimator rate. \p rate must be EVEN and in [8, 256].
97 * The final complex sample rate across the USB is
98 * adc_freq () / decim_rate ()
100 bool set_decim_rate (unsigned int rate);
101 bool set_nchannels (int nchan);
102 bool set_mux (int mux);
103 int determine_rx_mux_value(usrp_subdev_spec ss);
104 int determine_rx_mux_value(usrp_subdev_spec ss_a, usrp_subdev_spec ss_b);
107 * \brief set the center frequency of the digital down converter.
109 * \p channel must be 0. \p freq is the center frequency in Hz.
110 * It must be in the range [-FIXME, FIXME]. The frequency specified is
111 * quantized. Use rx_freq to retrieve the actual value used.
113 bool set_rx_freq (int channel, double freq);
116 * \brief set fpga special modes
118 bool set_fpga_mode (int mode);
121 * \brief Set the digital down converter phase register.
123 * \param channel which ddc channel [0, 3]
124 * \param phase 32-bit integer phase value.
126 bool set_ddc_phase(int channel, int phase);
128 long adc_rate() const { return converter_rate(); } // alias
129 long adc_freq() const { return converter_rate(); } // deprecated alias
131 unsigned int decim_rate () const;
132 int nchannels () const;
134 double rx_freq (int channel) const;
135 int noverruns () const { return d_noverruns; }
137 bool has_rx_halfband();
138 bool has_tx_halfband();
143 * \brief Called to enable drivers, etc for i/o devices.
145 * This allows a block to enable an associated driver to begin
146 * transfering data just before we start to execute the scheduler.
147 * The end result is that this reduces latency in the pipeline when
148 * dealing with audio devices, usrps, etc.
153 * \brief Called to disable drivers, etc for i/o devices.
158 * \brief Specify Rx data format.
160 * \param format format specifier
162 * Rx data format control register
165 * 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
166 * +-----------------------------------------+-+-+---------+-------+
167 * | Reserved (Must be zero) |B|Q| WIDTH | SHIFT |
168 * +-----------------------------------------+-+-+---------+-------+
170 * SHIFT specifies arithmetic right shift [0, 15]
171 * WIDTH specifies bit-width of I & Q samples across the USB [1, 16] (not all valid)
172 * Q if set deliver both I & Q, else just I
173 * B if set bypass half-band filter.
175 * Right now the acceptable values are:
181 * More valid combos to come.
183 * Default value is 0x00000300 16-bits, 0 shift, deliver both I & Q.
185 bool set_format(unsigned int format);
188 * \brief return current format
190 unsigned int format () const;
192 static unsigned int make_format(int width=16, int shift=0,
193 bool want_q=true, bool bypass_halfband=false);
194 static int format_width(unsigned int format);
195 static int format_shift(unsigned int format);
196 static bool format_want_q(unsigned int format);
197 static bool format_bypass_halfband(unsigned int format);
200 * \brief High-level "tune" method. Works for the single channel case.
202 * This method adjusts both the daughterboard LO and the DDC so that
203 * target_freq ends up at DC in the complex baseband samples.
205 * \param chan which DDC channel we're controlling (almost always 0).
206 * \param db the daughterboard we're controlling.
207 * \param target_freq the RF frequency we want at DC in the complex baseband.
208 * \param[out] result details how the hardware was configured.
210 * \returns true iff everything was successful.
212 bool tune(int chan, db_base_sptr db, double target_freq, usrp_tune_result *result);
215 * \brief Select suitable Rx daughterboard
217 usrp_subdev_spec pick_rx_subdevice();
220 #endif /* INCLUDED_USRP_SOURCE_BASE_H */