USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-gaea0e2de
UHD and USRP Manual
block_ctrl_base.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 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #ifndef INCLUDED_LIBUHD_BLOCK_CTRL_BASE_HPP
9 #define INCLUDED_LIBUHD_BLOCK_CTRL_BASE_HPP
10 
11 #include <uhd/property_tree.hpp>
12 #include <uhd/rfnoc/block_id.hpp>
13 #include <uhd/rfnoc/blockdef.hpp>
14 #include <uhd/rfnoc/constants.hpp>
16 #include <uhd/rfnoc/stream_sig.hpp>
17 #include <uhd/stream.hpp>
18 #include <uhd/types/sid.hpp>
19 #include <uhd/types/stream_cmd.hpp>
20 #include <uhd/types/wb_iface.hpp>
21 #include <uhd/utils/static.hpp>
22 #include <stdint.h>
23 #include <boost/shared_ptr.hpp>
24 
25 namespace uhd { namespace rfnoc {
26 // Forward declarations
27 class ctrl_iface;
28 namespace nocscript {
29 class block_iface;
30 }
31 
32 
33 // TODO: Move this out of public section
35 {
36  make_args_t(const std::string& key = "")
37  : device_index(0), block_name(""), block_key(key)
38  {
39  }
40 
42  std::map<size_t, boost::shared_ptr<ctrl_iface> > ctrl_ifaces;
44  uint32_t base_address;
46  size_t device_index;
48  // property tree is /mboards/0, pass a subtree starting at /mboards/0
49  // to the constructor.
52  std::string block_name;
54  std::string block_key;
55 };
56 
58 // block class
59 #define UHD_RFNOC_BLOCK_OBJECT(class_name) typedef boost::shared_ptr<class_name> sptr;
60 
62 #define UHD_RFNOC_BLOCK_CONSTRUCTOR(CLASS_NAME) \
63  CLASS_NAME##_impl(const make_args_t& make_args) : block_ctrl_base(make_args)
64 
66 // after the class definition
67 #define UHD_RFNOC_BLOCK_REGISTER(CLASS_NAME, BLOCK_NAME) \
68  block_ctrl_base::sptr CLASS_NAME##_make(const make_args_t& make_args) \
69  { \
70  return block_ctrl_base::sptr(new CLASS_NAME##_impl(make_args)); \
71  } \
72  UHD_STATIC_BLOCK(register_rfnoc_##CLASS_NAME) \
73  { \
74  uhd::rfnoc::block_ctrl_base::register_block(&CLASS_NAME##_make, BLOCK_NAME); \
75  }
76 
87 class block_ctrl_base : virtual public node_ctrl_base
88 {
89 public:
90  /***********************************************************************
91  * Types
92  **********************************************************************/
93  typedef boost::shared_ptr<block_ctrl_base> sptr;
94  typedef boost::function<sptr(const make_args_t&)> make_t;
95 
96  /***********************************************************************
97  * Factory functions
98  **********************************************************************/
99 
110  static void register_block(const make_t& make, const std::string& name);
111 
126  static sptr make(const make_args_t& make_args, uint64_t noc_id = ~0);
127 
128  /***********************************************************************
129  * Block Communication and Control
130  *
131  * These functions do not require communication with the FPGA.
132  **********************************************************************/
133 
136  uint32_t get_address(size_t block_port = 0);
137 
141  {
142  return _block_id;
143  };
144 
147  std::string unique_id() const
148  {
149  return _block_id.to_string();
150  };
151 
152  /***********************************************************************
153  * FPGA control & communication
154  **********************************************************************/
155 
158  std::vector<size_t> get_ctrl_ports() const;
159 
169  void sr_write(const uint32_t reg, const uint32_t data, const size_t port = 0);
170 
181  void sr_write(const std::string& reg, const uint32_t data, const size_t port = 0);
182 
190  uint64_t sr_read64(const settingsbus_reg_t reg, const size_t port = 0);
191 
199  uint32_t sr_read32(const settingsbus_reg_t reg, const size_t port = 0);
200 
211  uint64_t user_reg_read64(const uint32_t addr, const size_t port = 0);
212 
224  uint64_t user_reg_read64(const std::string& reg, const size_t port = 0);
225 
236  uint32_t user_reg_read32(const uint32_t addr, const size_t port = 0);
237 
249  uint32_t user_reg_read32(const std::string& reg, const size_t port = 0);
250 
251 
257  void set_command_time(const time_spec_t& time_spec, const size_t port = ANY_PORT);
258 
263  time_spec_t get_command_time(const size_t port = 0);
264 
270  void set_command_tick_rate(const double tick_rate, const size_t port = ANY_PORT);
271 
279  void clear_command_time(const size_t port);
280 
299  void clear();
300 
301  /***********************************************************************
302  * Argument handling
303  **********************************************************************/
309  void set_args(const uhd::device_addr_t& args, const size_t port = 0);
310 
312  // data type using by looking up its type in the block definition.
313  void set_arg(const std::string& key, const std::string& val, const size_t port = 0);
314 
316  template <typename T>
317  void set_arg(const std::string& key, const T& val, const size_t port = 0)
318  {
319  _tree->access<T>(get_arg_path(key, port) / "value").set(val);
320  }
321 
323  uhd::device_addr_t get_args(const size_t port = 0) const;
324 
326  std::string get_arg(const std::string& key, const size_t port = 0) const;
327 
329  template <typename T>
330  T get_arg(const std::string& key, const size_t port = 0) const
331  {
332  return _tree->access<T>(get_arg_path(key, port) / "value").get();
333  }
334 
335  std::string get_arg_type(const std::string& key, const size_t port = 0) const;
336 
337 protected:
338  /***********************************************************************
339  * Structors
340  **********************************************************************/
341  block_ctrl_base(void){}; // To allow pure virtual (interface) sub-classes
342  virtual ~block_ctrl_base();
343 
351  block_ctrl_base(const make_args_t& make_args);
352 
353  /***********************************************************************
354  * Helpers
355  **********************************************************************/
356  stream_sig_t _resolve_port_def(const blockdef::port_t& port_def) const;
357 
359  uhd::fs_path get_arg_path(const std::string& key, size_t port = 0) const
360  {
361  return _root_path / "args" / port / key;
362  };
363 
365  timed_wb_iface::sptr get_ctrl_iface(const size_t block_port);
366 
367  /***********************************************************************
368  * Hooks & Derivables
369  **********************************************************************/
370 
372  // than reset register SR_CLEAR_TX_FC.
373  virtual void _clear(const size_t port = 0);
374 
376  // setting the command time
377  virtual void _set_command_time(
378  const time_spec_t& time_spec, const size_t port = ANY_PORT);
379  /***********************************************************************
380  * Protected members
381  **********************************************************************/
382 
385 
388 
391 
392 private:
394  void _init_port_defs(const std::string& direction,
395  blockdef::ports_t ports,
396  const size_t first_port_index = 0);
397 
399  void _init_block_args();
400 
402  double get_command_tick_rate(const size_t port);
403 
405  void _start_drain(const size_t port = 0);
406 
408  bool _flush(const size_t port = 0);
409 
410  /***********************************************************************
411  * Private members
412  **********************************************************************/
414  std::map<size_t, boost::shared_ptr<ctrl_iface> > _ctrl_ifaces;
415  std::map<size_t, time_spec_t> _cmd_timespecs;
416  std::map<size_t, double> _cmd_tickrates;
417 
419  uint32_t _base_address;
420 
422  uint64_t _noc_id;
423 
425  uint64_t _compat_num;
426 
428  block_id_t _block_id;
429 
431  boost::shared_ptr<nocscript::block_iface> _nocscript_iface;
432 }; /* class block_ctrl_base */
433 
434 }} /* namespace uhd::rfnoc */
435 
436 #endif /* INCLUDED_LIBUHD_BLOCK_CTRL_BASE_HPP */
uhd::property_tree::sptr _tree
Property sub-tree.
Definition: block_ctrl_base.hpp:384
void set_arg(const std::string &key, const T &val, const size_t port=0)
Direct access to set a block argument.
Definition: block_ctrl_base.hpp:317
std::string block_name
The name of the block as it will be addressed.
Definition: block_ctrl_base.hpp:52
Definition: property_tree.hpp:199
make_args_t(const std::string &key="")
Definition: block_ctrl_base.hpp:36
Definition: time_spec.hpp:29
blockdef::sptr _block_def
Block definition (stores info about the block such as ports)
Definition: block_ctrl_base.hpp:390
uint32_t base_address
This block&#39;s base address (address of block port 0)
Definition: block_ctrl_base.hpp:44
Definition: block_ctrl_base.hpp:87
uhd::fs_path _root_path
Root node of this block&#39;s properties.
Definition: block_ctrl_base.hpp:387
std::map< size_t, boost::shared_ptr< ctrl_iface > > ctrl_ifaces
A valid interface that allows us to read and write registers.
Definition: block_ctrl_base.hpp:42
settingsbus_reg_t
Settings register readback.
Definition: constants.hpp:68
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:217
block_id_t get_block_id() const
Definition: block_ctrl_base.hpp:140
Definition: block_id.hpp:39
uhd::fs_path get_arg_path(const std::string &key, size_t port=0) const
Return the property tree path to a block argument key on port.
Definition: block_ctrl_base.hpp:359
Definition: build_info.hpp:13
std::string unique_id() const
Definition: block_ctrl_base.hpp:147
class UHD_RFNOC_API block_ctrl_base
Base class for all RFNoC block controller objects.
Definition: block_ctrl_base.hpp:86
std::string block_key
The key of the block, i.e. how it was registered.
Definition: block_ctrl_base.hpp:54
#define UHD_RFNOC_API
Definition: config.hpp:117
Definition: block_ctrl_base.hpp:34
uhd::property_tree::sptr tree
A property tree for this motherboard. Example: If the root a device&#39;s.
Definition: block_ctrl_base.hpp:50
T get_arg(const std::string &key, const size_t port=0) const
Direct access to get a block argument.
Definition: block_ctrl_base.hpp:330
boost::shared_ptr< block_ctrl_base > sptr
Definition: block_ctrl_base.hpp:93
boost::shared_ptr< blockdef > sptr
Definition: blockdef.hpp:25
block_ctrl_base(void)
Definition: block_ctrl_base.hpp:341
boost::shared_ptr< timed_wb_iface > sptr
Definition: wb_iface.hpp:72
boost::function< sptr(const make_args_t &)> make_t
Definition: block_ctrl_base.hpp:94
Describes port options for a block definition.
Definition: blockdef.hpp:34
Definition: stream_sig.hpp:23
std::vector< port_t > ports_t
Definition: blockdef.hpp:52
Definition: device_addr.hpp:38
size_t device_index
The device index (or motherboard index).
Definition: block_ctrl_base.hpp:46
Definition: node_ctrl_base.hpp:37