USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-g6563c537
UHD and USRP Manual
traffic_counter.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2018 Ettus Research, a National Instruments Company
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #ifndef INCLUDED_LIBUHD_TRAFFIC_COUNTER_HPP
8 #define INCLUDED_LIBUHD_TRAFFIC_COUNTER_HPP
9 
10 #include <uhd/property_tree.hpp>
11 #include <stdint.h>
12 #include <type_traits>
13 #include <functional>
14 #include <memory>
15 
16 namespace uhd { namespace rfnoc {
17 
19 {
20 public:
21  typedef std::shared_ptr<traffic_counter> sptr;
22  typedef std::function<void(const uint32_t addr, const uint32_t data)> write_reg_fn_t;
23  typedef std::function<uint64_t(const uint32_t addr)> read_reg_fn_t;
24 
26  uhd::fs_path root_path,
27  write_reg_fn_t write_reg_fn,
28  read_reg_fn_t read_reg_fn)
29  : _write_reg_fn(write_reg_fn), _read_reg_fn(read_reg_fn)
30  {
31  const uint32_t id_reg_offset = 0;
32  const uint32_t first_counter_offset = 1;
33  const uint64_t traffic_counter_id = 0x712AFF1C00000000ULL;
34 
35  // Check traffic counter id to determine if it's present
36  const uint64_t id = _read_reg_fn(id_reg_offset);
37 
38  // If present, add properties
39  if (id == traffic_counter_id) {
40  tree->create<bool>(root_path / "traffic_counter/enable")
41  .add_coerced_subscriber([this](const bool enable) {
42  uint32_t val = enable ? 1 : 0;
43  return _write_reg_fn(0, val);
44  })
45  .set(false);
46 
47  const char* counters[] = {"bus_clock_ticks",
48  "xbar_to_shell_xfer_count",
49  "xbar_to_shell_pkt_count",
50  "shell_to_xbar_xfer_count",
51  "shell_to_xbar_pkt_count",
52  "shell_to_ce_xfer_count",
53  "shell_to_ce_pkt_count",
54  "ce_to_shell_xfer_count",
55  "ce_to_shell_pkt_count"};
56 
57  for (size_t i = 0; i < std::extent<decltype(counters)>::value; i++) {
58  tree->create<uint64_t>(root_path / "traffic_counter" / counters[i])
59  .set_publisher([this, i, first_counter_offset]() {
60  return _read_reg_fn(i + first_counter_offset);
61  });
62  }
63  }
64  }
65 
66 private:
67  write_reg_fn_t _write_reg_fn;
68  read_reg_fn_t _read_reg_fn;
69 };
70 
71 }} /* namespace uhd::rfnoc */
72 
73 #endif /* INCLUDED_LIBUHD_TRAFFIC_COUNTER_HPP */
Definition: property_tree.hpp:199
Definition: traffic_counter.hpp:18
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:217
std::function< uint64_t(const uint32_t addr)> read_reg_fn_t
Definition: traffic_counter.hpp:23
Definition: build_info.hpp:13
std::shared_ptr< traffic_counter > sptr
Definition: traffic_counter.hpp:21
std::function< void(const uint32_t addr, const uint32_t data)> write_reg_fn_t
Definition: traffic_counter.hpp:22
traffic_counter(uhd::property_tree::sptr tree, uhd::fs_path root_path, write_reg_fn_t write_reg_fn, read_reg_fn_t read_reg_fn)
Definition: traffic_counter.hpp:25