From 64bbe1e39ca71499074b7af16a8df389b84203fd Mon Sep 17 00:00:00 2001 From: Ciro Nishiguchi Date: Fri, 28 Sep 2018 13:06:20 -0500 Subject: uhd: Add traffic counter to null source sink --- host/include/uhd/rfnoc/traffic_counter.hpp | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 host/include/uhd/rfnoc/traffic_counter.hpp (limited to 'host/include') diff --git a/host/include/uhd/rfnoc/traffic_counter.hpp b/host/include/uhd/rfnoc/traffic_counter.hpp new file mode 100644 index 000000000..4077596cd --- /dev/null +++ b/host/include/uhd/rfnoc/traffic_counter.hpp @@ -0,0 +1,81 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_LIBUHD_TRAFFIC_COUNTER_HPP +#define INCLUDED_LIBUHD_TRAFFIC_COUNTER_HPP + +#include +#include +#include +#include +#include + +namespace uhd { + namespace rfnoc { + +class traffic_counter +{ +public: + typedef std::shared_ptr sptr; + typedef std::function write_reg_fn_t ; + typedef std::function read_reg_fn_t ; + + 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 + ) : + _write_reg_fn(write_reg_fn), + _read_reg_fn(read_reg_fn) + { + const uint32_t id_reg_offset = 0; + const uint32_t first_counter_offset = 1; + const uint64_t traffic_counter_id = 0x712AFF1C00000000ULL; + + // Check traffic counter id to determine if it's present + const uint64_t id = _read_reg_fn(id_reg_offset); + + // If present, add properties + if (id == traffic_counter_id) + { + tree->create(root_path/"traffic_counter/enable") + .add_coerced_subscriber([this](const bool enable) { + uint32_t val = enable? 1 : 0; + return _write_reg_fn(0, val); + }).set(false); + + const char* counters[] = { + "bus_clock_ticks", + "xbar_to_shell_last", + "xbar_to_shell_valid", + "xbar_to_shell_ready", + "shell_to_xbar_last", + "shell_to_xbar_valid", + "shell_to_xbar_ready", + "shell_to_ce_last", + "shell_to_ce_valid", + "shell_to_ce_ready", + "ce_to_shell_last", + "ce_to_shell_valid", + "ce_to_shell_ready"}; + + for (size_t i = 0; i < std::extent::value; i++) { + tree->create(root_path/"traffic_counter"/counters[i]) + .set_publisher([this, i, first_counter_offset]() { + return _read_reg_fn(i+first_counter_offset); + }); + } + } + } +private: + write_reg_fn_t _write_reg_fn; + read_reg_fn_t _read_reg_fn; +}; + +}} /* namespace uhd::rfnoc */ + +#endif /* INCLUDED_LIBUHD_TRAFFIC_COUNTER_HPP */ -- cgit v1.2.3