3 * Copyright 2004 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 2, 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_STANDARD_H
24 #define INCLUDED_USRP_STANDARD_H
26 #include <usrp_basic.h>
28 class usrp_standard_common
30 int d_fpga_caps; // capability register val
33 usrp_standard_common(usrp_basic *parent);
37 *\brief does the FPGA implement the final Rx half-band filter?
38 * If it doesn't, the maximum decimation factor with proper gain
39 * is 1/2 of what it would otherwise be.
41 bool has_rx_halfband() const;
44 * \brief number of digital downconverters implemented in the FPGA
45 * This will be 0, 1, 2 or 4.
50 *\brief does the FPGA implement the initial Tx half-band filter?
52 bool has_tx_halfband() const;
55 * \brief number of digital upconverters implemented in the FPGA
56 * This will be 0, 1, or 2.
62 * \brief standard usrp RX class.
64 * Assumes digital down converter in FPGA
66 class usrp_standard_rx : public usrp_basic_rx, usrp_standard_common
69 static const int MAX_CHAN = 4;
70 unsigned int d_decim_rate;
74 double d_rx_freq[MAX_CHAN];
77 usrp_standard_rx (int which_board,
78 unsigned int decim_rate,
82 int fusb_block_size = 0,
84 const std::string fpga_filename = "",
85 const std::string firmware_filename = ""
86 ); // throws if trouble
88 bool write_hw_mux_reg ();
93 FPGA_MODE_NORMAL = 0x00,
94 FPGA_MODE_LOOPBACK = 0x01,
95 FPGA_MODE_COUNTING = 0x02,
96 FPGA_MODE_COUNTING_32BIT = 0x04
102 * \brief invokes constructor, returns instance or 0 if trouble
104 * \param which_board Which USRP board on usb (not particularly useful; use 0)
105 * \param fusb_block_size fast usb xfer block size. Must be a multiple of 512.
106 * Use zero for a reasonable default.
107 * \param fusb_nblocks number of fast usb URBs to allocate. Use zero for a reasonable default.
109 static usrp_standard_rx *make (int which_board,
110 unsigned int decim_rate,
114 int fusb_block_size = 0,
115 int fusb_nblocks = 0,
116 const std::string fpga_filename = "",
117 const std::string firmware_filename = ""
120 * \brief Set decimator rate. \p rate MUST BE EVEN and in [8, 256].
122 * The final complex sample rate across the USB is
123 * adc_freq () / decim_rate () * nchannels ()
125 bool set_decim_rate (unsigned int rate);
128 * \brief Set number of active channels. \p nchannels must be 1, 2 or 4.
130 * The final complex sample rate across the USB is
131 * adc_freq () / decim_rate () * nchannels ()
133 bool set_nchannels (int nchannels);
136 * \brief Set input mux configuration.
138 * This determines which ADC (or constant zero) is connected to
139 * each DDC input. There are 4 DDCs. Each has two inputs.
145 * 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
146 * +-------+-------+-------+-------+-------+-------+-------+-------+
147 * | Q3 | I3 | Q2 | I2 | Q1 | I1 | Q0 | I0 |
148 * +-------+-------+-------+-------+-------+-------+-------+-------+
150 * Each 4-bit I field is either 0,1,2,3
151 * Each 4-bit Q field is either 0,1,2,3 or 0xf (input is const zero)
152 * All Q's must be 0xf or none of them may be 0xf
155 bool set_mux (int mux);
158 * \brief set the frequency of the digital down converter.
160 * \p channel must be in the range [0,3]. \p freq is the center
161 * frequency in Hz. \p freq may be either negative or postive.
162 * The frequency specified is quantized. Use rx_freq to retrieve
163 * the actual value used.
165 bool set_rx_freq (int channel, double freq);
168 * \brief set fpga mode
170 bool set_fpga_mode (int mode);
173 * \brief Set the digital down converter phase register.
175 * \param channel which ddc channel [0, 3]
176 * \param phase 32-bit integer phase value.
178 bool set_ddc_phase(int channel, int phase);
181 * \brief Specify Rx data format.
183 * \param format format specifier
185 * Rx data format control register
188 * 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
189 * +-----------------------------------------+-+-+---------+-------+
190 * | Reserved (Must be zero) |B|Q| WIDTH | SHIFT |
191 * +-----------------------------------------+-+-+---------+-------+
193 * SHIFT specifies arithmetic right shift [0, 15]
194 * WIDTH specifies bit-width of I & Q samples across the USB [1, 16] (not all valid)
195 * Q if set deliver both I & Q, else just I
196 * B if set bypass half-band filter.
198 * Right now the acceptable values are:
204 * More valid combos to come.
206 * Default value is 0x00000300 16-bits, 0 shift, deliver both I & Q.
208 bool set_format(unsigned int format);
210 static unsigned int make_format(int width=16, int shift=0,
211 bool want_q=true, bool bypass_halfband=false);
212 static int format_width(unsigned int format);
213 static int format_shift(unsigned int format);
214 static bool format_want_q(unsigned int format);
215 static bool format_bypass_halfband(unsigned int format);
218 unsigned int decim_rate () const;
219 double rx_freq (int channel) const;
220 int nchannels () const;
222 unsigned int format () const;
224 // called in base class to derived class order
229 // ----------------------------------------------------------------
232 * \brief standard usrp TX class.
234 * Uses digital upconverter (coarse & fine modulators) in AD9862...
236 class usrp_standard_tx : public usrp_basic_tx, usrp_standard_common
240 CM_NEG_FDAC_OVER_4, // -32 MHz
241 CM_NEG_FDAC_OVER_8, // -16 MHz
243 CM_POS_FDAC_OVER_8, // +16 MHz
244 CM_POS_FDAC_OVER_4 // +32 MHz
248 static const int MAX_CHAN = 2;
249 unsigned int d_interp_rate;
253 double d_tx_freq[MAX_CHAN];
254 coarse_mod_t d_coarse_mod[MAX_CHAN];
255 unsigned char d_tx_modulator_shadow[MAX_CHAN];
257 virtual bool set_coarse_modulator (int channel, coarse_mod_t cm);
258 usrp_standard_tx::coarse_mod_t coarse_modulator (int channel) const;
261 usrp_standard_tx (int which_board,
262 unsigned int interp_rate,
265 int fusb_block_size = 0,
266 int fusb_nblocks = 0,
267 const std::string fpga_filename = "",
268 const std::string firmware_filename = ""
269 ); // throws if trouble
271 bool write_hw_mux_reg ();
274 ~usrp_standard_tx ();
277 * \brief invokes constructor, returns instance or 0 if trouble
279 * \param which_board Which USRP board on usb (not particularly useful; use 0)
280 * \param fusb_block_size fast usb xfer block size. Must be a multiple of 512.
281 * Use zero for a reasonable default.
282 * \param fusb_nblocks number of fast usb URBs to allocate. Use zero for a reasonable default.
284 static usrp_standard_tx *make (int which_board,
285 unsigned int interp_rate,
288 int fusb_block_size = 0,
289 int fusb_nblocks = 0,
290 const std::string fpga_filename = "",
291 const std::string firmware_filename = ""
295 * \brief Set interpolator rate. \p rate must be in [4, 512] and a multiple of 4.
297 * The final complex sample rate across the USB is
298 * dac_freq () / interp_rate () * nchannels ()
300 virtual bool set_interp_rate (unsigned int rate);
303 * \brief Set number of active channels. \p nchannels must be 1 or 2.
305 * The final complex sample rate across the USB is
306 * dac_freq () / decim_rate () * nchannels ()
308 bool set_nchannels (int nchannels);
311 * \brief Set output mux configuration.
315 * 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
316 * +-------------------------------+-------+-------+-------+-------+
317 * | | DAC3 | DAC2 | DAC1 | DAC0 |
318 * +-------------------------------+-------+-------+-------+-------+
320 * There are two interpolators with complex inputs and outputs.
321 * There are four DACs.
323 * Each 4-bit DACx field specifies the source for the DAC and
324 * whether or not that DAC is enabled. Each subfield is coded
332 * Where E is set if the DAC is enabled, and N specifies which
333 * interpolator output is connected to this DAC.
335 * N which interp output
336 * --- -------------------
343 bool set_mux (int mux);
346 * \brief set the frequency of the digital up converter.
348 * \p channel must be in the range [0,1]. \p freq is the center
349 * frequency in Hz. It must be in the range [-44M, 44M].
350 * The frequency specified is quantized. Use tx_freq to retrieve
351 * the actual value used.
353 virtual bool set_tx_freq (int channel, double freq); // chan: [0,1]
356 unsigned int interp_rate () const;
357 double tx_freq (int channel) const;
358 int nchannels () const;
361 // called in base class to derived class order
366 #endif /* INCLUDED_USRP_STANDARD_H */