USRP Hardware Driver and USRP Manual  Version: 003.010.000.HEAD-0-g6e1ac3fc
UHD and USRP Manual
block_ctrl_base.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_LIBUHD_BLOCK_CTRL_BASE_HPP
19 #define INCLUDED_LIBUHD_BLOCK_CTRL_BASE_HPP
20 
21 #include <uhd/property_tree.hpp>
22 #include <uhd/stream.hpp>
23 #include <uhd/types/sid.hpp>
24 #include <uhd/types/stream_cmd.hpp>
25 #include <uhd/types/wb_iface.hpp>
26 #include <uhd/utils/static.hpp>
28 #include <uhd/rfnoc/block_id.hpp>
29 #include <uhd/rfnoc/stream_sig.hpp>
30 #include <uhd/rfnoc/blockdef.hpp>
31 #include <uhd/rfnoc/constants.hpp>
32 #include <boost/cstdint.hpp>
33 #include <boost/shared_ptr.hpp>
34 #include <boost/lexical_cast.hpp>
35 #include <stdint.h>
36 
37 namespace uhd {
38  namespace rfnoc {
39  namespace nocscript {
40  // Forward declaration
41  class block_iface;
42  }
43 
44 
45 // TODO: Move this out of public section
47 {
48  make_args_t(const std::string &key="") :
49  device_index(0),
50  is_big_endian(true),
51  block_name(""),
52  block_key(key)
53  {}
54 
56  std::map<size_t, uhd::wb_iface::sptr> ctrl_ifaces;
58  uint32_t base_address;
60  size_t device_index;
62  // property tree is /mboards/0, pass a subtree starting at /mboards/0
63  // to the constructor.
67  std::string block_name;
69  std::string block_key;
70 };
71 
73 // block class
74 #define UHD_RFNOC_BLOCK_OBJECT(class_name) \
75  typedef boost::shared_ptr< class_name > sptr;
76 
78 #define UHD_RFNOC_BLOCK_CONSTRUCTOR(CLASS_NAME) \
79  CLASS_NAME##_impl( \
80  const make_args_t &make_args \
81  ) : block_ctrl_base(make_args)
82 
84 // after the class definition
85 #define UHD_RFNOC_BLOCK_REGISTER(CLASS_NAME, BLOCK_NAME) \
86  block_ctrl_base::sptr CLASS_NAME##_make( \
87  const make_args_t &make_args \
88  ) { \
89  return block_ctrl_base::sptr(new CLASS_NAME##_impl(make_args)); \
90  } \
91  UHD_STATIC_BLOCK(register_rfnoc_##CLASS_NAME) \
92  { \
93  uhd::rfnoc::block_ctrl_base::register_block(&CLASS_NAME##_make, BLOCK_NAME); \
94  }
95 
106 class block_ctrl_base : virtual public node_ctrl_base
107 {
108 public:
109  /***********************************************************************
110  * Types
111  **********************************************************************/
112  typedef boost::shared_ptr<block_ctrl_base> sptr;
113  typedef boost::function<sptr(const make_args_t &)> make_t;
114 
115  /***********************************************************************
116  * Factory functions
117  **********************************************************************/
118 
129  static void register_block(const make_t &make, const std::string &name);
130 
145  static sptr make(const make_args_t &make_args, boost::uint64_t noc_id = ~0);
146 
147  /***********************************************************************
148  * Block Communication and Control
149  *
150  * These functions do not require communication with the FPGA.
151  **********************************************************************/
152 
155  boost::uint32_t get_address(size_t block_port=0);
156 
159  block_id_t get_block_id() const { return _block_id; };
160 
163  std::string unique_id() const { return _block_id.to_string(); };
164 
165  /***********************************************************************
166  * FPGA control & communication
167  **********************************************************************/
168 
171  std::vector<size_t> get_ctrl_ports() const;
172 
181  void sr_write(const boost::uint32_t reg, const boost::uint32_t data, const size_t port = 0);
182 
192  void sr_write(const std::string &reg, const boost::uint32_t data, const size_t port = 0);
193 
200  boost::uint64_t sr_read64(const settingsbus_reg_t reg, const size_t port = 0);
201 
208  boost::uint32_t sr_read32(const settingsbus_reg_t reg, const size_t port = 0);
209 
219  boost::uint64_t user_reg_read64(const boost::uint32_t addr, const size_t port = 0);
220 
231  boost::uint64_t user_reg_read64(const std::string &reg, const size_t port = 0);
232 
242  boost::uint32_t user_reg_read32(const boost::uint32_t addr, const size_t port = 0);
243 
254  boost::uint32_t user_reg_read32(const std::string &reg, const size_t port = 0);
255 
256 
262  void set_command_time(const time_spec_t &time_spec, const size_t port = ANY_PORT);
263 
268  time_spec_t get_command_time(const size_t port = 0);
269 
274  void set_command_tick_rate(const double tick_rate, const size_t port = ANY_PORT);
275 
283  void clear_command_time(const size_t port);
284 
303  void clear(const size_t port = 0/* reserved, currently not used */);
304 
305  /***********************************************************************
306  * Argument handling
307  **********************************************************************/
313  void set_args(const uhd::device_addr_t &args, const size_t port = 0);
314 
316  // data type using by looking up its type in the block definition.
317  void set_arg(const std::string &key, const std::string &val, const size_t port = 0);
318 
320  template <typename T>
321  void set_arg(const std::string &key, const T &val, const size_t port = 0) {
322  _tree->access<T>(get_arg_path(key, port) / "value").set(val);
323  }
324 
326  uhd::device_addr_t get_args(const size_t port = 0) const;
327 
329  std::string get_arg(const std::string &key, const size_t port = 0) const;
330 
332  template <typename T>
333  T get_arg(const std::string &key, const size_t port = 0) const {
334  return _tree->access<T>(get_arg_path(key, port) / "value").get();
335  }
336 
337  std::string get_arg_type(const std::string &key, const size_t port = 0) const;
338 
339 protected:
340  /***********************************************************************
341  * Structors
342  **********************************************************************/
343  block_ctrl_base(void) {}; // To allow pure virtual (interface) sub-classes
344  virtual ~block_ctrl_base();
345 
353  const make_args_t &make_args
354  );
355 
356  /***********************************************************************
357  * Helpers
358  **********************************************************************/
359  stream_sig_t _resolve_port_def(const blockdef::port_t &port_def) const;
360 
362  uhd::fs_path get_arg_path(const std::string &key, size_t port = 0) const {
363  return _root_path / "args" / port / key;
364  };
365 
367  wb_iface::sptr get_ctrl_iface(const size_t block_port);
368 
369 
370  /***********************************************************************
371  * Hooks & Derivables
372  **********************************************************************/
373 
375  // than reset register SR_CLEAR_TX_FC.
376  virtual void _clear(const size_t port = 0);
377 
378  /***********************************************************************
379  * Protected members
380  **********************************************************************/
381 
384 
387 
390 
393 
394 private:
396  void _init_port_defs(
397  const std::string &direction,
398  blockdef::ports_t ports,
399  const size_t first_port_index=0
400  );
401 
403  void _init_block_args();
404 
405  /***********************************************************************
406  * Private members
407  **********************************************************************/
409  std::map<size_t, wb_iface::sptr> _ctrl_ifaces;
410 
412  uint32_t _base_address;
413 
415  block_id_t _block_id;
416 
418  boost::shared_ptr<nocscript::block_iface> _nocscript_iface;
419 }; /* class block_ctrl_base */
420 
421 }} /* namespace uhd::rfnoc */
422 
423 #endif /* INCLUDED_LIBUHD_BLOCK_CTRL_BASE_HPP */
424 // vim: sw=4 et:
uhd::property_tree::sptr _tree
Property sub-tree.
Definition: block_ctrl_base.hpp:383
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:321
boost::shared_ptr< wb_iface > sptr
Definition: wb_iface.hpp:32
std::string block_name
The name of the block as it will be addressed.
Definition: block_ctrl_base.hpp:67
std::map< size_t, uhd::wb_iface::sptr > ctrl_ifaces
A valid interface that allows us to do peeks and pokes.
Definition: block_ctrl_base.hpp:56
Definition: property_tree.hpp:204
make_args_t(const std::string &key="")
Definition: block_ctrl_base.hpp:48
bool is_big_endian
Definition: block_ctrl_base.hpp:65
Definition: time_spec.hpp:39
blockdef::sptr _block_def
Block definition (stores info about the block such as ports)
Definition: block_ctrl_base.hpp:392
uint32_t base_address
This block&#39;s base address (address of block port 0)
Definition: block_ctrl_base.hpp:58
Definition: block_ctrl_base.hpp:106
boost::function< sptr(const make_args_t &)> make_t
Definition: block_ctrl_base.hpp:113
uhd::fs_path _root_path
Root node of this block&#39;s properties.
Definition: block_ctrl_base.hpp:386
settingsbus_reg_t
Settings register readback.
Definition: constants.hpp:76
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:220
block_id_t get_block_id() const
Definition: block_ctrl_base.hpp:159
Definition: block_id.hpp:49
uhd::fs_path get_arg_path(const std::string &key, size_t port=0) const
Return the property tree path to a block argument on port.
Definition: block_ctrl_base.hpp:362
bool _transport_is_big_endian
Endianness of underlying transport (for data transport)
Definition: block_ctrl_base.hpp:389
Definition: build_info.hpp:25
std::string unique_id() const
Definition: block_ctrl_base.hpp:163
class UHD_RFNOC_API block_ctrl_base
Base class for all RFNoC block controller objects.
Definition: block_ctrl_base.hpp:105
std::string block_key
The key of the block, i.e. how it was registered.
Definition: block_ctrl_base.hpp:69
#define UHD_RFNOC_API
Definition: config.hpp:103
Definition: block_ctrl_base.hpp:46
uhd::property_tree::sptr tree
A property tree for this motherboard. Example: If the root a device&#39;s.
Definition: block_ctrl_base.hpp:64
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:333
boost::shared_ptr< block_ctrl_base > sptr
Definition: block_ctrl_base.hpp:112
boost::shared_ptr< blockdef > sptr
Definition: blockdef.hpp:35
block_ctrl_base(void)
Definition: block_ctrl_base.hpp:343
Describes port options for a block definition.
Definition: blockdef.hpp:44
Definition: stream_sig.hpp:33
std::vector< port_t > ports_t
Definition: blockdef.hpp:61
Definition: device_addr.hpp:47
size_t device_index
The device index (or motherboard index).
Definition: block_ctrl_base.hpp:60
Definition: node_ctrl_base.hpp:41