From 491a74269e7d7d7589119c22f229c994d8a2c3f8 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 7 Jun 2019 21:29:34 -0700 Subject: rfnoc: register_iface_holder: Add ability to invalidate and update This lets child classes of register_iface_holder change the register interface, or even invalidate it. --- host/lib/rfnoc/CMakeLists.txt | 1 + host/lib/rfnoc/register_iface_holder.cpp | 92 ++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 host/lib/rfnoc/register_iface_holder.cpp (limited to 'host/lib') diff --git a/host/lib/rfnoc/CMakeLists.txt b/host/lib/rfnoc/CMakeLists.txt index 93e7ff5b2..dfef4f90f 100644 --- a/host/lib/rfnoc/CMakeLists.txt +++ b/host/lib/rfnoc/CMakeLists.txt @@ -37,6 +37,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/node_ctrl_base.cpp ${CMAKE_CURRENT_SOURCE_DIR}/node.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rate_node_ctrl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/register_iface_holder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ctrlport_endpoint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/chdr_ctrl_endpoint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/registry_factory.cpp diff --git a/host/lib/rfnoc/register_iface_holder.cpp b/host/lib/rfnoc/register_iface_holder.cpp new file mode 100644 index 000000000..ea5bf0149 --- /dev/null +++ b/host/lib/rfnoc/register_iface_holder.cpp @@ -0,0 +1,92 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include +#include + +using namespace uhd::rfnoc; + +/*! Special type of register interface: Invalidated interface + * + * This interface does nothing, other than log error messages and implement + * register_iface. It is meant to be used as a replacement for another + * register_iface when that interface is no longer accessible. + * Because this should be safely usable in a destructor, it never throws. + */ +class invalid_register_iface : public register_iface +{ +public: + ~invalid_register_iface() = default; + + void poke32(uint32_t, uint32_t, uhd::time_spec_t, bool) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + } + + void multi_poke32( + const std::vector, const std::vector, uhd::time_spec_t, bool) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + } + + void block_poke32(uint32_t, const std::vector, uhd::time_spec_t, bool) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + } + + uint32_t peek32(uint32_t, uhd::time_spec_t) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + return {}; + } + + std::vector block_peek32(uint32_t, size_t, uhd::time_spec_t) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + return {}; + } + + void poll32(uint32_t, uint32_t, uint32_t, uhd::time_spec_t, uhd::time_spec_t, bool) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + } + + void sleep(uhd::time_spec_t, bool) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + } + + void register_async_msg_handler(async_msg_callback_t) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + } + + void set_policy(const std::string&, const uhd::device_addr_t&) + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + } + + uint16_t get_src_epid() const + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + return 0; + } + + uint16_t get_port_num() const + { + UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!"); + return 0; + } +}; // class invalid_register_iface + +void register_iface_holder::update_reg_iface(register_iface::sptr new_iface) +{ + if (new_iface) { + _reg = new_iface; + } else { + _reg = std::make_shared(); + } +} -- cgit v1.2.3