USRP Hardware Driver and USRP Manual  Version: 3.15.0.0-2+b1
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 
140  block_id_t get_block_id() const
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::rfnoc::block_ctrl_base::user_reg_read64
uint64_t user_reg_read64(const uint32_t addr, const size_t port=0)
uhd::rfnoc::block_ctrl_base::get_args
uhd::device_addr_t get_args(const size_t port=0) const
Return all block arguments as a device_addr_t.
uhd::timed_wb_iface::sptr
boost::shared_ptr< timed_wb_iface > sptr
Definition: wb_iface.hpp:72
uhd::rfnoc::settingsbus_reg_t
settingsbus_reg_t
Settings register readback.
Definition: constants.hpp:69
blockdef.hpp
uhd::rfnoc::make_args_t::base_address
uint32_t base_address
This block's base address (address of block port 0)
Definition: block_ctrl_base.hpp:44
uhd::rfnoc::block_ctrl_base::sr_read32
uint32_t sr_read32(const settingsbus_reg_t reg, const size_t port=0)
uhd::rfnoc::block_ctrl_base::_resolve_port_def
stream_sig_t _resolve_port_def(const blockdef::port_t &port_def) const
uhd::rfnoc::block_ctrl_base::unique_id
std::string unique_id() const
Definition: block_ctrl_base.hpp:144
uhd::rfnoc::block_ctrl_base::_block_def
blockdef::sptr _block_def
Block definition (stores info about the block such as ports)
Definition: block_ctrl_base.hpp:381
uhd::rfnoc::block_id_t
Definition: block_id.hpp:39
uhd::rfnoc::make_args_t::tree
uhd::property_tree::sptr tree
A property tree for this motherboard. Example: If the root a device's.
Definition: block_ctrl_base.hpp:50
uhd::rfnoc::make_args_t::ctrl_ifaces
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
stream_sig.hpp
uhd::rfnoc::make_args_t
Definition: block_ctrl_base.hpp:34
property_tree.hpp
uhd::rfnoc::block_ctrl_base::get_command_time
time_spec_t get_command_time(const size_t port=0)
uhd::rfnoc::blockdef::sptr
boost::shared_ptr< blockdef > sptr
Definition: blockdef.hpp:25
uhd::rfnoc::block_ctrl_base::set_command_time
void set_command_time(const time_spec_t &time_spec, const size_t port=ANY_PORT)
block_id.hpp
uhd::rfnoc::make_args_t::make_args_t
make_args_t(const std::string &key="")
Definition: block_ctrl_base.hpp:36
uhd::rfnoc::block_ctrl_base::get_ctrl_ports
std::vector< size_t > get_ctrl_ports() const
uhd::rfnoc::block_ctrl_base
Definition: block_ctrl_base.hpp:87
uhd::rfnoc::make_args_t::block_name
std::string block_name
The name of the block as it will be addressed.
Definition: block_ctrl_base.hpp:52
uhd::rfnoc::block_ctrl_base::get_ctrl_iface
timed_wb_iface::sptr get_ctrl_iface(const size_t block_port)
Get a control interface object for block port block_port.
UHD_RFNOC_API
#define UHD_RFNOC_API
Definition: config.hpp:117
uhd::rfnoc::block_ctrl_base::register_block
static void register_block(const make_t &make, const std::string &name)
node_ctrl_base.hpp
uhd::rfnoc::block_id_t::to_string
std::string to_string() const
Return a string like this: "0/FFT_1" (includes all components, if set)
uhd::rfnoc::node_ctrl_base
Definition: node_ctrl_base.hpp:37
uhd::rfnoc::block_ctrl_base::user_reg_read32
uint32_t user_reg_read32(const uint32_t addr, const size_t port=0)
uhd::rfnoc::block_ctrl_base::~block_ctrl_base
virtual ~block_ctrl_base()
uhd::rfnoc::make_args_t::block_key
std::string block_key
The key of the block, i.e. how it was registered.
Definition: block_ctrl_base.hpp:54
uhd::rfnoc::block_ctrl_base::make
static sptr make(const make_args_t &make_args, uint64_t noc_id=~0)
Create a block controller class given a NoC-ID or a block name.
uhd::rfnoc::block_ctrl_base::_set_command_time
virtual void _set_command_time(const time_spec_t &time_spec, const size_t port=ANY_PORT)
Override this function if your block needs to specially handle.
uhd::rfnoc::block_ctrl_base::clear_command_time
void clear_command_time(const size_t port)
uhd::rfnoc::blockdef::port_t
Describes port options for a block definition.
Definition: blockdef.hpp:34
uhd::rfnoc::block_ctrl_base::sptr
boost::shared_ptr< block_ctrl_base > sptr
Definition: block_ctrl_base.hpp:92
stream_cmd.hpp
uhd::device_addr_t
Definition: device_addr.hpp:38
uhd::rfnoc::block_ctrl_base::sr_read64
uint64_t sr_read64(const settingsbus_reg_t reg, const size_t port=0)
uhd::property_tree::sptr
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:217
uhd::rfnoc::block_ctrl_base::clear
void clear()
uhd::rfnoc::block_ctrl_base::sr_write
void sr_write(const uint32_t reg, const uint32_t data, const size_t port=0)
uhd::rfnoc::block_ctrl_base::set_arg
void set_arg(const std::string &key, const std::string &val, const size_t port=0)
Set a specific block argument. val is converted to the corresponding.
uhd
Definition: build_info.hpp:13
uhd::rfnoc::make_args_t::device_index
size_t device_index
The device index (or motherboard index).
Definition: block_ctrl_base.hpp:46
uhd::time_spec_t
Definition: time_spec.hpp:29
uhd::rfnoc::block_ctrl_base::block_ctrl_base
block_ctrl_base(void)
Definition: block_ctrl_base.hpp:335
constants.hpp
uhd::fs_path
Definition: property_tree.hpp:199
uhd::rfnoc::block_ctrl_base::_clear
virtual void _clear(const size_t port=0)
Override this function if your block does something else.
uhd::rfnoc::block_ctrl_base::_tree
uhd::property_tree::sptr _tree
Property sub-tree.
Definition: block_ctrl_base.hpp:375
uhd::rfnoc::block_ctrl_base::get_block_id
block_id_t get_block_id() const
Definition: block_ctrl_base.hpp:137
uhd::rfnoc::block_ctrl_base::_root_path
uhd::fs_path _root_path
Root node of this block's properties.
Definition: block_ctrl_base.hpp:378
uhd::rfnoc::block_ctrl_base::get_arg_type
std::string get_arg_type(const std::string &key, const size_t port=0) const
uhd::rfnoc::block_ctrl_base::make_t
boost::function< sptr(const make_args_t &)> make_t
Definition: block_ctrl_base.hpp:93
uhd::rfnoc::block_ctrl_base::get_arg_path
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:352
uhd::rfnoc::block_ctrl_base::set_command_tick_rate
void set_command_tick_rate(const double tick_rate, const size_t port=ANY_PORT)
static.hpp
wb_iface.hpp
uhd::rfnoc::stream_sig_t
Definition: stream_sig.hpp:23
stream.hpp
uhd::rfnoc::block_ctrl_base::get_arg
std::string get_arg(const std::string &key, const size_t port=0) const
Return a single block argument in string format.
uhd::rfnoc::block_ctrl_base::get_address
uint32_t get_address(size_t block_port=0)
sid.hpp
uhd::rfnoc::blockdef::ports_t
std::vector< port_t > ports_t
Definition: blockdef.hpp:52
uhd::rfnoc::block_ctrl_base::set_args
void set_args(const uhd::device_addr_t &args, const size_t port=0)