USRP Hardware Driver and USRP Manual  Version: 3.15.0.0-4+b1satnogs1
UHD and USRP Manual
device3.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 // Copyright 2018 Ettus Research, a National Instruments Company
4 // Copyright 2019 Ettus Research, a National Instruments Brand
5 //
6 // SPDX-License-Identifier: GPL-3.0-or-later
7 //
8 
9 #ifndef INCLUDED_UHD_DEVICE3_HPP
10 #define INCLUDED_UHD_DEVICE3_HPP
11 
12 #include <uhd/device.hpp>
14 #include <uhd/rfnoc/graph.hpp>
15 #include <boost/core/demangle.hpp>
16 #include <boost/thread/mutex.hpp>
17 #include <vector>
18 
19 namespace uhd {
20 
28 class UHD_API device3 : public uhd::device
29 {
30 public:
31  typedef boost::shared_ptr<device3> sptr;
32 
34  static sptr make(const device_addr_t& hint, const size_t which = 0);
35 
36  virtual rfnoc::graph::sptr create_graph(const std::string& name = "") = 0;
37 
42  void clear();
43 
50  bool has_block(const rfnoc::block_id_t& block_id) const;
51 
57  template <typename T>
58  bool has_block(const rfnoc::block_id_t& block_id) const
59  {
60  if (has_block(block_id)) {
61  return bool(boost::dynamic_pointer_cast<T>(get_block_ctrl(block_id)));
62  } else {
63  return false;
64  }
65  }
66 
76 
92  template <typename T>
93  boost::shared_ptr<T> get_block_ctrl(const rfnoc::block_id_t& block_id) const
94  {
95  boost::shared_ptr<T> blk =
96  boost::dynamic_pointer_cast<T>(get_block_ctrl(block_id));
97  if (blk) {
98  return blk;
99  } else {
100  throw uhd::lookup_error(str(
101  boost::format("This device does not have a block of type %s with ID: %s")
102  % boost::core::demangle(typeid(T).name()) % block_id.to_string()));
103  }
104  }
105 
129  std::vector<rfnoc::block_id_t> find_blocks(const std::string& block_id_hint) const;
130 
133  template <typename T>
134  std::vector<rfnoc::block_id_t> find_blocks(const std::string& block_id_hint) const
135  {
136  std::vector<rfnoc::block_id_t> all_block_ids = find_blocks(block_id_hint);
137  std::vector<rfnoc::block_id_t> filt_block_ids;
138  for (size_t i = 0; i < all_block_ids.size(); i++) {
139  if (has_block<T>(all_block_ids[i])) {
140  filt_block_ids.push_back(all_block_ids[i]);
141  }
142  }
143  return filt_block_ids;
144  }
145 
146 protected:
148  // It is the responsibility of the deriving class to make
149  // sure this gets correctly populated.
150  std::vector<rfnoc::block_ctrl_base::sptr> _rfnoc_block_ctrl;
152  boost::mutex _block_ctrl_mutex;
153 };
154 
155 } // namespace uhd
156 
157 #endif /* INCLUDED_UHD_DEVICE3_HPP */
Extends uhd::device for third-generation USRP devices.
Definition: device3.hpp:29
boost::mutex _block_ctrl_mutex
Mutex to protect access to members.
Definition: device3.hpp:152
std::vector< rfnoc::block_id_t > find_blocks(const std::string &block_id_hint) const
std::vector< rfnoc::block_id_t > find_blocks(const std::string &block_id_hint) const
Definition: device3.hpp:134
std::vector< rfnoc::block_ctrl_base::sptr > _rfnoc_block_ctrl
List of all RFNoC blocks available on this device.
Definition: device3.hpp:150
boost::shared_ptr< device3 > sptr
Definition: device3.hpp:31
virtual rfnoc::graph::sptr create_graph(const std::string &name="")=0
rfnoc::block_ctrl_base::sptr get_block_ctrl(const rfnoc::block_id_t &block_id) const
Returns a block controller class for an RFNoC block.
static sptr make(const device_addr_t &hint, const size_t which=0)
Same as uhd::device::make(), but will fail if not actually a device3.
boost::shared_ptr< T > get_block_ctrl(const rfnoc::block_id_t &block_id) const
Definition: device3.hpp:93
bool has_block(const rfnoc::block_id_t &block_id) const
Checks if an RFNoC block exists on the device.
bool has_block(const rfnoc::block_id_t &block_id) const
Definition: device3.hpp:58
Definition: device_addr.hpp:39
Definition: device.hpp:29
boost::shared_ptr< device > sptr
Definition: device.hpp:31
boost::shared_ptr< block_ctrl_base > sptr
Definition: block_ctrl_base.hpp:93
Definition: block_id.hpp:40
std::string to_string() const
Return a string like this: "0/FFT_1" (includes all components, if set)
boost::shared_ptr< uhd::rfnoc::graph > sptr
Definition: graph.hpp:20
#define UHD_API
Definition: config.h:68
Definition: build_info.hpp:13
Definition: exception.hpp:61