1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
/* -*- c++ -*- */
/*
* Copyright 2004 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_USRP_STANDARD_H
#define INCLUDED_USRP_STANDARD_H
#include <usrp_basic.h>
class usrp_standard_common
{
int d_fpga_caps; // capability register val
protected:
usrp_standard_common(usrp_basic *parent);
public:
/*!
*\brief does the FPGA implement the final Rx half-band filter?
* If it doesn't, the maximum decimation factor with proper gain
* is 1/2 of what it would otherwise be.
*/
bool has_rx_halfband() const;
/*!
* \brief number of digital downconverters implemented in the FPGA
* This will be 0, 1, 2 or 4.
*/
int nddcs() const;
/*!
*\brief does the FPGA implement the initial Tx half-band filter?
*/
bool has_tx_halfband() const;
/*!
* \brief number of digital upconverters implemented in the FPGA
* This will be 0, 1, or 2.
*/
int nducs() const;
};
/*!
* \brief standard usrp RX class.
*
* Assumes digital down converter in FPGA
*/
class usrp_standard_rx : public usrp_basic_rx, usrp_standard_common
{
private:
static const int MAX_CHAN = 4;
unsigned int d_decim_rate;
int d_nchan;
int d_sw_mux;
int d_hw_mux;
double d_rx_freq[MAX_CHAN];
protected:
usrp_standard_rx (int which_board,
unsigned int decim_rate,
int nchan = 1,
int mux = -1,
int mode = 0,
int fusb_block_size = 0,
int fusb_nblocks = 0,
const std::string fpga_filename = "",
const std::string firmware_filename = ""
); // throws if trouble
bool write_hw_mux_reg ();
public:
enum {
FPGA_MODE_NORMAL = 0x00,
FPGA_MODE_LOOPBACK = 0x01,
FPGA_MODE_COUNTING = 0x02,
FPGA_MODE_COUNTING_32BIT = 0x04
};
~usrp_standard_rx ();
/*!
* \brief invokes constructor, returns instance or 0 if trouble
*
* \param which_board Which USRP board on usb (not particularly useful; use 0)
* \param fusb_block_size fast usb xfer block size. Must be a multiple of 512.
* Use zero for a reasonable default.
* \param fusb_nblocks number of fast usb URBs to allocate. Use zero for a reasonable default.
*/
static usrp_standard_rx *make (int which_board,
unsigned int decim_rate,
int nchan = 1,
int mux = -1,
int mode = 0,
int fusb_block_size = 0,
int fusb_nblocks = 0,
const std::string fpga_filename = "",
const std::string firmware_filename = ""
);
/*!
* \brief Set decimator rate. \p rate MUST BE EVEN and in [8, 256].
*
* The final complex sample rate across the USB is
* adc_freq () / decim_rate () * nchannels ()
*/
bool set_decim_rate (unsigned int rate);
/*!
* \brief Set number of active channels. \p nchannels must be 1, 2 or 4.
*
* The final complex sample rate across the USB is
* adc_freq () / decim_rate () * nchannels ()
*/
bool set_nchannels (int nchannels);
/*!
* \brief Set input mux configuration.
*
* This determines which ADC (or constant zero) is connected to
* each DDC input. There are 4 DDCs. Each has two inputs.
*
* <pre>
* Mux value:
*
* 3 2 1
* 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
* +-------+-------+-------+-------+-------+-------+-------+-------+
* | Q3 | I3 | Q2 | I2 | Q1 | I1 | Q0 | I0 |
* +-------+-------+-------+-------+-------+-------+-------+-------+
*
* Each 4-bit I field is either 0,1,2,3
* Each 4-bit Q field is either 0,1,2,3 or 0xf (input is const zero)
* All Q's must be 0xf or none of them may be 0xf
* </pre>
*/
bool set_mux (int mux);
/*!
* \brief set the frequency of the digital down converter.
*
* \p channel must be in the range [0,3]. \p freq is the center
* frequency in Hz. \p freq may be either negative or postive.
* The frequency specified is quantized. Use rx_freq to retrieve
* the actual value used.
*/
bool set_rx_freq (int channel, double freq);
/*!
* \brief set fpga mode
*/
bool set_fpga_mode (int mode);
/*!
* \brief Set the digital down converter phase register.
*
* \param channel which ddc channel [0, 3]
* \param phase 32-bit integer phase value.
*/
bool set_ddc_phase(int channel, int phase);
/*!
* \brief Specify Rx data format.
*
* \param format format specifier
*
* Rx data format control register
*
* 3 2 1
* 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
* +-----------------------------------------+-+-+---------+-------+
* | Reserved (Must be zero) |B|Q| WIDTH | SHIFT |
* +-----------------------------------------+-+-+---------+-------+
*
* SHIFT specifies arithmetic right shift [0, 15]
* WIDTH specifies bit-width of I & Q samples across the USB [1, 16] (not all valid)
* Q if set deliver both I & Q, else just I
* B if set bypass half-band filter.
*
* Right now the acceptable values are:
*
* B Q WIDTH SHIFT
* 0 1 16 0
* 0 1 8 8
*
* More valid combos to come.
*
* Default value is 0x00000300 16-bits, 0 shift, deliver both I & Q.
*/
bool set_format(unsigned int format);
static unsigned int make_format(int width=16, int shift=0,
bool want_q=true, bool bypass_halfband=false);
static int format_width(unsigned int format);
static int format_shift(unsigned int format);
static bool format_want_q(unsigned int format);
static bool format_bypass_halfband(unsigned int format);
// ACCESSORS
unsigned int decim_rate () const;
double rx_freq (int channel) const;
int nchannels () const;
int mux () const;
unsigned int format () const;
// called in base class to derived class order
bool start ();
bool stop ();
};
// ----------------------------------------------------------------
/*!
* \brief standard usrp TX class.
*
* Uses digital upconverter (coarse & fine modulators) in AD9862...
*/
class usrp_standard_tx : public usrp_basic_tx, usrp_standard_common
{
public:
enum coarse_mod_t {
CM_NEG_FDAC_OVER_4, // -32 MHz
CM_NEG_FDAC_OVER_8, // -16 MHz
CM_OFF,
CM_POS_FDAC_OVER_8, // +16 MHz
CM_POS_FDAC_OVER_4 // +32 MHz
};
protected:
static const int MAX_CHAN = 2;
unsigned int d_interp_rate;
int d_nchan;
int d_sw_mux;
int d_hw_mux;
double d_tx_freq[MAX_CHAN];
coarse_mod_t d_coarse_mod[MAX_CHAN];
unsigned char d_tx_modulator_shadow[MAX_CHAN];
virtual bool set_coarse_modulator (int channel, coarse_mod_t cm);
usrp_standard_tx::coarse_mod_t coarse_modulator (int channel) const;
protected:
usrp_standard_tx (int which_board,
unsigned int interp_rate,
int nchan = 1,
int mux = -1,
int fusb_block_size = 0,
int fusb_nblocks = 0,
const std::string fpga_filename = "",
const std::string firmware_filename = ""
); // throws if trouble
bool write_hw_mux_reg ();
public:
~usrp_standard_tx ();
/*!
* \brief invokes constructor, returns instance or 0 if trouble
*
* \param which_board Which USRP board on usb (not particularly useful; use 0)
* \param fusb_block_size fast usb xfer block size. Must be a multiple of 512.
* Use zero for a reasonable default.
* \param fusb_nblocks number of fast usb URBs to allocate. Use zero for a reasonable default.
*/
static usrp_standard_tx *make (int which_board,
unsigned int interp_rate,
int nchan = 1,
int mux = -1,
int fusb_block_size = 0,
int fusb_nblocks = 0,
const std::string fpga_filename = "",
const std::string firmware_filename = ""
);
/*!
* \brief Set interpolator rate. \p rate must be in [4, 512] and a multiple of 4.
*
* The final complex sample rate across the USB is
* dac_freq () / interp_rate () * nchannels ()
*/
virtual bool set_interp_rate (unsigned int rate);
/*!
* \brief Set number of active channels. \p nchannels must be 1 or 2.
*
* The final complex sample rate across the USB is
* dac_freq () / decim_rate () * nchannels ()
*/
bool set_nchannels (int nchannels);
/*!
* \brief Set output mux configuration.
*
* <pre>
* 3 2 1
* 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
* +-------------------------------+-------+-------+-------+-------+
* | | DAC3 | DAC2 | DAC1 | DAC0 |
* +-------------------------------+-------+-------+-------+-------+
*
* There are two interpolators with complex inputs and outputs.
* There are four DACs.
*
* Each 4-bit DACx field specifies the source for the DAC and
* whether or not that DAC is enabled. Each subfield is coded
* like this:
*
* 3 2 1 0
* +-+-----+
* |E| N |
* +-+-----+
*
* Where E is set if the DAC is enabled, and N specifies which
* interpolator output is connected to this DAC.
*
* N which interp output
* --- -------------------
* 0 chan 0 I
* 1 chan 0 Q
* 2 chan 1 I
* 3 chan 1 Q
* </pre>
*/
bool set_mux (int mux);
/*!
* \brief set the frequency of the digital up converter.
*
* \p channel must be in the range [0,1]. \p freq is the center
* frequency in Hz. It must be in the range [-44M, 44M].
* The frequency specified is quantized. Use tx_freq to retrieve
* the actual value used.
*/
virtual bool set_tx_freq (int channel, double freq); // chan: [0,1]
// ACCESSORS
unsigned int interp_rate () const;
double tx_freq (int channel) const;
int nchannels () const;
int mux () const;
// called in base class to derived class order
bool start ();
bool stop ();
};
#endif /* INCLUDED_USRP_STANDARD_H */
|