1From 3796175f32f0cc24c16809d8175d423bc7053de9 Mon Sep 17 00:00:00 2001 2From: StefanBruens <stefan.bruens@rwth-aachen.de> 3Date: Wed, 5 May 2021 18:24:58 +0200 4Subject: [PATCH] usrp2: Replace boost::math::iround/math::sign with std::lround 5 6Instead of multiplying zone with the sign repeatedly just make 7the zone a signed value. 8 9See #437, #438 10 11Signed-off-by: Aaron Rossetto <aaron.rossetto@ni.com> 12[gwenhael.goavec-merou@trabucayre.com: backport from upstream] 13Signed-off-by: Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com> 14--- 15 host/lib/usrp/usrp2/usrp2_impl.cpp | 10 +++++----- 16 1 file changed, 5 insertions(+), 5 deletions(-) 17 18diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp 19index 1be4c7339..c0719a316 100644 20--- a/host/lib/usrp/usrp2/usrp2_impl.cpp 21+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp 22@@ -22,6 +22,7 @@ 23 #include <boost/asio/ip/address_v4.hpp> 24 #include <boost/asio.hpp> //used for htonl and ntohl 25 #include <boost/thread.hpp> 26+#include <cmath> 27 28 using namespace uhd; 29 using namespace uhd::usrp; 30@@ -844,20 +845,19 @@ double usrp2_impl::set_tx_dsp_freq( 31 _tree->access<double>("/mboards/"+mb+"/tick_rate").get(); 32 33 //calculate the DAC shift (multiples of rate) 34- const int sign = boost::math::sign(new_freq); 35- const int zone = std::min(boost::math::iround(new_freq/tick_rate), 2); 36- const double dac_shift = sign*zone*tick_rate; 37+ const int zone = std::max(std::min(std::lround(new_freq / tick_rate), 2), -2); 38+ const double dac_shift = zone * tick_rate; 39 new_freq -= dac_shift; //update FPGA DSP target freq 40 UHD_LOG_TRACE("USRP2", 41 "DSP Tuning: Requested " + std::to_string(freq_/1e6) + " MHz, Using " 42- "Nyquist zone " + std::to_string(sign*zone) + ", leftover DSP tuning: " 43+ "Nyquist zone " + std::to_string(zone) + ", leftover DSP tuning: " 44 + std::to_string(new_freq/1e6) + " MHz."); 45 46 //set the DAC shift (modulation mode) 47 if (zone == 0) { 48 _mbc[mb].codec->set_tx_mod_mode(0); //no shift 49 } else { 50- _mbc[mb].codec->set_tx_mod_mode(sign*4/zone); //DAC interp = 4 51+ _mbc[mb].codec->set_tx_mod_mode(4 / zone); // DAC interp = 4 52 } 53 54 return _mbc[mb].tx_dsp->set_freq(new_freq) + dac_shift; //actual freq 55-- 562.32.0 57 58