USRP Hardware Driver and USRP Manual  Version: 004.000.000.HEAD-0-g8773fb2c
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 
193  void sr_write(const std::string &reg, const boost::uint32_t data, const size_t port = 0);
194 
202  boost::uint64_t sr_read64(const settingsbus_reg_t reg, const size_t port = 0);
203 
211  boost::uint32_t sr_read32(const settingsbus_reg_t reg, const size_t port = 0);
212 
223  boost::uint64_t user_reg_read64(const boost::uint32_t addr, const size_t port = 0);
224 
236  boost::uint64_t user_reg_read64(const std::string &reg, const size_t port = 0);
237 
248  boost::uint32_t user_reg_read32(const boost::uint32_t addr, const size_t port = 0);
249 
260  boost::uint32_t user_reg_read32(const std::string &reg, const size_t port = 0);
261 
262 
268  void set_command_time(const time_spec_t &time_spec, const size_t port = ANY_PORT);
269 
274  time_spec_t get_command_time(const size_t port = 0);
275 
281  void set_command_tick_rate(const double tick_rate, const size_t port = ANY_PORT);
282 
290  void clear_command_time(const size_t port);
291 
310  void clear(const size_t port = 0/* reserved, currently not used */);
311 
312  /***********************************************************************
313  * Argument handling
314  **********************************************************************/
320  void set_args(const uhd::device_addr_t &args, const size_t port = 0);
321 
323  // data type using by looking up its type in the block definition.
324  void set_arg(const std::string &key, const std::string &val, const size_t port = 0);
325 
327  template <typename T>
328  void set_arg(const std::string &key, const T &val, const size_t port = 0) {
329  _tree->access<T>(get_arg_path(key, port) / "value").set(val);
330  }
331 
333  uhd::device_addr_t get_args(const size_t port = 0) const;
334 
336  std::string get_arg(const std::string &key, const size_t port = 0) const;
337 
339  template <typename T>
340  T get_arg(const std::string &key, const size_t port = 0) const {
341  return _tree->access<T>(get_arg_path(key, port) / "value").get();
342  }
343 
344  std::string get_arg_type(const std::string &key, const size_t port = 0) const;
345 
346 protected:
347  /***********************************************************************
348  * Structors
349  **********************************************************************/
350  block_ctrl_base(void) {}; // To allow pure virtual (interface) sub-classes
351  virtual ~block_ctrl_base();
352 
360  const make_args_t &make_args
361  );
362 
363  /***********************************************************************
364  * Helpers
365  **********************************************************************/
366  stream_sig_t _resolve_port_def(const blockdef::port_t &port_def) const;
367 
369  uhd::fs_path get_arg_path(const std::string &key, size_t port = 0) const {
370  return _root_path / "args" / port / key;
371  };
372 
374  wb_iface::sptr get_ctrl_iface(const size_t block_port);
375 
376 
377  /***********************************************************************
378  * Hooks & Derivables
379  **********************************************************************/
380 
382  // than reset register SR_CLEAR_TX_FC.
383  virtual void _clear(const size_t port = 0);
384 
385  /***********************************************************************
386  * Protected members
387  **********************************************************************/
388 
391 
394 
397 
400 
401 private:
403  void _init_port_defs(
404  const std::string &direction,
405  blockdef::ports_t ports,
406  const size_t first_port_index=0
407  );
408 
410  void _init_block_args();
411 
412  /***********************************************************************
413  * Private members
414  **********************************************************************/
416  std::map<size_t, wb_iface::sptr> _ctrl_ifaces;
417 
419  uint32_t _base_address;
420 
422  block_id_t _block_id;
423 
425  boost::shared_ptr<nocscript::block_iface> _nocscript_iface;
426 }; /* class block_ctrl_base */
427 
428 }} /* namespace uhd::rfnoc */
429 
430 #endif /* INCLUDED_LIBUHD_BLOCK_CTRL_BASE_HPP */
431 // vim: sw=4 et:
uhd::property_tree::sptr _tree
Property sub-tree.
Definition: block_ctrl_base.hpp:390
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:328
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:399
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:393
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 key on port.
Definition: block_ctrl_base.hpp:369
bool _transport_is_big_endian
Endianness of underlying transport (for data transport)
Definition: block_ctrl_base.hpp:396
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:340
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:350
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:40