USRP Hardware Driver and USRP Manual  Version: 4.7.0.0
UHD and USRP Manual
rfnoc_graph.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2019 Ettus Research, a National Instruments Brand
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #pragma once
8 
9 #include <uhd/config.hpp>
10 #include <uhd/rfnoc/block_id.hpp>
11 #include <uhd/rfnoc/graph_edge.hpp>
13 #include <uhd/stream.hpp>
16 #include <uhd/types/time_spec.hpp>
18 #include <boost/units/detail/utility.hpp> // for demangle
19 #include <memory>
20 #include <vector>
21 
22 namespace uhd { namespace rfnoc {
23 
24 class mb_controller;
25 
33  public std::enable_shared_from_this<rfnoc_graph>
34 {
35 public:
39  using sptr = std::shared_ptr<rfnoc_graph>;
40 
41  virtual ~rfnoc_graph() {}
42 
43  /******************************************
44  * Factory
45  ******************************************/
54  static sptr make(const device_addr_t& dev_addr);
55 
56  /******************************************
57  * Block Discovery/Retrieval
58  ******************************************/
78  virtual std::vector<block_id_t> find_blocks(
79  const std::string& block_id_hint) const = 0;
80 
83  template <typename T>
84  std::vector<block_id_t> find_blocks(const std::string& block_id_hint) const
85  {
86  std::vector<block_id_t> all_block_ids = find_blocks(block_id_hint);
87  std::vector<block_id_t> filt_block_ids;
88  for (size_t i = 0; i < all_block_ids.size(); i++) {
89  if (has_block<T>(all_block_ids[i])) {
90  filt_block_ids.push_back(all_block_ids[i]);
91  }
92  }
93  return filt_block_ids;
94  }
95 
102  virtual bool has_block(const block_id_t& block_id) const = 0;
103 
109  template <typename T>
110  bool has_block(const block_id_t& block_id) const
111  {
112  return has_block(block_id)
113  && bool(std::dynamic_pointer_cast<T>(get_block(block_id)));
114  }
115 
124  virtual noc_block_base::sptr get_block(const block_id_t& block_id) const = 0;
125 
140  template <typename T>
141  std::shared_ptr<T> get_block(const block_id_t& block_id) const
142  {
143  std::shared_ptr<T> blk = std::dynamic_pointer_cast<T>(get_block(block_id));
144  if (blk) {
145  return blk;
146  } else {
147  throw uhd::lookup_error(
148  std::string("This device does not have a block of type ")
149  + boost::units::detail::demangle(typeid(T).name())
150  + " with ID: " + block_id.to_string());
151  }
152  }
153 
154  /**************************************************************************
155  * Connection APIs
156  *************************************************************************/
165  virtual bool is_connectable(const block_id_t& src_blk,
166  size_t src_port,
167  const block_id_t& dst_blk,
168  size_t dst_port) = 0;
169 
189  virtual void connect(const block_id_t& src_blk,
190  size_t src_port,
191  const block_id_t& dst_blk,
192  size_t dst_port,
193  bool is_back_edge = false) = 0;
194 
206  virtual void connect(uhd::tx_streamer::sptr streamer,
207  size_t strm_port,
208  const block_id_t& dst_blk,
209  size_t dst_port,
210  uhd::transport::adapter_id_t adapter_id = uhd::transport::NULL_ADAPTER_ID) = 0;
211 
223  virtual void connect(const block_id_t& src_blk,
224  size_t src_port,
225  uhd::rx_streamer::sptr streamer,
226  size_t strm_port,
227  uhd::transport::adapter_id_t adapter_id = uhd::transport::NULL_ADAPTER_ID) = 0;
228 
242  virtual void disconnect(const block_id_t& src_blk,
243  size_t src_port,
244  const block_id_t& dst_blk,
245  size_t dst_port) = 0;
246 
256  virtual void disconnect(const std::string& streamer_id) = 0;
257 
268  virtual void disconnect(const std::string& streamer_id, size_t port) = 0;
269 
279  virtual std::vector<uhd::transport::adapter_id_t> enumerate_adapters_from_src(
280  const block_id_t& src_blk, size_t src_port) = 0;
281 
291  virtual std::vector<uhd::transport::adapter_id_t> enumerate_adapters_to_dst(
292  const block_id_t& dst_blk, size_t dst_port) = 0;
293 
303  virtual std::vector<graph_edge_t> enumerate_static_connections() const = 0;
304 
312  virtual std::vector<graph_edge_t> enumerate_active_connections() = 0;
313 
321  virtual void commit() = 0;
322 
328  virtual void release() = 0;
329 
336  virtual std::string to_dot() = 0;
337 
338  /******************************************
339  * Streaming
340  ******************************************/
341 
352  virtual rx_streamer::sptr create_rx_streamer(
353  const size_t num_ports, const stream_args_t& args) = 0;
354 
365  virtual tx_streamer::sptr create_tx_streamer(
366  const size_t num_ports, const stream_args_t& args) = 0;
367 
368  /**************************************************************************
369  * Hardware Control
370  *************************************************************************/
378  virtual size_t get_num_mboards() const = 0;
379 
389  virtual std::shared_ptr<mb_controller> get_mb_controller(
390  const size_t mb_index = 0) = 0;
391 
426  virtual bool synchronize_devices(
427  const uhd::time_spec_t& time_spec, const bool quiet) = 0;
428 
430  virtual uhd::property_tree::sptr get_tree(void) const = 0;
431 }; // class rfnoc_graph
432 
433 }}; // namespace uhd::rfnoc
std::shared_ptr< rx_streamer > sptr
Definition: stream.hpp:169
bool has_block(const block_id_t &block_id) const
Definition: rfnoc_graph.hpp:110
std::string to_string() const
Return a string like this: "0/FFT#1" (includes all components, if set)
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
Definition: exception.hpp:58
Definition: time_spec.hpp:28
std::shared_ptr< T > get_block(const block_id_t &block_id) const
Definition: rfnoc_graph.hpp:141
size_t adapter_id_t
Host transport adapter ID.
Definition: adapter_id.hpp:17
Definition: block_id.hpp:39
std::shared_ptr< rfnoc_graph > sptr
Definition: rfnoc_graph.hpp:39
Definition: build_info.hpp:12
Definition: rfnoc_graph.hpp:32
Definition: stream.hpp:47
std::shared_ptr< noc_block_base > sptr
Definition: noc_block_base.hpp:48
#define UHD_API
Definition: config.h:87
string release
Definition: conf.py:29
std::shared_ptr< tx_streamer > sptr
Definition: stream.hpp:267
virtual ~rfnoc_graph()
Definition: rfnoc_graph.hpp:41
std::vector< block_id_t > find_blocks(const std::string &block_id_hint) const
Definition: rfnoc_graph.hpp:84
std::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:223
Definition: device_addr.hpp:37