USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
UHD and USRP Manual
noc_block_base.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/property_tree.hpp>
11 #include <uhd/rfnoc/block_id.hpp>
12 #include <uhd/rfnoc/defaults.hpp>
13 #include <uhd/rfnoc/node.hpp>
17 
19 #define RFNOC_BLOCK_CONSTRUCTOR(CLASS_NAME) \
20  CLASS_NAME##_impl(make_args_ptr make_args) : CLASS_NAME(std::move(make_args))
21 
22 #define RFNOC_DECLARE_BLOCK(CLASS_NAME) \
23  using sptr = std::shared_ptr<CLASS_NAME>; \
24  CLASS_NAME(make_args_ptr make_args) : noc_block_base(std::move(make_args)) {}
25 
26 namespace uhd { namespace rfnoc {
27 
28 class clock_iface;
29 class mb_controller;
30 
43 {
44 public:
48  using sptr = std::shared_ptr<noc_block_base>;
49 
51  struct make_args_t;
52 
54  using make_args_ptr = std::unique_ptr<make_args_t>;
55 
56  ~noc_block_base() override;
57 
58  /**************************************************************************
59  * node_t API calls
60  *************************************************************************/
62  std::string get_unique_id() const override
63  {
64  return get_block_id().to_string();
65  }
66 
68  // information stored in the global register space.
69  //
70  // Note: This may be overridden by the block (e.g., the X300 radio may not
71  // have all ports available if no TwinRX board is plugged in), but the
72  // subclassed version may never report more ports than this.
73  size_t get_num_input_ports() const override
74  {
75  return _num_input_ports;
76  }
77 
79  // information stored in the global register space.
80  //
81  // Note: This may be overridden by the block (e.g., the X300 radio may not
82  // have all ports available if no TwinRX board is plugged in), but the
83  // subclassed version may never report more ports than this.
84  size_t get_num_output_ports() const override
85  {
86  return _num_output_ports;
87  }
88 
89  /**************************************************************************
90  * RFNoC-block specific API calls
91  *************************************************************************/
97  {
98  return _noc_id;
99  }
100 
105  const block_id_t& get_block_id() const
106  {
107  return _block_id;
108  }
109 
114  double get_tick_rate() const;
115 
132  size_t get_mtu(const res_source_info& edge);
133 
147  size_t get_chdr_hdr_len(const bool account_for_ts = true) const;
148 
176  size_t get_max_payload_size(
177  const res_source_info& edge, const bool account_for_ts = true);
178 
182  {
183  return _block_args;
184  }
185 
188  {
189  return _tree;
190  }
191 
194  {
195  return _tree;
196  }
197 
209  std::shared_ptr<mb_controller> get_mb_controller();
210 
211 protected:
212  noc_block_base(make_args_ptr make_args);
213 
215  //
216  // - The new number of ports may not exceed the old number. This can only
217  // be used to 'decrease' the number of ports.
218  // - This is considered an 'advanced' API and should rarely be called by
219  // blocks. See also get_num_output_ports().
220  //
221  // \throws uhd::value_error if \p num_ports is larger than the current
222  // number of ports.
223  void set_num_input_ports(const size_t num_ports);
224 
226  //
227  // - The new number of ports may not exceed the old number. This can only
228  // be used to 'decrease' the number of ports.
229  // - This is considered an 'advanced' API and should rarely be called by
230  // blocks. An example of where this is useful is the X310 radio block,
231  // which has 2 output ports, but only 1 is useful for UBX/SBX/WBX boards
232  // (i.e., boards with 1 frontend). In that case, software can make a
233  // determination to 'invalidate' one of the ports.
234  //
235  // \throws uhd::value_error if \p num_ports is larger than the current
236  // number of ports.
237  void set_num_output_ports(const size_t num_ports);
238 
244  void set_tick_rate(const double tick_rate);
245 
274  void set_mtu_forwarding_policy(const forwarding_policy_t policy);
275 
281  void set_mtu(const res_source_info& edge, const size_t new_mtu);
282 
292  property_base_t* get_mtu_prop_ref(const res_source_info& edge);
293 
311  virtual void deinit();
312 
313 private:
314  friend class block_initializer;
315 
321  void _set_tick_rate(const double tick_rate);
322 
328  void shutdown() override;
329 
337  void post_init();
338 
339  /**************************************************************************
340  * Attributes
341  **************************************************************************/
343  noc_id_t _noc_id;
344 
346  //
347  // The framework will guarantee that no one else has the same block ID
348  block_id_t _block_id;
349 
351  size_t _num_input_ports;
352 
354  size_t _num_output_ports;
355 
357  // for all in- and output edges.
358  std::vector<property_t<double>> _tick_rate_props;
359 
361  forwarding_policy_t _mtu_fwd_policy = forwarding_policy_t::ONE_TO_ONE;
362 
364  bool _mtu_fwd_policy_set = false;
365 
367  // for all in- and output edges.
368  std::vector<property_t<size_t>> _mtu_props;
369 
371  std::unordered_map<res_source_info, size_t> _mtu;
372 
374  chdr_w_t _chdr_w;
375 
377  std::shared_ptr<clock_iface> _ctrlport_clock_iface;
378 
380  std::shared_ptr<clock_iface> _tb_clock_iface;
381 
383  // block had requested and was granted access
384  std::shared_ptr<mb_controller> _mb_controller;
385 
387  const uhd::device_addr_t _block_args;
388 
390  //
391  // It is mutable because _tree->access<>(..).get() is not const, but we
392  // need to do just that in some const contexts
393  mutable uhd::property_tree::sptr _tree;
394 
395 }; // class noc_block_base
396 
397 }} /* namespace uhd::rfnoc */
398 
noc_block_make_args.hpp
uhd::rfnoc::noc_block_base::get_block_args
uhd::device_addr_t get_block_args() const
Definition: noc_block_base.hpp:181
uhd::rfnoc::res_source_info
Definition: res_source_info.hpp:17
uhd::rfnoc::noc_block_base::get_block_id
const block_id_t & get_block_id() const
Definition: noc_block_base.hpp:105
device_addr.hpp
uhd::rfnoc::block_id_t
Definition: block_id.hpp:39
uhd::rfnoc::register_iface_holder
Definition: register_iface_holder.hpp:18
config.hpp
uhd::rfnoc::noc_block_base
Definition: noc_block_base.hpp:42
node.hpp
property_tree.hpp
block_id.hpp
uhd::rfnoc::noc_block_base::make_args_t
Definition: noc_block_make_args.hpp:24
UHD_API
#define UHD_API
Definition: config.h:87
uhd::property_tree::sptr
std::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:222
uhd::rfnoc::noc_block_base::get_tree
uhd::property_tree::sptr & get_tree()
Return a reference to this block's subtree (non-const version)
Definition: noc_block_base.hpp:193
uhd::device_addr_t
Definition: device_addr.hpp:37
uhd::rfnoc::node_t
Definition: node.hpp:34
uhd::rfnoc::noc_block_base::get_unique_id
std::string get_unique_id() const override
Unique ID for an RFNoC block is its block ID.
Definition: noc_block_base.hpp:62
register_iface_holder.hpp
uhd::rfnoc::noc_block_base::get_num_output_ports
size_t get_num_output_ports() const override
Number of output ports. Note: This gets passed outto this block from the.
Definition: noc_block_base.hpp:84
uhd
Definition: build_info.hpp:12
uhd::rfnoc::noc_block_base::get_noc_id
noc_id_t get_noc_id() const
Definition: noc_block_base.hpp:96
uhd::rfnoc::node_t::forwarding_policy_t
forwarding_policy_t
Types of property/action forwarding for those not defined by the block itself.
Definition: node.hpp:46
rfnoc_types.hpp
uhd::rfnoc::noc_block_base::get_num_input_ports
size_t get_num_input_ports() const override
Number of input ports. Note: This gets passed into this block from the.
Definition: noc_block_base.hpp:73
uhd::rfnoc::property_base_t
Definition: property.hpp:25
uhd::rfnoc::noc_block_base::get_tree
uhd::property_tree::sptr & get_tree() const
Return a reference to this block's subtree.
Definition: noc_block_base.hpp:187
uhd::rfnoc::noc_block_base::sptr
std::shared_ptr< noc_block_base > sptr
Definition: noc_block_base.hpp:48
defaults.hpp
uhd::rfnoc::noc_id_t
uint32_t noc_id_t
Definition: defaults.hpp:50
uhd::rfnoc::noc_block_base::make_args_ptr
std::unique_ptr< make_args_t > make_args_ptr
Opaque pointer to the constructor arguments.
Definition: noc_block_base.hpp:54
uhd::rfnoc::chdr_w_t
chdr_w_t
Type that indicates the CHDR Width in bits.
Definition: rfnoc_types.hpp:19