diff options
author | Trung N Tran <trung.tran@ettus.com> | 2017-12-20 04:37:56 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:06:03 -0800 |
commit | 3980f7401e6c461a9359f229b6b940e580452e08 (patch) | |
tree | cd17c56164c6bd7ab995ecfdd66ef1b2ec5a7b39 /host/lib/usrp/dboard | |
parent | 2e32f96291ac9c0e4d6514d6e4f8edc36ef4d426 (diff) | |
download | uhd-3980f7401e6c461a9359f229b6b940e580452e08.tar.gz uhd-3980f7401e6c461a9359f229b6b940e580452e08.tar.bz2 uhd-3980f7401e6c461a9359f229b6b940e580452e08.zip |
mg: Use floating point comparison for all frequencies
Reviewed-by: Martin Braun <martin.braun@ettus.com>
Diffstat (limited to 'host/lib/usrp/dboard')
-rw-r--r-- | host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_cpld.cpp | 34 | ||||
-rw-r--r-- | host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp | 12 |
2 files changed, 23 insertions, 23 deletions
diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_cpld.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_cpld.cpp index 1c3016587..d1ef730b7 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_cpld.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_cpld.cpp @@ -8,7 +8,7 @@ #include "magnesium_cpld_ctrl.hpp" #include "magnesium_constants.hpp" #include <uhd/utils/log.hpp> - +#include <uhd/utils/math.hpp> /* * Magnesium Rev C frequency bands: * @@ -39,7 +39,7 @@ using namespace uhd; using namespace uhd::usrp; using namespace uhd::rfnoc; - +using namespace uhd::math::fp_compare; void magnesium_radio_ctrl_impl::_update_atr_switches( const magnesium_cpld_ctrl::chan_sel_t chan, const direction_t dir, @@ -142,12 +142,12 @@ void magnesium_radio_ctrl_impl::_update_rx_freq_switches( auto rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER2100X2850MHZFROM; auto rx_sw5 = magnesium_cpld_ctrl::RX_SW5_FILTER1100X1575MHZFROM; auto rx_sw6 = magnesium_cpld_ctrl::RX_SW6_BYPASSPATHFROMSWITCH2; - const auto select_lowband_mixer_path = (freq <= MAGNESIUM_LOWBAND_FREQ) ? + const auto select_lowband_mixer_path = (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ) ? magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_LOBAND : magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS; - const bool enable_lowband_mixer = (freq < MAGNESIUM_LOWBAND_FREQ); + const bool enable_lowband_mixer = (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ); const bool rx_lna2_enable = - not bypass_lnas and (freq < MAGNESIUM_RX_BAND4_MIN_FREQ); + not bypass_lnas and (fp_compare_epsilon<double>(freq) < MAGNESIUM_RX_BAND4_MIN_FREQ); const bool rx_lna1_enable = not bypass_lnas and not rx_lna2_enable; UHD_LOG_TRACE(unique_id(), @@ -155,37 +155,37 @@ void magnesium_radio_ctrl_impl::_update_rx_freq_switches( " Enabling LNA2: " << (rx_lna2_enable ? "Yes" : "No")); // All the defaults are OK when using the bypass path. if (not bypass_lnas) { - if (freq < MAGNESIUM_LOWBAND_FREQ) { + if (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ) { rx_sw2 = magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3; rx_sw3 = magnesium_cpld_ctrl::RX_SW3_FILTER0490LPMHZ; rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ; rx_sw5 = magnesium_cpld_ctrl::RX_SW5_FILTER0490LPMHZFROM; rx_sw6 = magnesium_cpld_ctrl::RX_SW6_LOWERFILTERBANKFROMSWITCH5; - } else if (freq < MAGNESIUM_RX_BAND2_MIN_FREQ) { + } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_RX_BAND2_MIN_FREQ) { rx_sw2 = magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3; rx_sw3 = magnesium_cpld_ctrl::RX_SW3_FILTER0440X0530MHZ; rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ; rx_sw5 = magnesium_cpld_ctrl::RX_SW5_FILTER0440X0530MHZFROM; rx_sw6 = magnesium_cpld_ctrl::RX_SW6_LOWERFILTERBANKFROMSWITCH5; - } else if (freq < MAGNESIUM_RX_BAND3_MIN_FREQ) { + } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_RX_BAND3_MIN_FREQ) { rx_sw2 = magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3; rx_sw3 = magnesium_cpld_ctrl::RX_SW3_FILTER0650X1000MHZ; rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ; rx_sw5 = magnesium_cpld_ctrl::RX_SW5_FILTER0650X1000MHZFROM; rx_sw6 = magnesium_cpld_ctrl::RX_SW6_LOWERFILTERBANKFROMSWITCH5; - } else if (freq < MAGNESIUM_RX_BAND4_MIN_FREQ) { + } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_RX_BAND4_MIN_FREQ) { rx_sw2 = magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3; rx_sw3 = magnesium_cpld_ctrl::RX_SW3_FILTER1100X1575MHZ; rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ; rx_sw5 = magnesium_cpld_ctrl::RX_SW5_FILTER1100X1575MHZFROM; rx_sw6 = magnesium_cpld_ctrl::RX_SW6_LOWERFILTERBANKFROMSWITCH5; - } else if (freq < MAGNESIUM_RX_BAND5_MIN_FREQ) { + } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_RX_BAND5_MIN_FREQ) { rx_sw2 = magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3; rx_sw3 = magnesium_cpld_ctrl::RX_SW3_FILTER1600X2250MHZ; rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER1600X2250MHZFROM; rx_sw5 = magnesium_cpld_ctrl::RX_SW5_FILTER0440X0530MHZFROM; rx_sw6 = magnesium_cpld_ctrl::RX_SW6_UPPERFILTERBANKFROMSWITCH4; - } else if (freq < MAGNESIUM_RX_BAND6_MIN_FREQ) { + } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_RX_BAND6_MIN_FREQ) { rx_sw2 = magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3; rx_sw3 = magnesium_cpld_ctrl::RX_SW3_FILTER2100X2850MHZ; rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER2100X2850MHZFROM; @@ -231,34 +231,34 @@ void magnesium_radio_ctrl_impl::_update_tx_freq_switches( auto tx_sw1 = magnesium_cpld_ctrl::TX_SW1_SHUTDOWNTXSW1; auto tx_sw2 = magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP6400MHZ; auto tx_sw3 = magnesium_cpld_ctrl::TX_SW3_BYPASSPATHTOTRXSW; - const auto select_lowband_mixer_path = (freq <= MAGNESIUM_LOWBAND_FREQ) ? + const auto select_lowband_mixer_path = (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ) ? magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_LOBAND : magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS; - const bool enable_lowband_mixer = (freq <= MAGNESIUM_LOWBAND_FREQ); + const bool enable_lowband_mixer = (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ); // Defaults are fine for bypassing the amp stage if (bypass_amp) { _sw_trx[chan_sel] = magnesium_cpld_ctrl::SW_TRX_BYPASSPATHTOTXSW3; } else { // Set filters based on frequency - if (freq < MAGNESIUM_TX_BAND1_MIN_FREQ) { + if (fp_compare_epsilon<double>(freq) < MAGNESIUM_TX_BAND1_MIN_FREQ) { _sw_trx[chan_sel] = magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; tx_sw1 = magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP0800MHZ; tx_sw2 = magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP0800MHZ; tx_sw3 = magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS; - } else if (freq < MAGNESIUM_TX_BAND2_MIN_FREQ) { + } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_TX_BAND2_MIN_FREQ) { _sw_trx[chan_sel] = magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; tx_sw1 = magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP0800MHZ; tx_sw2 = magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP0800MHZ; tx_sw3 = magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS; - } else if (freq < MAGNESIUM_TX_BAND3_MIN_FREQ) { + } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_TX_BAND3_MIN_FREQ) { _sw_trx[chan_sel] = magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; tx_sw1 = magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP1700MHZ; tx_sw2 = magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP1700MHZ; tx_sw3 = magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS; - } else if (freq < MAGNESIUM_TX_BAND4_MIN_FREQ) { + } else if (fp_compare_epsilon<double>(freq) < MAGNESIUM_TX_BAND4_MIN_FREQ) { _sw_trx[chan_sel] = magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; tx_sw1 = magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP3400MHZ; diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp index dd239484b..7796b8b47 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp @@ -23,7 +23,7 @@ using namespace uhd; using namespace uhd::usrp; using namespace uhd::rfnoc; - +using namespace uhd::math::fp_compare; namespace { /************************************************************************** * ADF4351 Controls @@ -226,7 +226,7 @@ double magnesium_radio_ctrl_impl::set_tx_frequency( UHD_ASSERT_THROW(adf4351_source == "internal"); double coerced_if_freq = freq; - if (freq < MAGNESIUM_LOWBAND_FREQ) { // Low band + if (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ) { // Low band _is_low_band[TX_DIRECTION] = true; const double desired_low_freq = MAGNESIUM_TX_IF_FREQ - freq; coerced_if_freq = @@ -284,9 +284,9 @@ void magnesium_radio_ctrl_impl::_update_freq( UHD_LOG_TRACE(unique_id(), "RF freq = " << rf_freq); - UHD_ASSERT_THROW(rf_freq >= 0); + UHD_ASSERT_THROW(fp_compare_epsilon<double>(rf_freq) >= 0); UHD_ASSERT_THROW( - std::abs(rf_freq - _desired_rf_freq[dir]) <= _master_clock_rate/2); + fp_compare_epsilon<double>(std::abs(rf_freq - _desired_rf_freq[dir])) <= _master_clock_rate/2); if (dir == RX_DIRECTION){ radio_ctrl_impl::set_rx_frequency(rf_freq, chan); }else if (dir == TX_DIRECTION){ @@ -324,7 +324,7 @@ double magnesium_radio_ctrl_impl::set_rx_frequency( UHD_ASSERT_THROW(adf4351_source == "internal"); double coerced_if_freq = freq; - if (freq < MAGNESIUM_LOWBAND_FREQ) { // Low band + if (fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ) { // Low band _is_low_band[RX_DIRECTION] = true; const double desired_low_freq = MAGNESIUM_RX_IF_FREQ - freq; coerced_if_freq = @@ -815,7 +815,7 @@ bool magnesium_radio_ctrl_impl::get_lo_lock_status( _rpc_prefix + "get_ad9371_lo_lock", trx); UHD_LOG_TRACE(unique_id(), "AD9371 " << trx << " LO reports lock: " << (lo_lock ? "Yes" : "No")); - if (lo_lock && freq < MAGNESIUM_LOWBAND_FREQ) { + if (lo_lock && fp_compare_epsilon<double>(freq) < MAGNESIUM_LOWBAND_FREQ) { lo_lock = lo_lock && _rpcc->request_with_token<bool>( _rpc_prefix + "get_lowband_lo_lock", trx); UHD_LOG_TRACE(unique_id(), |