From 9b9da62e800ed88123c3bae7abecd5603ead0f7e Mon Sep 17 00:00:00 2001 From: Mark Meserve Date: Fri, 21 Dec 2018 15:54:17 -0600 Subject: rh: implement set_rate --- host/lib/usrp/dboard/rhodium/rhodium_constants.hpp | 6 +++- .../dboard/rhodium/rhodium_radio_ctrl_impl.cpp | 35 ++++++++++++++++++---- .../dboard/rhodium/rhodium_radio_ctrl_init.cpp | 8 +++-- 3 files changed, 40 insertions(+), 9 deletions(-) (limited to 'host/lib/usrp/dboard') diff --git a/host/lib/usrp/dboard/rhodium/rhodium_constants.hpp b/host/lib/usrp/dboard/rhodium/rhodium_constants.hpp index 2aafe4a63..c52a73bca 100644 --- a/host/lib/usrp/dboard/rhodium/rhodium_constants.hpp +++ b/host/lib/usrp/dboard/rhodium/rhodium_constants.hpp @@ -14,7 +14,11 @@ static constexpr double RHODIUM_FREQ_COMPARE_EPSILON = 1e-5; -static constexpr double RHODIUM_RADIO_RATE = 122.88e6; // Hz +static constexpr size_t NUM_RHODIUM_RADIO_RATES = 3; + +static constexpr std::array RHODIUM_RADIO_RATES = { + 200e6, 245.76e6, 250e6}; + static constexpr double RHODIUM_MIN_FREQ = 1e6; // Hz static constexpr double RHODIUM_MAX_FREQ = 6e9; // Hz diff --git a/host/lib/usrp/dboard/rhodium/rhodium_radio_ctrl_impl.cpp b/host/lib/usrp/dboard/rhodium/rhodium_radio_ctrl_impl.cpp index 6599e3d82..61e2d2550 100644 --- a/host/lib/usrp/dboard/rhodium/rhodium_radio_ctrl_impl.cpp +++ b/host/lib/usrp/dboard/rhodium/rhodium_radio_ctrl_impl.cpp @@ -70,13 +70,36 @@ rhodium_radio_ctrl_impl::~rhodium_radio_ctrl_impl() /****************************************************************************** * API Calls *****************************************************************************/ -double rhodium_radio_ctrl_impl::set_rate(double /* rate */) +double rhodium_radio_ctrl_impl::set_rate(double requested_rate) { - // TODO: implement - // TODO: set_rate may also need to update the LO since master clock rate - // changes also change the lowband LO frequency. (run set_frequency) - UHD_LOG_WARNING(unique_id(), "set_rate() called but not implemented"); - return 0.0; + meta_range_t rates; + for (const double rate : RHODIUM_RADIO_RATES) { + rates.push_back(range_t(rate)); + } + + const double rate = rates.clip(requested_rate); + if (!math::frequencies_are_equal(requested_rate, rate)) { + UHD_LOG_WARNING(unique_id(), + "Coercing requested sample rate from " << (requested_rate / 1e6) << " MHz to " << + (rate / 1e6) << " MHz, the closest possible rate."); + } + + const double current_rate = get_rate(); + if (math::frequencies_are_equal(current_rate, rate)) { + UHD_LOG_DEBUG( + unique_id(), "Rate is already at " << (rate / 1e6) << " MHz. Skipping set_rate()"); + return current_rate; + } + + UHD_LOG_TRACE(unique_id(), "Updating master clock rate to " << rate); + auto new_rate = _rpcc->request_with_token(_rpc_prefix + "set_master_clock_rate", rate); + // The lowband LO frequency will change with the master clock rate, so + // update the tuning of the device. + set_tx_frequency(get_tx_frequency(0), 0); + set_rx_frequency(get_rx_frequency(0), 0); + + radio_ctrl_impl::set_rate(new_rate); + return new_rate; } void rhodium_radio_ctrl_impl::set_tx_antenna( diff --git a/host/lib/usrp/dboard/rhodium/rhodium_radio_ctrl_init.cpp b/host/lib/usrp/dboard/rhodium/rhodium_radio_ctrl_init.cpp index 9cf7c57e6..b626e5c15 100644 --- a/host/lib/usrp/dboard/rhodium/rhodium_radio_ctrl_init.cpp +++ b/host/lib/usrp/dboard/rhodium/rhodium_radio_ctrl_init.cpp @@ -794,11 +794,15 @@ void rhodium_radio_ctrl_impl::_init_prop_tree() _tree->create("rx_codecs" / _radio_slot / "name").set("ad9695-625"); _tree->create("tx_codecs" / _radio_slot / "name").set("dac37j82"); - // TODO remove this dirty hack - if (not _tree->exists("tick_rate")) + // The tick_rate is equivalent to the master clock rate of the DB in slot A + if (_radio_slot == "A") { + UHD_ASSERT_THROW(!_tree->exists("tick_rate")); + // set_rate sets the clock rate of the entire device, not just this DB, + // so only add DB A's set and get functions to the tree. _tree->create("tick_rate") .set_publisher([this](){ return this->get_rate(); }) + .add_coerced_subscriber([this](double rate) { return this->set_rate(rate); }) ; } } -- cgit v1.2.3