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
|
/* -*- c++ -*- */
/*
* Copyright 2008,2009 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 3, 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.
*/
%include "gnuradio.i" // the common stuff
%import <stdint.i>
%{
#include "usrp2_source_16sc.h"
#include "usrp2_source_32fc.h"
#include "usrp2_sink_16sc.h"
#include "usrp2_sink_32fc.h"
%}
%include <usrp2/tune_result.h>
%include <usrp2/mimo_config.h>
%include <usrp2/metadata.h>
%template(uint32_t_vector) std::vector<uint32_t>;
// ----------------------------------------------------------------
class usrp2_base : public gr_sync_block
{
protected:
usrp2_base() throw (std::runtime_error);
public:
~usrp2_base();
std::string mac_addr() const;
std::string interface_name() const;
%rename(_real_fpga_master_clock_freq) fpga_master_clock_freq;
bool fpga_master_clock_freq(long *freq);
bool config_mimo(int flags);
bool sync_to_pps();
bool sync_every_pps(bool enable);
std::vector<uint32_t> peek32(uint32_t addr, uint32_t words);
bool poke32(uint32_t addr, const std::vector<uint32_t> &data);
};
// ----------------------------------------------------------------
class usrp2_source_base : public usrp2_base
{
protected:
usrp2_source_base() throw (std::runtime_error);
public:
~usrp2_source_base();
bool set_antenna(int ant);
bool set_gain(double gain);
%rename(_real_set_center_freq) set_center_freq;
bool set_lo_offset(double frequency);
bool set_center_freq(double frequency, usrp2::tune_result *r);
bool set_decim(int decimation_factor);
bool set_scale_iq(int scale_i, int scale_q);
int decim();
%rename(_real_adc_rate) adc_rate;
bool adc_rate(long *rate);
double gain_min();
double gain_max();
double gain_db_per_step();
double freq_min();
double freq_max();
%rename(_real_daughterboard_id) daughterboard_id;
bool daughterboard_id(int *dbid);
unsigned int overruns();
unsigned int missing();
bool set_gpio_ddr(uint16_t value, uint16_t mask);
bool set_gpio_sels(std::string sels);
bool write_gpio(uint16_t value, uint16_t mask);
%rename(_real_read_gpio) read_gpio;
bool read_gpio(uint16_t *value);
bool enable_gpio_streaming(int enable);
};
// ----------------------------------------------------------------
GR_SWIG_BLOCK_MAGIC(usrp2,source_32fc)
usrp2_source_32fc_sptr
usrp2_make_source_32fc(const std::string ifc="eth0",
const std::string mac="")
throw (std::runtime_error);
class usrp2_source_32fc : public usrp2_source_base
{
protected:
usrp2_source_32fc(const std::string &ifc, const std::string &mac);
public:
~usrp2_source_32fc();
};
// ----------------------------------------------------------------
GR_SWIG_BLOCK_MAGIC(usrp2,source_16sc)
usrp2_source_16sc_sptr
usrp2_make_source_16sc(const std::string ifc="eth0",
const std::string mac="")
throw (std::runtime_error);
class usrp2_source_16sc : public usrp2_source_base
{
protected:
usrp2_source_16sc(const std::string &ifc, const std::string &mac);
public:
~usrp2_source_16sc();
};
// ----------------------------------------------------------------
class usrp2_sink_base : public usrp2_base
{
protected:
usrp2_sink_base() throw (std::runtime_error);
public:
~usrp2_sink_base();
bool set_antenna(int ant);
bool set_gain(double gain);
%rename(_real_set_center_freq) set_center_freq;
bool set_lo_offset(double frequency);
bool set_center_freq(double frequency, usrp2::tune_result *r);
bool set_interp(int interp_factor);
bool set_scale_iq(int scale_i, int scale_q);
int interp();
%rename(_real_default_tx_scale_iq) default_scale_iq;
void default_scale_iq(int interp, int *scale_i, int *scale_q);
%rename(_real_dac_rate) dac_rate;
bool dac_rate(long *rate);
double gain_min();
double gain_max();
double gain_db_per_step();
double freq_min();
double freq_max();
%rename(_real_daughterboard_id) daughterboard_id;
bool daughterboard_id(int *dbid);
bool set_gpio_ddr(uint16_t value, uint16_t mask);
bool set_gpio_sels(std::string sels);
bool write_gpio(uint16_t value, uint16_t mask);
%rename(_real_read_gpio) read_gpio;
bool read_gpio(uint16_t *value);
bool start_streaming_at(usrp2::fpga_timestamp time);
};
// ----------------------------------------------------------------
GR_SWIG_BLOCK_MAGIC(usrp2,sink_32fc)
usrp2_sink_32fc_sptr
usrp2_make_sink_32fc(const std::string ifc="eth0",
const std::string mac="")
throw (std::runtime_error);
class usrp2_sink_32fc : public usrp2_sink_base
{
protected:
usrp2_sink_32fc(const std::string &ifc, const std::string &mac);
public:
~usrp2_sink_32fc();
};
// ----------------------------------------------------------------
GR_SWIG_BLOCK_MAGIC(usrp2,sink_16sc)
usrp2_sink_16sc_sptr
usrp2_make_sink_16sc(const std::string ifc="eth0",
const std::string mac="")
throw (std::runtime_error);
class usrp2_sink_16sc : public usrp2_sink_base
{
protected:
usrp2_sink_16sc(const std::string &ifc, const std::string &mac);
public:
~usrp2_sink_16sc();
};
// ----------------------------------------------------------------
// some utility functions to allow Python to deal with pointers
%{
long *make_long_ptr() { return new long; }
long deref_long_ptr(long *l) { return *l; }
void free_long_ptr(long *l) { delete l; }
int *make_int_ptr() { return new int; }
int deref_int_ptr(int *l) { return *l; }
void free_int_ptr(int *l) { delete l; }
uint16_t *make_uint16_ptr() { return new uint16_t; }
int deref_uint16_ptr(uint16_t *l) { return *l; }
void free_uint16_ptr(uint16_t *l) { delete l; }
%}
long *make_long_ptr();
long deref_long_ptr(long *l);
void free_long_ptr(long *l);
int *make_int_ptr();
int deref_int_ptr(int *l);
void free_int_ptr(int *l);
uint16_t *make_uint16_ptr();
int deref_uint16_ptr(uint16_t *l);
void free_uint16_ptr(uint16_t *l);
#ifdef SWIGPYTHON
// create a more pythonic interface
%pythoncode %{
def __set_center_freq(self, freq):
tr = tune_result()
r = self._real_set_center_freq(freq, tr)
if r:
return tr
else:
return None
def __fpga_master_clock_freq(self):
f = make_long_ptr();
r = self._real_fpga_master_clock_freq(f)
if r:
result = deref_long_ptr(f)
else:
result = None
free_long_ptr(f)
return result
def __adc_rate(self):
rate = make_long_ptr();
r = self._real_adc_rate(rate)
if r:
result = deref_long_ptr(rate)
else:
result = None
free_long_ptr(rate)
return result
def __dac_rate(self):
rate = make_long_ptr();
r = self._real_dac_rate(rate)
if r:
result = deref_long_ptr(rate)
else:
result = None
free_long_ptr(rate)
return result
def __gain_range(self):
return [self.gain_min(),
self.gain_max(),
self.gain_db_per_step()]
# NOTE: USRP1 uses a length three tuple here (3rd value is 'freq step'),
# but it's not really useful. We let an index error happen here
# to identify code using it.
def __freq_range(self):
return [self.freq_min(),
self.freq_max()]
def __daughterboard_id(self):
dbid = make_int_ptr()
r = self._real_daughterboard_id(dbid)
if r:
result = deref_int_ptr(dbid)
else:
result = None
free_int_ptr(dbid)
return result
def __default_tx_scale_iq(self, interp):
scale_i = make_int_ptr()
scale_q = make_int_ptr()
self._real_default_tx_scale_iq(interp, scale_i, scale_q)
return (deref_int_ptr(scale_i), deref_int_ptr(scale_q))
def __read_gpio(self):
value = make_uint16_ptr()
r = self._real_read_gpio(value)
if r:
result = deref_uint16_ptr(value)
else:
result = None
free_uint16_ptr(value)
return result
usrp2_source_32fc_sptr.set_center_freq = __set_center_freq
usrp2_source_16sc_sptr.set_center_freq = __set_center_freq
usrp2_sink_32fc_sptr.set_center_freq = __set_center_freq
usrp2_sink_16sc_sptr.set_center_freq = __set_center_freq
usrp2_source_32fc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
usrp2_source_16sc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
usrp2_sink_32fc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
usrp2_sink_16sc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
usrp2_source_32fc_sptr.adc_rate = __adc_rate
usrp2_source_16sc_sptr.adc_rate = __adc_rate
usrp2_sink_32fc_sptr.dac_rate = __dac_rate
usrp2_sink_16sc_sptr.dac_rate = __dac_rate
usrp2_source_32fc_sptr.gain_range = __gain_range
usrp2_source_16sc_sptr.gain_range = __gain_range
usrp2_sink_32fc_sptr.gain_range = __gain_range
usrp2_sink_16sc_sptr.gain_range = __gain_range
usrp2_source_32fc_sptr.freq_range = __freq_range
usrp2_source_16sc_sptr.freq_range = __freq_range
usrp2_sink_32fc_sptr.freq_range = __freq_range
usrp2_sink_16sc_sptr.freq_range = __freq_range
usrp2_source_32fc_sptr.daughterboard_id = __daughterboard_id
usrp2_source_16sc_sptr.daughterboard_id = __daughterboard_id
usrp2_sink_32fc_sptr.daughterboard_id = __daughterboard_id
usrp2_sink_16sc_sptr.daughterboard_id = __daughterboard_id
usrp2_sink_32fc_sptr.default_scale_iq = __default_tx_scale_iq
usrp2_sink_16sc_sptr.default_scale_iq = __default_tx_scale_iq
usrp2_source_32fc_sptr.read_gpio = __read_gpio
usrp2_source_16sc_sptr.read_gpio = __read_gpio
usrp2_sink_32fc_sptr.read_gpio = __read_gpio
usrp2_sink_16sc_sptr.read_gpio = __read_gpio
%}
#endif
#if SWIGGUILE
%scheme %{
(load-extension-global "libguile-gnuradio-usrp2_swig" "scm_init_gnuradio_usrp2_swig_module")
%}
%goops %{
(use-modules (gnuradio gnuradio_core_runtime))
%}
#endif
|