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