11 #include <uhdlib/utils/narrow.hpp> 13 #include <type_traits> 17 namespace uhd {
namespace rfnoc {
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;
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)
32 const uint32_t id_reg_offset = 0;
33 const uint32_t first_counter_offset = 1;
34 const uint64_t traffic_counter_id = 0x712AFF1C00000000ULL;
37 const uint64_t
id = _read_reg_fn(id_reg_offset);
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);
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"};
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]() {
62 uhd::narrow_cast<uint32_t>(i) + first_counter_offset);
69 write_reg_fn_t _write_reg_fn;
70 read_reg_fn_t _read_reg_fn;
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