diff options
author | Ciro Nishiguchi <ciro.nishiguchi@ni.com> | 2018-09-28 13:06:20 -0500 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-10-11 13:16:22 -0700 |
commit | 64bbe1e39ca71499074b7af16a8df389b84203fd (patch) | |
tree | 9680c58553925cc3730b2cf316d924556eb70828 /host/include | |
parent | 71300593e5c0c6af4116d8706c9762f808dbf441 (diff) | |
download | uhd-64bbe1e39ca71499074b7af16a8df389b84203fd.tar.gz uhd-64bbe1e39ca71499074b7af16a8df389b84203fd.tar.bz2 uhd-64bbe1e39ca71499074b7af16a8df389b84203fd.zip |
uhd: Add traffic counter to null source sink
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/rfnoc/traffic_counter.hpp | 81 |
1 files changed, 81 insertions, 0 deletions
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 <uhd/property_tree.hpp> +#include <stdint.h> +#include <memory> +#include <functional> +#include <type_traits> + +namespace uhd { + namespace rfnoc { + +class traffic_counter +{ +public: + typedef std::shared_ptr<traffic_counter> sptr; + typedef std::function<void(const uint32_t addr, const uint32_t data)> write_reg_fn_t ; + typedef std::function<uint64_t(const uint32_t addr)> 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<bool>(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<decltype(counters)>::value; i++) { + tree->create<uint64_t>(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 */ |