USRP Hardware Driver and USRP Manual  Version: 3.13.1.0-3
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/stream.hpp>
13 #include <uhd/types/sid.hpp>
14 #include <uhd/types/stream_cmd.hpp>
15 #include <uhd/types/wb_iface.hpp>
16 #include <uhd/utils/static.hpp>
18 #include <uhd/rfnoc/block_id.hpp>
19 #include <uhd/rfnoc/stream_sig.hpp>
20 #include <uhd/rfnoc/blockdef.hpp>
21 #include <uhd/rfnoc/constants.hpp>
22 #include <boost/shared_ptr.hpp>
23 #include <stdint.h>
24 
25 namespace uhd {
26  namespace rfnoc {
27  // Forward declarations
28  class ctrl_iface;
29  namespace nocscript {
30  class block_iface;
31  }
32 
33 
34 // TODO: Move this out of public section
36 {
37  make_args_t(const std::string &key="") :
38  device_index(0),
39  block_name(""),
40  block_key(key)
41  {}
42 
44  std::map<size_t, boost::shared_ptr<ctrl_iface> > ctrl_ifaces;
46  uint32_t base_address;
48  size_t device_index;
50  // property tree is /mboards/0, pass a subtree starting at /mboards/0
51  // to the constructor.
54  std::string block_name;
56  std::string block_key;
57 };
58 
60 // block class
61 #define UHD_RFNOC_BLOCK_OBJECT(class_name) \
62  typedef boost::shared_ptr< class_name > sptr;
63 
65 #define UHD_RFNOC_BLOCK_CONSTRUCTOR(CLASS_NAME) \
66  CLASS_NAME##_impl( \
67  const make_args_t &make_args \
68  ) : block_ctrl_base(make_args)
69 
71 // after the class definition
72 #define UHD_RFNOC_BLOCK_REGISTER(CLASS_NAME, BLOCK_NAME) \
73  block_ctrl_base::sptr CLASS_NAME##_make( \
74  const make_args_t &make_args \
75  ) { \
76  return block_ctrl_base::sptr(new CLASS_NAME##_impl(make_args)); \
77  } \
78  UHD_STATIC_BLOCK(register_rfnoc_##CLASS_NAME) \
79  { \
80  uhd::rfnoc::block_ctrl_base::register_block(&CLASS_NAME##_make, BLOCK_NAME); \
81  }
82 
93 class block_ctrl_base : virtual public node_ctrl_base
94 {
95 public:
96  /***********************************************************************
97  * Types
98  **********************************************************************/
99  typedef boost::shared_ptr<block_ctrl_base> sptr;
100  typedef boost::function<sptr(const make_args_t &)> make_t;
101 
102  /***********************************************************************
103  * Factory functions
104  **********************************************************************/
105 
116  static void register_block(const make_t &make, const std::string &name);
117 
132  static sptr make(const make_args_t &make_args, uint64_t noc_id = ~0);
133 
134  /***********************************************************************
135  * Block Communication and Control
136  *
137  * These functions do not require communication with the FPGA.
138  **********************************************************************/
139 
142  uint32_t get_address(size_t block_port=0);
143 
146  block_id_t get_block_id() const { return _block_id; };
147 
150  std::string unique_id() const { return _block_id.to_string(); };
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 
250  uint32_t user_reg_read32(const std::string &reg, const size_t port = 0);
251 
252 
258  void set_command_time(const time_spec_t &time_spec, const size_t port = ANY_PORT);
259 
264  time_spec_t get_command_time(const size_t port = 0);
265 
271  void set_command_tick_rate(const double tick_rate, const size_t port = ANY_PORT);
272 
280  void clear_command_time(const size_t port);
281 
300  void clear();
301 
302  /***********************************************************************
303  * Argument handling
304  **********************************************************************/
310  void set_args(const uhd::device_addr_t &args, const size_t port = 0);
311 
313  // data type using by looking up its type in the block definition.
314  void set_arg(const std::string &key, const std::string &val, const size_t port = 0);
315 
317  template <typename T>
318  void set_arg(const std::string &key, const T &val, const size_t port = 0) {
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  return _tree->access<T>(get_arg_path(key, port) / "value").get();
332  }
333 
334  std::string get_arg_type(const std::string &key, const size_t port = 0) const;
335 
336 protected:
337  /***********************************************************************
338  * Structors
339  **********************************************************************/
340  block_ctrl_base(void) {}; // To allow pure virtual (interface) sub-classes
341  virtual ~block_ctrl_base();
342 
350  const make_args_t &make_args
351  );
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  return _root_path / "args" / port / key;
361  };
362 
364  timed_wb_iface::sptr get_ctrl_iface(const size_t block_port);
365 
366  /***********************************************************************
367  * Hooks & Derivables
368  **********************************************************************/
369 
371  // than reset register SR_CLEAR_TX_FC.
372  virtual void _clear(const size_t port = 0);
373 
375  // setting the command time
376  virtual void _set_command_time(const time_spec_t &time_spec, const size_t port = ANY_PORT);
377  /***********************************************************************
378  * Protected members
379  **********************************************************************/
380 
383 
386 
389 
390 private:
392  void _init_port_defs(
393  const std::string &direction,
394  blockdef::ports_t ports,
395  const size_t first_port_index=0
396  );
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 */
437 // vim: sw=4 et:
uhd::property_tree::sptr _tree
Property sub-tree.
Definition: block_ctrl_base.hpp:382
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:318
std::string block_name
The name of the block as it will be addressed.
Definition: block_ctrl_base.hpp:54
Definition: property_tree.hpp:194
make_args_t(const std::string &key="")
Definition: block_ctrl_base.hpp:37
Definition: time_spec.hpp:28
blockdef::sptr _block_def
Block definition (stores info about the block such as ports)
Definition: block_ctrl_base.hpp:388
uint32_t base_address
This block&#39;s base address (address of block port 0)
Definition: block_ctrl_base.hpp:46
Definition: block_ctrl_base.hpp:93
boost::function< sptr(const make_args_t &)> make_t
Definition: block_ctrl_base.hpp:100
uhd::fs_path _root_path
Root node of this block&#39;s properties.
Definition: block_ctrl_base.hpp:385
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:44
settingsbus_reg_t
Settings register readback.
Definition: constants.hpp:69
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:210
block_id_t get_block_id() const
Definition: block_ctrl_base.hpp:146
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:14
std::string unique_id() const
Definition: block_ctrl_base.hpp:150
class UHD_RFNOC_API block_ctrl_base
Base class for all RFNoC block controller objects.
Definition: block_ctrl_base.hpp:92
std::string block_key
The key of the block, i.e. how it was registered.
Definition: block_ctrl_base.hpp:56
#define UHD_RFNOC_API
Definition: config.hpp:98
Definition: block_ctrl_base.hpp:35
uhd::property_tree::sptr tree
A property tree for this motherboard. Example: If the root a device&#39;s.
Definition: block_ctrl_base.hpp:52
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:99
boost::shared_ptr< blockdef > sptr
Definition: blockdef.hpp:25
block_ctrl_base(void)
Definition: block_ctrl_base.hpp:340
boost::shared_ptr< timed_wb_iface > sptr
Definition: wb_iface.hpp:73
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:51
Definition: device_addr.hpp:38
size_t device_index
The device index (or motherboard index).
Definition: block_ctrl_base.hpp:48
Definition: node_ctrl_base.hpp:31