GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
usrp_block.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2015 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22 
23 #ifndef INCLUDED_GR_UHD_USRP_BLOCK_H
24 #define INCLUDED_GR_UHD_USRP_BLOCK_H
25 
26 #include <gnuradio/uhd/api.h>
27 #include <gnuradio/sync_block.h>
28 #include <uhd/usrp/multi_usrp.hpp>
29 
30 namespace gr {
31  namespace uhd {
32 
33  /*! Base class for USRP blocks.
34  * \ingroup uhd_blk
35  *
36  * Note that many of the functions defined here differ between
37  * Rx and Tx configurations. As an example, set_center_freq()
38  * will set the Rx frequency for a usrp_source object, and the
39  * Tx frequency on a usrp_sink object.
40  */
42  {
43  protected:
44  usrp_block() {}; // For virtual sub-classing
45  usrp_block(const std::string &name,
46  gr::io_signature::sptr input_signature,
47  gr::io_signature::sptr output_signature);
48  public:
49 
50  /*!
51  * Set the frontend specification.
52  *
53  * \param spec the subdev spec markup string
54  * \param mboard the motherboard index 0 to M-1
55  */
56  virtual void set_subdev_spec(const std::string &spec, size_t mboard = 0) = 0;
57 
58  /*!
59  * Get the frontend specification.
60  *
61  * \param mboard the motherboard index 0 to M-1
62  * \return the frontend specification in use
63  */
64  virtual std::string get_subdev_spec(size_t mboard = 0) = 0;
65 
66  /*!
67  * Return the number of motherboards in this configuration.
68  */
69  virtual size_t get_num_mboards() = 0;
70 
71  /*!
72  * Set the sample rate for this connection to the USRP.
73  *
74  * \param rate a new rate in Sps
75  */
76  virtual void set_samp_rate(double rate) = 0;
77 
78  /*!
79  * Get the sample rate for this connection to the USRP.
80  * This is the actual sample rate and may differ from the rate set.
81  *
82  * \return the actual rate in Sps
83  */
84  virtual double get_samp_rate(void) = 0;
85 
86  /*!
87  * Get the possible sample rates for this connection.
88  *
89  * \return a range of rates in Sps
90  */
91  virtual ::uhd::meta_range_t get_samp_rates(void) = 0;
92 
93  /*!
94  * Tune the selected channel to the desired center frequency.
95  *
96  * \param tune_request the tune request instructions
97  * \param chan the channel index 0 to N-1
98  * \return a tune result with the actual frequencies
99  */
100  virtual ::uhd::tune_result_t set_center_freq(
101  const ::uhd::tune_request_t tune_request,
102  size_t chan = 0
103  ) = 0;
104 
105  /*!
106  * Tune the the selected channel to the desired center frequency.
107  *
108  * This is a wrapper around set_center_freq() so that in this case,
109  * the user can pass a single frequency in the call instead of
110  * having to generate a tune_request_t object.
111  *
112  * \param freq the desired frequency in Hz
113  * \param chan the channel index 0 to N-1
114  * \return a tune result with the actual frequencies
115  */
116  ::uhd::tune_result_t set_center_freq(double freq, size_t chan = 0)
117  {
118  return set_center_freq(::uhd::tune_request_t(freq), chan);
119  }
120 
121  /*!
122  * Get the center frequency.
123  *
124  * \param chan the channel index 0 to N-1
125  * \return the frequency in Hz
126  */
127  virtual double get_center_freq(size_t chan = 0) = 0;
128 
129  /*!
130  * Get the tunable frequency range.
131  *
132  * \param chan the channel index 0 to N-1
133  * \return the frequency range in Hz
134  */
135  virtual ::uhd::freq_range_t get_freq_range(size_t chan = 0) = 0;
136 
137  /*!
138  * Set the gain for the selected channel.
139  *
140  * \param gain the gain in dB
141  * \param chan the channel index 0 to N-1
142  */
143  virtual void set_gain(double gain, size_t chan = 0) = 0;
144 
145  /*!
146  * Set the named gain on the dboard.
147  *
148  * \param gain the gain in dB
149  * \param name the name of the gain stage
150  * \param chan the channel index 0 to N-1
151  */
152  virtual void set_gain(double gain,
153  const std::string &name,
154  size_t chan = 0) = 0;
155 
156  /*!
157  * Set the normalized gain.
158  *
159  * The normalized gain is always in [0, 1], regardless of the device.
160  * 0 corresponds to minimum gain (usually 0 dB, but make sure to read the device
161  * notes in the UHD manual) and 1 corresponds to maximum gain.
162  * This will work for any UHD device. Use get_gain() to see which dB value
163  * the normalized gain value corresponds to.
164  *
165  * Note that it is not possible to specify a gain name for this function.
166  *
167  * \throws A runtime_error if \p norm_gain is not within the valid range.
168  *
169  * \param norm_gain the gain in fractions of the gain range (must be 0 <= norm_gain <= 1)
170  * \param chan the channel index 0 to N-1
171  */
172  virtual void set_normalized_gain(double norm_gain, size_t chan = 0) = 0;
173 
174  /*!
175  * Get the actual dboard gain setting.
176  *
177  * \param chan the channel index 0 to N-1
178  * \return the actual gain in dB
179  */
180  virtual double get_gain(size_t chan = 0) = 0;
181 
182  /*!
183  * Get the actual dboard gain setting of named stage.
184  *
185  * \param name the name of the gain stage
186  * \param chan the channel index 0 to N-1
187  * \return the actual gain in dB
188  */
189  virtual double get_gain(const std::string &name,
190  size_t chan = 0) = 0;
191 
192  /*!
193  * Returns the normalized gain.
194  *
195  * The normalized gain is always in [0, 1], regardless of the device.
196  * See also set_normalized_gain().
197  *
198  * Note that it is not possible to specify a gain name for
199  * this function, the result is over the entire gain chain.
200  *
201  * \param chan the channel index 0 to N-1
202  */
203  virtual double get_normalized_gain(size_t chan = 0) = 0;
204 
205  /*!
206  * Get the actual dboard gain setting of named stage.
207  *
208  * \param chan the channel index 0 to N-1
209  * \return the actual gain in dB
210  */
211  virtual std::vector<std::string> get_gain_names(size_t chan = 0) = 0;
212 
213  /*!
214  * Get the settable gain range.
215  *
216  * \param chan the channel index 0 to N-1
217  * \return the gain range in dB
218  */
219  virtual ::uhd::gain_range_t get_gain_range(size_t chan = 0) = 0;
220 
221  /*!
222  * Get the settable gain range.
223  *
224  * \param name the name of the gain stage
225  * \param chan the channel index 0 to N-1
226  * \return the gain range in dB
227  */
228  virtual ::uhd::gain_range_t get_gain_range(const std::string &name,
229  size_t chan = 0) = 0;
230 
231  /*!
232  * Set the antenna to use for a given channel.
233  *
234  * \param ant the antenna string
235  * \param chan the channel index 0 to N-1
236  */
237  virtual void set_antenna(const std::string &ant,
238  size_t chan = 0) = 0;
239 
240  /*!
241  * Get the antenna in use.
242  *
243  * \param chan the channel index 0 to N-1
244  * \return the antenna string
245  */
246  virtual std::string get_antenna(size_t chan = 0) = 0;
247 
248  /*!
249  * Get a list of possible antennas on a given channel.
250  *
251  * \param chan the channel index 0 to N-1
252  * \return a vector of antenna strings
253  */
254  virtual std::vector<std::string> get_antennas(size_t chan = 0) = 0;
255 
256  /*!
257  * Set the bandpass filter on the RF frontend.
258  *
259  * \param bandwidth the filter bandwidth in Hz
260  * \param chan the channel index 0 to N-1
261  */
262  virtual void set_bandwidth(double bandwidth, size_t chan = 0) = 0;
263 
264  /*!
265  * Get the bandpass filter setting on the RF frontend.
266  *
267  * \param chan the channel index 0 to N-1
268  * \return bandwidth of the filter in Hz
269  */
270  virtual double get_bandwidth(size_t chan = 0) = 0;
271 
272  /*!
273  * Get the bandpass filter range of the RF frontend.
274  *
275  * \param chan the channel index 0 to N-1
276  * \return the range of the filter bandwidth in Hz
277  */
278  virtual ::uhd::freq_range_t get_bandwidth_range(size_t chan = 0) = 0;
279 
280  /*!
281  * Get an RF frontend sensor value.
282  * \param name the name of the sensor
283  * \param chan the channel index 0 to N-1
284  * \return a sensor value object
285  */
286  virtual ::uhd::sensor_value_t get_sensor(const std::string &name,
287  size_t chan = 0) = 0;
288 
289  /*!
290  * Get a list of possible RF frontend sensor names.
291  * \param chan the channel index 0 to N-1
292  * \return a vector of sensor names
293  */
294  virtual std::vector<std::string> get_sensor_names(size_t chan = 0) = 0;
295 
296  //! DEPRECATED use get_sensor
297  ::uhd::sensor_value_t get_dboard_sensor(const std::string &name,
298  size_t chan = 0)
299  {
300  return this->get_sensor(name, chan);
301  }
302 
303  //! DEPRECATED use get_sensor_names
304  std::vector<std::string> get_dboard_sensor_names(size_t chan = 0)
305  {
306  return this->get_sensor_names(chan);
307  }
308 
309  /*!
310  * Get a motherboard sensor value.
311  *
312  * \param name the name of the sensor
313  * \param mboard the motherboard index 0 to M-1
314  * \return a sensor value object
315  */
316  virtual ::uhd::sensor_value_t get_mboard_sensor(const std::string &name,
317  size_t mboard = 0) = 0;
318 
319  /*!
320  * Get a list of possible motherboard sensor names.
321  *
322  * \param mboard the motherboard index 0 to M-1
323  * \return a vector of sensor names
324  */
325  virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
326 
327  /*!
328  * Get the currently set time source.
329  *
330  * \param mboard which motherboard to get the config
331  * \return the string representing the time source
332  */
333  virtual std::string get_time_source(const size_t mboard) = 0;
334 
335  /*!
336  * Get a list of possible time sources.
337  *
338  * \param mboard which motherboard to get the list
339  * \return a vector of strings for possible settings
340  */
341  virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;
342 
343  /*!
344  * Set the clock source for the usrp device.
345  *
346  * This sets the source for a 10 MHz reference clock.
347  * Typical options for source: internal, external, MIMO.
348  *
349  * \param source a string representing the clock source
350  * \param mboard which motherboard to set the config
351  */
352  virtual void set_clock_source(const std::string &source,
353  const size_t mboard = 0) = 0;
354 
355  /*!
356  * Get the currently set clock source.
357  *
358  * \param mboard which motherboard to get the config
359  * \return the string representing the clock source
360  */
361  virtual std::string get_clock_source(const size_t mboard) = 0;
362 
363  /*!
364  * Get a list of possible clock sources.
365  *
366  * \param mboard which motherboard to get the list
367  * \return a vector of strings for possible settings
368  */
369  virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;
370 
371  /*!
372  * Get the master clock rate.
373  *
374  * \param mboard the motherboard index 0 to M-1
375  * \return the clock rate in Hz
376  */
377  virtual double get_clock_rate(size_t mboard = 0) = 0;
378 
379  /*!
380  * Set the master clock rate.
381  *
382  * \param rate the new rate in Hz
383  * \param mboard the motherboard index 0 to M-1
384  */
385  virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
386 
387  /*!
388  * Get the current time registers.
389  *
390  * \param mboard the motherboard index 0 to M-1
391  * \return the current usrp time
392  */
393  virtual ::uhd::time_spec_t get_time_now(size_t mboard = 0) = 0;
394 
395  /*!
396  * Get the time when the last pps pulse occured.
397  * \param mboard the motherboard index 0 to M-1
398  * \return the current usrp time
399  */
400  virtual ::uhd::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
401 
402  /*!
403  * Sets the time registers immediately.
404  * \param time_spec the new time
405  * \param mboard the motherboard index 0 to M-1
406  */
407  virtual void set_time_now(const ::uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
408 
409  /*!
410  * Set the time registers at the next pps.
411  * \param time_spec the new time
412  */
413  virtual void set_time_next_pps(const ::uhd::time_spec_t &time_spec) = 0;
414 
415  /*!
416  * Sync the time registers with an unknown pps edge.
417  * \param time_spec the new time
418  */
419  virtual void set_time_unknown_pps(const ::uhd::time_spec_t &time_spec) = 0;
420 
421  /*!
422  * Set the time at which the control commands will take effect.
423  *
424  * A timed command will back-pressure all subsequent timed commands,
425  * assuming that the subsequent commands occur within the time-window.
426  * If the time spec is late, the command will be activated upon arrival.
427  *
428  * \param time_spec the time at which the next command will activate
429  * \param mboard which motherboard to set the config
430  */
431  virtual void set_command_time(const ::uhd::time_spec_t &time_spec,
432  size_t mboard = 0) = 0;
433 
434  /*!
435  * Clear the command time so future commands are sent ASAP.
436  *
437  * \param mboard which motherboard to set the config
438  */
439  virtual void clear_command_time(size_t mboard = 0) = 0;
440 
441  /*!
442  * Get access to the underlying uhd dboard iface object.
443  *
444  * \return the dboard_iface object
445  */
446  virtual ::uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan = 0) = 0;
447 
448  /*!
449  * Get access to the underlying uhd device object.
450  *
451  * NOTE: This function is only available in C++.
452  * \return the multi usrp device object
453  */
454  virtual ::uhd::usrp::multi_usrp::sptr get_device(void) = 0;
455 
456  /*!
457  * Perform write on the user configuration register bus. These
458  * only exist if the user has implemented custom setting
459  * registers in the device FPGA.
460  *
461  * \param addr 8-bit register address
462  * \param data 32-bit register value
463  * \param mboard which motherboard to set the user register
464  */
465  virtual void set_user_register(const uint8_t addr,
466  const uint32_t data,
467  size_t mboard = 0) = 0;
468 
469  /*!
470  * Set the clock configuration.
471  *
472  * DEPRECATED for set_time/clock_source.
473  * \param clock_config the new configuration
474  * \param mboard the motherboard index 0 to M-1
475  */
476  virtual void set_clock_config(const ::uhd::clock_config_t &clock_config,
477  size_t mboard = 0) = 0;
478 
479  /*!
480  * Set the time source for the USRP device.
481  *
482  * This sets the method of time synchronization,
483  * typically a pulse per second or an encoded time.
484  * Typical options for source: external, MIMO.
485  * \param source a string representing the time source
486  * \param mboard which motherboard to set the config
487  */
488  virtual void set_time_source(const std::string &source,
489  const size_t mboard = 0) = 0;
490 
491  /*!
492  * Update the stream args for this device.
493  *
494  * This update will only take effect after a restart of the
495  * streaming, or before streaming and after construction.
496  * This will also delete the current streamer.
497  * Note you cannot change the I/O signature of this block using
498  * this function, or it will throw.
499  *
500  * It is possible to leave the 'channels' fields of \p stream_args
501  * unset. In this case, the previous channels field is used.
502  *
503  * \param stream_args New stream args.
504  * \throws std::runtime_error if new settings are invalid.
505  */
506  virtual void set_stream_args(const ::uhd::stream_args_t &stream_args) = 0;
507 
508  /*******************************************************************
509  * GPIO methods
510  ******************************************************************/
511  /*!
512  * Enumerate GPIO banks on the current device.
513  * \param mboard the motherboard index 0 to M-1
514  * \return a list of string for each bank name
515  */
516  virtual std::vector<std::string> get_gpio_banks(const size_t mboard) = 0;
517 
518  /*!
519  * Set a GPIO attribute on a particular GPIO bank.
520  * Possible attribute names:
521  * - CTRL - 1 for ATR mode 0 for GPIO mode
522  * - DDR - 1 for output 0 for input
523  * - OUT - GPIO output level (not ATR mode)
524  * - ATR_0X - ATR idle state
525  * - ATR_RX - ATR receive only state
526  * - ATR_TX - ATR transmit only state
527  * - ATR_XX - ATR full duplex state
528  * \param bank the name of a GPIO bank
529  * \param attr the name of a GPIO attribute
530  * \param value the new value for this GPIO bank
531  * \param mask the bit mask to effect which pins are changed
532  * \param mboard the motherboard index 0 to M-1
533  */
534  virtual void set_gpio_attr(
535  const std::string &bank,
536  const std::string &attr,
537  const boost::uint32_t value,
538  const boost::uint32_t mask = 0xffffffff,
539  const size_t mboard = 0
540  ) = 0;
541 
542  /*!
543  * Get a GPIO attribute on a particular GPIO bank.
544  * Possible attribute names:
545  * - CTRL - 1 for ATR mode 0 for GPIO mode
546  * - DDR - 1 for output 0 for input
547  * - OUT - GPIO output level (not ATR mode)
548  * - ATR_0X - ATR idle state
549  * - ATR_RX - ATR receive only state
550  * - ATR_TX - ATR transmit only state
551  * - ATR_XX - ATR full duplex state
552  * - READBACK - readback input GPIOs
553  * \param bank the name of a GPIO bank
554  * \param attr the name of a GPIO attribute
555  * \param mboard the motherboard index 0 to M-1
556  * \return the value set for this attribute
557  */
558  virtual boost::uint32_t get_gpio_attr(
559  const std::string &bank,
560  const std::string &attr,
561  const size_t mboard = 0
562  ) = 0;
563 
564  };
565 
566  } /* namespace uhd */
567 } /* namespace gr */
568 
569 #endif /* INCLUDED_GR_UHD_USRP_BLOCK_H */
boost::shared_ptr< io_signature > sptr
Definition: io_signature.h:45
Definition: usrp_block.h:41
::uhd::tune_result_t set_center_freq(double freq, size_t chan=0)
Definition: usrp_block.h:116
Definition: usrp_sink.h:30
usrp_block()
Definition: usrp_block.h:44
Include this header to use the message passing features.
Definition: logger.h:131
synchronous 1:1 input to output with historyOverride work to provide the signal processing implementa...
Definition: sync_block.h:37
#define GR_UHD_API
Definition: gr-uhd/include/gnuradio/uhd/api.h:30
std::vector< std::string > get_dboard_sensor_names(size_t chan=0)
DEPRECATED use get_sensor_names.
Definition: usrp_block.h:304
::uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan=0)
DEPRECATED use get_sensor.
Definition: usrp_block.h:297