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