From 12673d9290319d2453fedd806ddf248d3d5586e3 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Thu, 18 Jun 2020 17:46:06 -0500 Subject: uhd: Split radio_control into rf_control interfaces These rf_control interfaces allow easier implementation of radio controls as well as allowing easier sharing of code for implementing e.g. gain_profile. --- host/lib/rfnoc/CMakeLists.txt | 1 + host/lib/rfnoc/radio_control_impl.cpp | 36 +++++++--------- host/lib/rfnoc/rf_control/CMakeLists.txt | 13 ++++++ host/lib/rfnoc/rf_control/gain_profile.cpp | 68 ++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 host/lib/rfnoc/rf_control/CMakeLists.txt create mode 100644 host/lib/rfnoc/rf_control/gain_profile.cpp (limited to 'host/lib/rfnoc') diff --git a/host/lib/rfnoc/CMakeLists.txt b/host/lib/rfnoc/CMakeLists.txt index 33da287fe..53bca9b45 100644 --- a/host/lib/rfnoc/CMakeLists.txt +++ b/host/lib/rfnoc/CMakeLists.txt @@ -61,3 +61,4 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/window_block_control.cpp ) +INCLUDE_SUBDIRECTORY(rf_control) diff --git a/host/lib/rfnoc/radio_control_impl.cpp b/host/lib/rfnoc/radio_control_impl.cpp index f9347b9e7..e20f5d4f6 100644 --- a/host/lib/rfnoc/radio_control_impl.cpp +++ b/host/lib/rfnoc/radio_control_impl.cpp @@ -253,6 +253,10 @@ radio_control_impl::radio_control_impl(make_args_ptr make_args) boost::optional timestamp) { this->async_message_handler(addr, data, timestamp); }); + + // Set the default gain profiles + _rx_gain_profile_api = std::make_shared(); + _tx_gain_profile_api = std::make_shared(); } /* ctor */ /****************************************************************************** @@ -436,42 +440,34 @@ void radio_control_impl::set_rx_agc(const bool, const size_t) throw uhd::not_implemented_error("set_rx_agc() is not supported on this radio!"); } -void radio_control_impl::set_tx_gain_profile(const std::string& profile, const size_t) +void radio_control_impl::set_tx_gain_profile(const std::string& profile, const size_t chan) { - if (profile != DEFAULT_GAIN_PROFILE) { - throw uhd::value_error( - std::string("set_tx_gain_profile(): Unknown gain profile: `") + profile - + "'"); - } + _tx_gain_profile_api->set_gain_profile(profile, chan); } -void radio_control_impl::set_rx_gain_profile(const std::string& profile, const size_t) +void radio_control_impl::set_rx_gain_profile(const std::string& profile, const size_t chan) { - if (profile != DEFAULT_GAIN_PROFILE) { - throw uhd::value_error( - std::string("set_rx_gain_profile(): Unknown gain profile: `") + profile - + "'"); - } + _rx_gain_profile_api->set_gain_profile(profile, chan); } -std::vector radio_control_impl::get_tx_gain_profile_names(const size_t) const +std::vector radio_control_impl::get_tx_gain_profile_names(const size_t chan) const { - return {DEFAULT_GAIN_PROFILE}; + return _tx_gain_profile_api->get_gain_profile_names(chan); } -std::vector radio_control_impl::get_rx_gain_profile_names(const size_t) const +std::vector radio_control_impl::get_rx_gain_profile_names(const size_t chan) const { - return {DEFAULT_GAIN_PROFILE}; + return _rx_gain_profile_api->get_gain_profile_names(chan); } -std::string radio_control_impl::get_tx_gain_profile(const size_t) const +std::string radio_control_impl::get_tx_gain_profile(const size_t chan) const { - return DEFAULT_GAIN_PROFILE; + return _tx_gain_profile_api->get_gain_profile(chan); } -std::string radio_control_impl::get_rx_gain_profile(const size_t) const +std::string radio_control_impl::get_rx_gain_profile(const size_t chan) const { - return DEFAULT_GAIN_PROFILE; + return _rx_gain_profile_api->get_gain_profile(chan); } double radio_control_impl::set_tx_bandwidth(const double bandwidth, const size_t chan) diff --git a/host/lib/rfnoc/rf_control/CMakeLists.txt b/host/lib/rfnoc/rf_control/CMakeLists.txt new file mode 100644 index 000000000..11c7e57ef --- /dev/null +++ b/host/lib/rfnoc/rf_control/CMakeLists.txt @@ -0,0 +1,13 @@ +# +# Copyright 2020 Ettus Research, a National Instruments Brand +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +######################################################################## +# This file included, use CMake directory variables +######################################################################## + +LIBUHD_APPEND_SOURCES( + ${CMAKE_CURRENT_SOURCE_DIR}/gain_profile.cpp +) diff --git a/host/lib/rfnoc/rf_control/gain_profile.cpp b/host/lib/rfnoc/rf_control/gain_profile.cpp new file mode 100644 index 000000000..54ccb9006 --- /dev/null +++ b/host/lib/rfnoc/rf_control/gain_profile.cpp @@ -0,0 +1,68 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include +#include +#include +#include +#include +#include +#include + +namespace uhd { namespace rfnoc { namespace rf_control { + +const std::string default_gain_profile::DEFAULT_GAIN_PROFILE = "default"; + +std::vector default_gain_profile::get_gain_profile_names(const size_t) const +{ + return {DEFAULT_GAIN_PROFILE}; +} + +void default_gain_profile::set_gain_profile(const std::string& profile, const size_t) +{ + if (profile != DEFAULT_GAIN_PROFILE) { + throw uhd::value_error( + std::string("set_tx_gain_profile(): Unknown gain profile: `") + profile + + "'"); + } +} + +std::string default_gain_profile::get_gain_profile(const size_t) const +{ + return DEFAULT_GAIN_PROFILE; +} + +enumerated_gain_profile::enumerated_gain_profile( + const std::vector& possible_profiles, + const std::string& default_profile, + size_t num_channels) + : _possible_profiles(possible_profiles), _gain_profile(num_channels, default_profile) +{ +} + +void enumerated_gain_profile::set_gain_profile( + const std::string& profile, const size_t chan) +{ + if (!uhd::has(_possible_profiles, profile)) { + const std::string err_msg = ("Invalid gain profile provided: " + profile); + UHD_LOG_ERROR("gain_profile", err_msg); + throw uhd::key_error(err_msg); + } + _gain_profile.at(chan) = profile; +} + +std::string enumerated_gain_profile::get_gain_profile(const size_t chan) const +{ + return _gain_profile.at(chan); +} + +std::vector enumerated_gain_profile::get_gain_profile_names( + const size_t) const +{ + return _possible_profiles; +} + +}}} // namespace uhd::rfnoc::rf_control -- cgit v1.2.3