From eab0f7fe8923fbfa2f69d0227a91ae722d5f560f Mon Sep 17 00:00:00 2001 From: Martin Anderseck Date: Mon, 12 Oct 2026 13:49:45 +0200 Subject: [PATCH] hbx: Fix LTC freq lookup logic Previously the logic for the LTC5594 configuration was wrong. We sometimes fell back into the default case which then didn't choose the default but the first row in our lookup table. The default value was now moved into an own constant and the lookup logic is now inverted to be correct. --- host/lib/include/uhdlib/usrp/common/ltc5594.hpp | 5 ++++- host/lib/usrp/common/ltc5594.cpp | 14 ++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/host/lib/include/uhdlib/usrp/common/ltc5594.hpp b/host/lib/include/uhdlib/usrp/common/ltc5594.hpp index b873a1750..55df5933e 100644 --- a/host/lib/include/uhdlib/usrp/common/ltc5594.hpp +++ b/host/lib/include/uhdlib/usrp/common/ltc5594.hpp @@ -102,11 +102,14 @@ static const std::vector lo_matching_table = { { 1242e6, 1411e6, 1, 21, 3, 28 }, { 1411e6, 1696e6, 1, 17, 2, 26 }, { 1696e6, 2070e6, 1, 15, 1, 31 }, - { 0, 0, 1, 8, 3, 3 }, // Default { 2070e6, 2470e6, 1, 8, 1, 21 }, { 2470e6, 2980e6, 1, 2, 1, 10 }, { 2980e6, 3500e6, 1, 1, 0, 19 }, { 3500e6, 9000e6, 1, 0, 0, 0 } }; + +static const ltc5594_lo_matching_t default_lo_matching = { + 0, 0, 1, 8, 3, 3 +}; // Turn clang-format back on // clang-format on diff --git a/host/lib/usrp/common/ltc5594.cpp b/host/lib/usrp/common/ltc5594.cpp index 521b68a1a..2b28e7e25 100644 --- a/host/lib/usrp/common/ltc5594.cpp +++ b/host/lib/usrp/common/ltc5594.cpp @@ -165,20 +165,14 @@ private: { auto settings = lo_matching_table.begin(); auto settings_end = lo_matching_table.end(); - // Check if the frequency is within the range of the settings, else return the - // default settings saved at min=0, max=0: - if ((*settings).min_band_freq <= lo_freq - && (*settings_end).max_band_freq >= lo_freq) { - lo_freq = 0.0; - } for (; settings != settings_end; ++settings) { - if (settings->max_band_freq >= lo_freq) { + if (settings->min_band_freq <= lo_freq + && settings->max_band_freq >= lo_freq) { return *settings; } } - // If no matching setting is found, throw an exception - throw std::runtime_error( - "No matching LO settings found for the given frequency."); + // If no matching setting is found, return default settings + return default_lo_matching; } };