diff options
Diffstat (limited to 'host')
9 files changed, 799 insertions, 279 deletions
| diff --git a/host/lib/usrp/dboard/magnesium/CMakeLists.txt b/host/lib/usrp/dboard/magnesium/CMakeLists.txt index d1db7d1ea..36fff8b66 100644 --- a/host/lib/usrp/dboard/magnesium/CMakeLists.txt +++ b/host/lib/usrp/dboard/magnesium/CMakeLists.txt @@ -20,8 +20,10 @@ IF(ENABLE_MPMD)          ${CMAKE_CURRENT_SOURCE_DIR}/magnesium_radio_ctrl_impl.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/magnesium_radio_ctrl_init.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/magnesium_radio_ctrl_cpld.cpp +        ${CMAKE_CURRENT_SOURCE_DIR}/magnesium_radio_ctrl_gain.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/magnesium_ad9371_iface.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/magnesium_cpld_ctrl.cpp +        ${CMAKE_CURRENT_SOURCE_DIR}/magnesium_gain_table.cpp      )      LIBUHD_APPEND_SOURCES(${MAGNESIUM_SOURCES})  ENDIF(ENABLE_MPMD) diff --git a/host/lib/usrp/dboard/magnesium/magnesium_constants.hpp b/host/lib/usrp/dboard/magnesium/magnesium_constants.hpp index f66d9ab8e..ec7595d98 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_constants.hpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_constants.hpp @@ -42,10 +42,10 @@ static const double AD9371_MIN_TX_GAIN = 0.0; // dB  static const double AD9371_MAX_TX_GAIN = 41.95; // dB  static const double AD9371_TX_GAIN_STEP = 0.05;  static const double ALL_RX_MIN_GAIN = 0.0; -static const double ALL_RX_MAX_GAIN = 61.5; +static const double ALL_RX_MAX_GAIN = 75.0;  static const double ALL_RX_GAIN_STEP = 0.5;  static const double ALL_TX_MIN_GAIN = 0.0; -static const double ALL_TX_MAX_GAIN = 73.45; +static const double ALL_TX_MAX_GAIN = 65.0;  static const double ALL_TX_GAIN_STEP = 0.5;  static const double MAGNESIUM_CENTER_FREQ = 2.5e9; // Hz  static const std::vector<std::string> MAGNESIUM_RX_ANTENNAS = { diff --git a/host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp b/host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp new file mode 100644 index 000000000..72707db17 --- /dev/null +++ b/host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp @@ -0,0 +1,443 @@ +// +// Copyright 2017 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0 +// + +#include "magnesium_gain_table.hpp" +#include "magnesium_constants.hpp" +#include <uhd/exception.hpp> +#include <map> + +using namespace uhd; +using namespace magnesium; + +namespace { +    //! Maps gain index -> gain_tuple_t +    // +    // Note: This is an int, for easier lookups. We're basically hardcoding the +    // knowledge that the gain map has a 1 dB granularity. +    using gain_tuple_map_t = std::map<int, gain_tuple_t>; + +    //! Maps max frequency -> gain_tuple_map_t +    using gain_tables_t = std::map<double, gain_tuple_map_t>; + +    /*! RX gain tables +     */ +    const gain_tables_t rx_gain_tables = { +        {MAGNESIUM_LOWBAND_FREQ, { +                // Gain, DSA att, Myk att, bypass +                {0,    {30, 30, true}}, +                {1,    {30, 29, true}}, +                {2,    {30, 28, true}}, +                {3,    {30, 27, true}}, +                {4,    {30, 26, true}}, +                {5,    {30, 25, true}}, +                {6,    {29, 25, true}}, +                {7,    {28, 25, true}}, +                {8,    {27, 25, true}}, +                {9,    {26, 25, true}}, +                {10,   {25, 25, true}}, +                {11,   {25, 24, true}}, +                {12,   {25, 23, true}}, +                {13,   {25, 22, true}}, +                {14,   {25, 21, true}}, +                {15,   {25, 20, true}}, +                {16,   {24, 20, true}}, +                {17,   {23, 20, true}}, +                {18,   {22, 20, true}}, +                {19,   {21, 20, true}}, +                {20,   {20, 20, true}}, +                {21,   {20, 19, true}}, +                {22,   {20, 18, true}}, +                {23,   {20, 17, true}}, +                {24,   {20, 16, true}}, +                {25,   {20, 15, true}}, +                {26,   {19, 15, true}}, +                {27,   {18, 15, true}}, +                {28,   {17, 15, true}}, +                {29,   {16, 15, true}}, +                {30,   {15, 15, true}}, +                {31,   {14, 15, true}}, +                {32,   {13, 15, true}}, +                {33,   {12, 15, true}}, +                {34,   {11, 15, true}}, +                {35,   {10, 15, true}}, +                {36,   {10, 14, true}}, +                {37,   {10, 13, true}}, +                {38,   {10, 12, true}}, +                {39,   {10, 11, true}}, +                {40,   {10, 10, true}}, +                {41,   {9, 10, true}}, +                {42,   {8, 10, true}}, +                {43,   {7, 10, true}}, +                {44,   {6, 10, true}}, +                {45,   {5, 10, true}}, +                {46,   {4, 10, true}}, +                {47,   {3, 10, true}}, +                {48,   {2, 10, true}}, +                {49,   {1, 10, true}}, +                {50,   {15, 15, false}}, +                {51,   {14, 15, false}}, +                {52,   {13, 15, false}}, +                {53,   {12, 15, false}}, +                {54,   {11, 15, false}}, +                {55,   {10, 15, false}}, +                {56,   {10, 14, false}}, +                {57,   {10, 13, false}}, +                {58,   {10, 12, false}}, +                {59,   {10, 11, false}}, +                {60,   {10, 10, false}}, +                {61,   {9, 10, false}}, +                {62,   {8, 10, false}}, +                {63,   {7, 10, false}}, +                {64,   {6, 10, false}}, +                {65,   {5, 10, false}}, +                {66,   {4, 10, false}}, +                {67,   {3, 10, false}}, +                {68,   {2, 10, false}}, +                {69,   {1, 10, false}}, +                {70,   {0, 10, false}}, +                {71,   {0, 9, false}}, +                {72,   {0, 8, false}}, +                {73,   {0, 7, false}}, +                {74,   {0, 6, false}}, +                {75,   {0, 5, false}} +        }}, +        {MAGNESIUM_RX_BAND4_MIN_FREQ, { +                {0, {30, 30, true}}, +                {1, {30, 29, true}}, +                {2, {30, 28, true}}, +                {3, {30, 27, true}}, +                {4, {30, 26, true}}, +                {5, {30, 25, true}}, +                {6, {30, 24, true}}, +                {7, {30, 23, true}}, +                {8, {30, 22, true}}, +                {9, {30, 21, true}}, +                {10, {30, 20, true}}, +                {11, {30, 19, true}}, +                {12, {30, 18, true}}, +                {13, {30, 17, true}}, +                {14, {30, 16, true}}, +                {15, {30, 15, true}}, +                {16, {29, 15, true}}, +                {17, {28, 15, true}}, +                {18, {27, 15, true}}, +                {19, {26, 15, true}}, +                {20, {25, 15, true}}, +                {21, {24, 15, true}}, +                {22, {23, 15, true}}, +                {23, {22, 15, true}}, +                {24, {21, 15, true}}, +                {25, {20, 15, true}}, +                {26, {19, 15, true}}, +                {27, {18, 15, true}}, +                {28, {17, 15, true}}, +                {29, {16, 15, true}}, +                {30, {15, 15, true}}, +                {31, {14, 15, true}}, +                {32, {13, 15, true}}, +                {33, {12, 15, true}}, +                {34, {11, 15, true}}, +                {35, {10, 15, true}}, +                {36, {9, 15, true}}, +                {37, {8, 15, true}}, +                {38, {7, 15, true}}, +                {39, {6, 15, true}}, +                {40, {5, 15, true}}, +                {41, {5, 14, true}}, +                {42, {5, 13, true}}, +                {43, {5, 12, true}}, +                {44, {5, 11, true}}, +                {45, {5, 10, true}}, +                {46, {4, 10, true}}, +                {47, {3, 10, true}}, +                {48, {2, 10, true}}, +                {49, {1, 10, true}}, +                {50, {15, 15, false}}, +                {51, {15, 14, false}}, +                {52, {15, 13, false}}, +                {53, {15, 12, false}}, +                {54, {15, 11, false}}, +                {55, {15, 10, false}}, +                {56, {15, 9, false}}, +                {57, {15, 8, false}}, +                {58, {15, 7, false}}, +                {59, {15, 6, false}}, +                {60, {15, 5, false}}, +                {61, {14, 5, false}}, +                {62, {13, 5, false}}, +                {63, {12, 5, false}}, +                {64, {11, 5, false}}, +                {65, {10, 5, false}}, +                {66, {10, 4, false}}, +                {67, {10, 3, false}}, +                {68, {10, 2, false}}, +                {69, {10, 1, false}}, +                {70, {10, 0, false}}, +                {71, {9, 0, false}}, +                {72, {8, 0, false}}, +                {73, {7, 0, false}}, +                {74, {6, 0, false}}, +                {75, {5, 0, false}} +        }}, +        {MAGNESIUM_MAX_FREQ, { +                {0, {30, 30, true}}, +                {1, {30, 29, true}}, +                {2, {30, 28, true}}, +                {3, {30, 27, true}}, +                {4, {30, 26, true}}, +                {5, {30, 25, true}}, +                {6, {30, 24, true}}, +                {7, {30, 23, true}}, +                {8, {30, 22, true}}, +                {9, {30, 21, true}}, +                {10, {30, 20, true}}, +                {11, {30, 19, true}}, +                {12, {30, 18, true}}, +                {13, {30, 17, true}}, +                {14, {30, 16, true}}, +                {15, {30, 15, true}}, +                {16, {29, 15, true}}, +                {17, {28, 15, true}}, +                {18, {27, 15, true}}, +                {19, {26, 15, true}}, +                {20, {25, 15, true}}, +                {21, {24, 15, true}}, +                {22, {23, 15, true}}, +                {23, {22, 15, true}}, +                {24, {21, 15, true}}, +                {25, {20, 15, true}}, +                {26, {19, 15, true}}, +                {27, {18, 15, true}}, +                {28, {17, 15, true}}, +                {29, {16, 15, true}}, +                {30, {15, 15, true}}, +                {31, {15, 14, true}}, +                {32, {15, 13, true}}, +                {33, {15, 12, true}}, +                {34, {15, 11, true}}, +                {35, {15, 10, true}}, +                {36, {14, 10, true}}, +                {37, {13, 10, true}}, +                {38, {12, 10, true}}, +                {39, {11, 10, true}}, +                {40, {10, 10, true}}, +                {41, {9, 10, true}}, +                {42, {8, 10, true}}, +                {43, {7, 10, true}}, +                {44, {6, 10, true}}, +                {45, {5, 10, true}}, +                {46, {4, 10, true}}, +                {47, {3, 10, true}}, +                {48, {2, 10, true}}, +                {49, {1, 10, true}}, +                {50, {15, 15, false}}, +                {51, {15, 14, false}}, +                {52, {15, 13, false}}, +                {53, {15, 12, false}}, +                {54, {15, 11, false}}, +                {55, {15, 10, false}}, +                {56, {14, 10, false}}, +                {57, {13, 10, false}}, +                {58, {12, 10, false}}, +                {59, {11, 10, false}}, +                {60, {10, 10, false}}, +                {61, {10, 9, false}}, +                {62, {10, 8, false}}, +                {63, {10, 7, false}}, +                {64, {10, 6, false}}, +                {65, {10, 5, false}}, +                {66, {9, 5, false}}, +                {67, {8, 5, false}}, +                {68, {7, 5, false}}, +                {69, {6, 5, false}}, +                {70, {5, 5, false}}, +                {71, {5, 4, false}}, +                {72, {5, 3, false}}, +                {73, {5, 2, false}}, +                {74, {5, 1, false}}, +                {75, {5, 0, false}} +            }, +        } +    }; /* rx_gain_tables */ + +    const gain_tables_t tx_gain_tables = { +        {MAGNESIUM_LOWBAND_FREQ, { +                // Gain, DSA att, Myk att, bypass +                {0, {30, 20, true}}, +                {1, {29, 20, true}}, +                {2, {28, 20, true}}, +                {3, {27, 20, true}}, +                {4, {26, 20, true}}, +                {5, {25, 20, true}}, +                {6, {24, 20, true}}, +                {7, {23, 20, true}}, +                {8, {22, 20, true}}, +                {9, {21, 20, true}}, +                {10, {20, 20, true}}, +                {11, {19, 20, true}}, +                {12, {18, 20, true}}, +                {13, {17, 20, true}}, +                {14, {16, 20, true}}, +                {15, {15, 20, true}}, +                {16, {14, 20, true}}, +                {17, {13, 20, true}}, +                {18, {12, 20, true}}, +                {19, {11, 20, true}}, +                {20, {10, 20, true}}, +                {21, {9, 20, true}}, +                {22, {8, 20, true}}, +                {23, {7, 20, true}}, +                {24, {6, 20, true}}, +                {25, {5, 20, true}}, +                {26, {4, 20, true}}, +                {27, {3, 20, true}}, +                {28, {2, 20, true}}, +                {29, {1, 20, true}}, +                {30, {0, 20, true}}, +                {31, {0, 19, true}}, +                {32, {0, 18, true}}, +                {33, {0, 17, true}}, +                {34, {0, 16, true}}, +                {35, {0, 15, true}}, +                {36, {0, 14, true}}, +                {37, {0, 13, true}}, +                {38, {0, 12, true}}, +                {39, {0, 11, true}}, +                {40, {10, 15, false}}, +                {41, {9, 15, false}}, +                {42, {8, 15, false}}, +                {43, {7, 15, false}}, +                {44, {6, 15, false}}, +                {45, {5, 15, false}}, +                {46, {4, 15, false}}, +                {47, {3, 15, false}}, +                {48, {2, 15, false}}, +                {49, {1, 15, false}}, +                {50, {0, 15, false}}, +                {51, {0, 14, false}}, +                {52, {0, 13, false}}, +                {53, {0, 12, false}}, +                {54, {0, 11, false}}, +                {55, {0, 10, false}}, +                {56, {0, 9, false}}, +                {57, {0, 8, false}}, +                {58, {0, 7, false}}, +                {59, {0, 6, false}}, +                {60, {0, 5, false}}, +                {61, {0, 4, false}}, +                {62, {0, 3, false}}, +                {63, {0, 2, false}}, +                {64, {0, 1, false}}, +                {65, {0, 0, false}} +        }}, +        {6e9, { +                {0, {30, 20, true}}, +                {1, {29, 20, true}}, +                {2, {28, 20, true}}, +                {3, {27, 20, true}}, +                {4, {26, 20, true}}, +                {5, {25, 20, true}}, +                {6, {24, 20, true}}, +                {7, {23, 20, true}}, +                {8, {22, 20, true}}, +                {9, {21, 20, true}}, +                {10, {20, 20, true}}, +                {11, {19, 20, true}}, +                {12, {18, 20, true}}, +                {13, {17, 20, true}}, +                {14, {16, 20, true}}, +                {15, {15, 20, true}}, +                {16, {14, 20, true}}, +                {17, {13, 20, true}}, +                {18, {12, 20, true}}, +                {19, {11, 20, true}}, +                {20, {10, 20, true}}, +                {21, {9, 20, true}}, +                {22, {8, 20, true}}, +                {23, {7, 20, true}}, +                {24, {6, 20, true}}, +                {25, {5, 20, true}}, +                {26, {4, 20, true}}, +                {27, {3, 20, true}}, +                {28, {2, 20, true}}, +                {29, {1, 20, true}}, +                {30, {0, 20, true}}, +                {31, {0, 19, true}}, +                {32, {0, 18, true}}, +                {33, {0, 17, true}}, +                {34, {0, 16, true}}, +                {35, {5, 20, false}}, +                {36, {4, 20, false}}, +                {37, {3, 20, false}}, +                {38, {2, 20, false}}, +                {39, {1, 20, false}}, +                {40, {0, 20, false}}, +                {41, {0, 19, false}}, +                {42, {0, 18, false}}, +                {43, {0, 17, false}}, +                {44, {0, 16, false}}, +                {45, {0, 15, false}}, +                {46, {0, 14, false}}, +                {47, {0, 13, false}}, +                {48, {0, 12, false}}, +                {49, {0, 11, false}}, +                {50, {0, 10, false}}, +                {51, {0, 9, false}}, +                {52, {0, 8, false}}, +                {53, {0, 7, false}}, +                {54, {0, 6, false}}, +                {55, {0, 5, false}}, +                {56, {0, 4, false}}, +                {57, {0, 3, false}}, +                {58, {0, 2, false}}, +                {59, {0, 1, false}}, +                {60, {0, 0, false}}, +                // Rest is fake to keep same gain range as low band +                {61, {0, 0, false}}, +                {62, {0, 0, false}}, +                {63, {0, 0, false}}, +                {64, {0, 0, false}}, +                {65, {0, 0, false}} +        }} +    }; /* tx_gain_tables */ +} /* namespace ANON */ + +gain_tuple_t magnesium::get_gain_tuple( +    const double gain_index, +    const double freq, +    const uhd::direction_t dir +) { +    UHD_ASSERT_THROW(dir == RX_DIRECTION or dir == TX_DIRECTION); +    if (dir == RX_DIRECTION) { +        UHD_ASSERT_THROW( +            gain_index <= ALL_RX_MAX_GAIN and gain_index >= ALL_RX_MIN_GAIN +        ); +    } else { +        UHD_ASSERT_THROW( +            gain_index <= ALL_TX_MAX_GAIN and gain_index >= ALL_TX_MIN_GAIN +        ); +    } +    auto &gain_table = (dir == RX_DIRECTION) ? +        rx_gain_tables : +        tx_gain_tables; + +    for (const auto &gain_map : gain_table) { +        // First, find appropriate gain map for this frequency +        if (gain_map.first >= freq) { +            int gain_index_truncd = int(gain_index); +            // Here, we hardcode the half-dB steps. We soak up all half-dB +            // steps by twiddling the AD9371 attenuation, but we need to make +            // sure we don't make it negative. +            gain_tuple_t gain_tuple = gain_map.second.at(gain_index_truncd); +            if (gain_index - double(gain_index_truncd) >= .5) { +                gain_tuple.ad9371_att = +                    std::max(0.0, gain_tuple.ad9371_att - .5); +            } +            return gain_tuple; +        } +    } +    UHD_THROW_INVALID_CODE_PATH(); +} diff --git a/host/lib/usrp/dboard/magnesium/magnesium_gain_table.hpp b/host/lib/usrp/dboard/magnesium/magnesium_gain_table.hpp new file mode 100644 index 000000000..e3af493b1 --- /dev/null +++ b/host/lib/usrp/dboard/magnesium/magnesium_gain_table.hpp @@ -0,0 +1,40 @@ +// +// Copyright 2017 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0 +// + +#ifndef INCLUDED_LIBUHD_MAGNESIUM_GAIN_TABLE_HPP +#define INCLUDED_LIBUHD_MAGNESIUM_GAIN_TABLE_HPP + +#include <uhd/types/direction.hpp> + +namespace magnesium { + +/*! Store all gain-table related settings for the N310 (Magnesium) daughterboard + * + * For every requested gain value, one of these will be returned. Works for TX + * and RX paths. + */ +struct gain_tuple_t +{ +    //! Attenuation value of the DSA in dB +    double dsa_att; +    //! Attenuation value of Mykonos (AD9371) in dB +    double ad9371_att; +    //! If true, bypass LNA or PA section +    bool bypass; +}; + + +/*! Given a gain index, return a tuple of gain-related settings + */ +gain_tuple_t get_gain_tuple( +    const double gain_index, +    const double freq, +    const uhd::direction_t dir +); + +} /* namespace magnesium */ + +#endif 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 5b8cb5f70..d76bcf4a6 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_cpld.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_cpld.cpp @@ -115,194 +115,165 @@ void magnesium_radio_ctrl_impl::_update_atr_switches(  void magnesium_radio_ctrl_impl::_update_rx_freq_switches(      const double freq, +    const bool bypass_lnas,      const size_t chan  ) { -     UHD_LOG_TRACE(unique_id(), -             "Update all RX freq related switches. f=" << freq << " Hz, " -             "chan=" << chan); +    UHD_LOG_TRACE(unique_id(), +        "Update all RX freq related switches. f=" << freq << " Hz, " +        "bypass LNAS: " << (bypass_lnas ? "Yes" : "No") << ", chan=" << chan +    ); -     // Set filters based on frequency. Note: We always switch both channels -    if (freq < MAGNESIUM_RX_BAND1_MIN_FREQ) { -        _cpld->set_rx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3, -            magnesium_cpld_ctrl::RX_SW3_FILTER0490LPMHZ, -            magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ, -            magnesium_cpld_ctrl::RX_SW5_FILTER0490LPMHZFROM, -            magnesium_cpld_ctrl::RX_SW6_LOWERFILTERBANKFROMSWITCH5, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_LOBAND, -            true // Enable lowband mixer -        ); -    } else if (freq < MAGNESIUM_RX_BAND2_MIN_FREQ) { -        _cpld->set_rx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3, -            magnesium_cpld_ctrl::RX_SW3_FILTER0440X0530MHZ, -            magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ, -            magnesium_cpld_ctrl::RX_SW5_FILTER0440X0530MHZFROM, -            magnesium_cpld_ctrl::RX_SW6_LOWERFILTERBANKFROMSWITCH5, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false -        ); -    } else if (freq < MAGNESIUM_RX_BAND3_MIN_FREQ) { -        _cpld->set_rx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3, -            magnesium_cpld_ctrl::RX_SW3_FILTER0650X1000MHZ, -            magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ, -            magnesium_cpld_ctrl::RX_SW5_FILTER0650X1000MHZFROM, -            magnesium_cpld_ctrl::RX_SW6_LOWERFILTERBANKFROMSWITCH5, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false -        ); -    } else if (freq < MAGNESIUM_RX_BAND4_MIN_FREQ) { -        _cpld->set_rx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3, -            magnesium_cpld_ctrl::RX_SW3_FILTER1100X1575MHZ, -            magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ, -            magnesium_cpld_ctrl::RX_SW5_FILTER1100X1575MHZFROM, -            magnesium_cpld_ctrl::RX_SW6_LOWERFILTERBANKFROMSWITCH5, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false -        ); -    } else if (freq < MAGNESIUM_RX_BAND5_MIN_FREQ) { -        _cpld->set_rx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3, -            magnesium_cpld_ctrl::RX_SW3_FILTER1600X2250MHZ, -            magnesium_cpld_ctrl::RX_SW4_FILTER1600X2250MHZFROM, -            magnesium_cpld_ctrl::RX_SW5_FILTER0440X0530MHZFROM, -            magnesium_cpld_ctrl::RX_SW6_UPPERFILTERBANKFROMSWITCH4, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false -        ); -    } else if (freq < MAGNESIUM_RX_BAND6_MIN_FREQ) { -        _cpld->set_rx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3, -            magnesium_cpld_ctrl::RX_SW3_FILTER2100X2850MHZ, -            magnesium_cpld_ctrl::RX_SW4_FILTER2100X2850MHZFROM, -            magnesium_cpld_ctrl::RX_SW5_FILTER0440X0530MHZFROM, -            magnesium_cpld_ctrl::RX_SW6_UPPERFILTERBANKFROMSWITCH4, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false -        ); -    } else { -        _cpld->set_rx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::RX_SW2_UPPERFILTERBANKTOSWITCH4, -            magnesium_cpld_ctrl::RX_SW3_SHUTDOWNSW3, -            magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ, -            magnesium_cpld_ctrl::RX_SW5_FILTER0440X0530MHZFROM, -            magnesium_cpld_ctrl::RX_SW6_UPPERFILTERBANKFROMSWITCH4, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false -        ); +    auto rx_sw2 = magnesium_cpld_ctrl::RX_SW2_BYPASSPATHTOSWITCH6; +    auto rx_sw3 = magnesium_cpld_ctrl::RX_SW3_SHUTDOWNSW3; +    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) ? +        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 rx_lna2_enable = +        not bypass_lnas and (freq < MAGNESIUM_RX_BAND4_MIN_FREQ); +    const bool rx_lna1_enable = +        not bypass_lnas and not rx_lna2_enable; +    UHD_LOG_TRACE(unique_id(), +        " Enabling LNA1: " << (rx_lna1_enable ? "Yes" : "No") << +        " 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) { +            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) { +            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) { +            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) { +            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) { +            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) { +            rx_sw2 = magnesium_cpld_ctrl::RX_SW2_LOWERFILTERBANKTOSWITCH3; +            rx_sw3 = magnesium_cpld_ctrl::RX_SW3_FILTER2100X2850MHZ; +            rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER2100X2850MHZFROM; +            rx_sw5 = magnesium_cpld_ctrl::RX_SW5_FILTER0440X0530MHZFROM; +            rx_sw6 = magnesium_cpld_ctrl::RX_SW6_UPPERFILTERBANKFROMSWITCH4; +        } else { +            rx_sw2 = magnesium_cpld_ctrl::RX_SW2_UPPERFILTERBANKTOSWITCH4; +            rx_sw3 = magnesium_cpld_ctrl::RX_SW3_SHUTDOWNSW3; +            rx_sw4 = magnesium_cpld_ctrl::RX_SW4_FILTER2700HPMHZ; +            rx_sw5 = magnesium_cpld_ctrl::RX_SW5_FILTER0440X0530MHZFROM; +            rx_sw6 = magnesium_cpld_ctrl::RX_SW6_UPPERFILTERBANKFROMSWITCH4; +        }      } + +    _cpld->set_rx_lna_atr_bits( +        magnesium_cpld_ctrl::BOTH, +        magnesium_cpld_ctrl::ANY, +        rx_lna1_enable, +        rx_lna2_enable, +        true /* defer commit */ +    ); +    _cpld->set_rx_switches( +        magnesium_cpld_ctrl::BOTH, +        rx_sw2, +        rx_sw3, +        rx_sw4, +        rx_sw5, +        rx_sw6, +        select_lowband_mixer_path, +        enable_lowband_mixer +    );  }  void magnesium_radio_ctrl_impl::_update_tx_freq_switches(      const double freq, +    const bool bypass_amp,      const size_t chan  ){ -     UHD_LOG_TRACE(unique_id(), -             "Update all TX freq related switches. f=" << freq << " Hz, " -             "chan=" << chan); -     magnesium_cpld_ctrl::chan_sel_t chan_sel = +    UHD_LOG_TRACE(unique_id(), +        "Update all TX freq related switches. f=" << freq << " Hz, " +        "bypass amp: " << (bypass_amp ? "Yes" : "No") << ", chan=" << chan +    ); +    magnesium_cpld_ctrl::chan_sel_t chan_sel =           _master ?  magnesium_cpld_ctrl::CHAN1 : magnesium_cpld_ctrl::CHAN2; -     // Set filters based on frequency -    if (freq < MAGNESIUM_TX_BAND1_MIN_FREQ) { -        _sw_trx[chan_sel] = -            magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; -        _cpld->set_trx_sw_atr_bits( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::ON, -            _sw_trx[chan_sel], -            true /* defer commit */ -        ); -        _cpld->set_tx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP0800MHZ, -            magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP0800MHZ, -            magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_LOBAND, -            true, // Enable lowband mixer -            magnesium_cpld_ctrl::ON -        ); -    } else if (freq < MAGNESIUM_TX_BAND2_MIN_FREQ) { -        _sw_trx[chan_sel] = -            magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; -        _cpld->set_trx_sw_atr_bits( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::ON, -            _sw_trx[chan_sel], -            true /* defer commit */ -        ); -        _cpld->set_tx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP0800MHZ, -            magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP0800MHZ, -            magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false, // Disable lowband mixer -            magnesium_cpld_ctrl::ON -        ); -    } else if (freq < MAGNESIUM_TX_BAND3_MIN_FREQ) { -        _sw_trx[chan_sel] = -            magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; -        _cpld->set_trx_sw_atr_bits( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::ON, -            _sw_trx[chan_sel], -            true /* defer commit */ -        ); -        _cpld->set_tx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP1700MHZ, -            magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP1700MHZ, -            magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false, -            magnesium_cpld_ctrl::ON -        ); -    } else if (freq < MAGNESIUM_TX_BAND4_MIN_FREQ) { -        _sw_trx[chan_sel] = -            magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; -        _cpld->set_trx_sw_atr_bits( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::ON, -            _sw_trx[chan_sel], -            true /* defer commit */ -        ); -        _cpld->set_tx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP3400MHZ, -            magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP3400MHZ, -            magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false, -            magnesium_cpld_ctrl::ON -        ); -    } else { -        _sw_trx[chan_sel] = -            magnesium_cpld_ctrl::SW_TRX_FROMTXUPPERFILTERBANKLP6400MHZ; -        _cpld->set_trx_sw_atr_bits( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::ON, -            _sw_trx[chan_sel], -            true /* defer commit */ -        ); -        _cpld->set_tx_switches( -            magnesium_cpld_ctrl::BOTH, -            magnesium_cpld_ctrl::TX_SW1_SHUTDOWNTXSW1, -            magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP6400MHZ, -            magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS, -            magnesium_cpld_ctrl::LOWBAND_MIXER_PATH_SEL_BYPASS, -            false, -            magnesium_cpld_ctrl::ON -        ); +    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) ? +        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); +    // Defaults are fine for bypassing the amp stage +    if (not bypass_amp) { +         // Set filters based on frequency +        if (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) { +            _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) { +            _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) { +            _sw_trx[chan_sel] = +                magnesium_cpld_ctrl::SW_TRX_FROMLOWERFILTERBANKTXSW1; +            tx_sw1 = magnesium_cpld_ctrl::TX_SW1_FROMTXFILTERLP3400MHZ; +            tx_sw2 = magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP3400MHZ; +            tx_sw3 = magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS; +        } else { +            _sw_trx[chan_sel] = +                magnesium_cpld_ctrl::SW_TRX_FROMTXUPPERFILTERBANKLP6400MHZ; +            tx_sw1 = magnesium_cpld_ctrl::TX_SW1_SHUTDOWNTXSW1; +            tx_sw2 = magnesium_cpld_ctrl::TX_SW2_TOTXFILTERLP6400MHZ; +            tx_sw3 = magnesium_cpld_ctrl::TX_SW3_TOTXFILTERBANKS; +        }      } + +    _cpld->set_trx_sw_atr_bits( +        magnesium_cpld_ctrl::BOTH, +        magnesium_cpld_ctrl::ON, +        _sw_trx[chan_sel], +        true /* defer commit */ +    ); +    _cpld->set_tx_switches( +        magnesium_cpld_ctrl::BOTH, +        tx_sw1, +        tx_sw2, +        tx_sw3, +        select_lowband_mixer_path, +        enable_lowband_mixer, +        magnesium_cpld_ctrl::ON +    );  } diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_gain.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_gain.cpp new file mode 100644 index 000000000..b3d01df2c --- /dev/null +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_gain.cpp @@ -0,0 +1,123 @@ +// +// Copyright 2017 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0 +// + +#include "magnesium_radio_ctrl_impl.hpp" +#include "magnesium_gain_table.hpp" +#include "magnesium_constants.hpp" +#include <uhd/utils/log.hpp> + +using namespace uhd; +using namespace uhd::usrp; +using namespace uhd::rfnoc; +using namespace magnesium; + +double magnesium_radio_ctrl_impl::_set_all_gain( +    const double gain, +    const double freq, +    const size_t chan, +    const direction_t dir +) { +    UHD_LOG_TRACE(unique_id(), +        __func__ << "(gain=" << gain << "dB, " +        "freq=" << freq << " Hz, " +        "chan=" << chan << ", " +        "dir=" << dir); +    const auto gain_tuple = get_gain_tuple(gain, freq, dir); +    const double ad9371_gain = +        ((dir == RX_DIRECTION) ?  AD9371_MAX_RX_GAIN : AD9371_MAX_TX_GAIN) +        - gain_tuple.ad9371_att; +    UHD_LOG_TRACE(unique_id(), +        "AD9371 attenuation==" << gain_tuple.ad9371_att << " dB, " +        "AD9371 gain==" << ad9371_gain << " dB, " +        "DSA attenuation == " << gain_tuple.dsa_att << " dB." +    ); +    _ad9371->set_gain(ad9371_gain, chan, dir); +    _dsa_set_att(gain_tuple.dsa_att, chan, dir); +    if (dir == RX_DIRECTION or dir == DX_DIRECTION) { +        _all_rx_gain = gain; +        _rx_bypass_lnas = gain_tuple.bypass; +        _update_rx_freq_switches( +            radio_ctrl_impl::get_rx_frequency(chan), +            _rx_bypass_lnas, +            chan +        ); +    } +    if (dir == TX_DIRECTION or dir == DX_DIRECTION) { +        _all_tx_gain = gain; +        _tx_bypass_amp = gain_tuple.bypass; +        _update_tx_freq_switches( +            radio_ctrl_impl::get_tx_frequency(chan), +            _tx_bypass_amp, +            chan +        ); +    } + +    return gain; +} + +double magnesium_radio_ctrl_impl::_get_all_gain( +    const size_t /* chan */, +    const direction_t dir +) { +    UHD_LOG_TRACE(unique_id(), "Getting all gain "); +    if (dir == RX_DIRECTION) { +       return _all_rx_gain; +    } +    return _all_tx_gain; +} + +/****************************************************************************** + * DSA Controls + *****************************************************************************/ +double magnesium_radio_ctrl_impl::_dsa_set_att( +    const double att, +    const size_t chan, +    const direction_t dir +) { +    UHD_LOG_TRACE(unique_id(), +        __func__ << +        "(att=" << "att dB, chan=" << chan << ", dir=" << dir << ")") +    const uint32_t dsa_val = 2*att; + +    _set_dsa_val(chan, dir, dsa_val); +    if (dir == RX_DIRECTION or dir == DX_DIRECTION) { +        _dsa_rx_att = att; +    } +    if (dir == TX_DIRECTION or dir == DX_DIRECTION) { +        _dsa_tx_att = att; +    } +    return att; +} + +double magnesium_radio_ctrl_impl::_dsa_get_att( +    const size_t /*chan*/, +    const direction_t dir +) { +    if (dir == RX_DIRECTION) { +       return _dsa_rx_att; +    } +    return _dsa_tx_att; +} + +void magnesium_radio_ctrl_impl::_set_dsa_val( +    const size_t chan, +    const direction_t dir, +    const uint32_t dsa_val +) { +    if (dir == RX_DIRECTION or dir == DX_DIRECTION){ +        UHD_LOG_TRACE(unique_id(), +            __func__ << "(chan=" << chan << ", dir=RX" +            << ", dsa_val=" << dsa_val << ")") +        _gpio[chan]->set_gpio_out(dsa_val, 0x003F); +    } +    if (dir == TX_DIRECTION or dir == DX_DIRECTION){ +        UHD_LOG_TRACE(unique_id(), +            __func__ << "(chan=" << chan << ", dir=TX" +            << ", dsa_val=" << dsa_val << ")") +        _gpio[chan]->set_gpio_out(dsa_val, 0x0FC0); +    } +} + 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 a6841b4b9..495eca3b0 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp @@ -6,6 +6,7 @@  #include "magnesium_radio_ctrl_impl.hpp"  #include "magnesium_constants.hpp" +#include "magnesium_gain_table.hpp"  #include <uhd/utils/log.hpp>  #include <uhd/rfnoc/node_ctrl_base.hpp>  #include <uhd/transport/chdr.hpp> @@ -166,7 +167,7 @@ double magnesium_radio_ctrl_impl::set_tx_frequency(      // bands.      UHD_LOG_TRACE(unique_id(),          "set_tx_frequency(f=" << freq << ", chan=" << chan << ")"); -    _update_tx_freq_switches(freq, chan); +    _update_tx_freq_switches(freq, _tx_bypass_amp, chan);      //double ad9371_freq = freq;      double if_freq = 0.0;      auto lo_iface = _tx_lo; @@ -199,7 +200,7 @@ double magnesium_radio_ctrl_impl::set_rx_frequency(      // bands.      UHD_LOG_TRACE(unique_id(),          "set_rx_frequency(f=" << freq << ", chan=" << chan << ")"); -    _update_rx_freq_switches(freq, chan); +    _update_rx_freq_switches(freq, _rx_bypass_lnas, chan);      //double ad9371_freq = freq;      double if_freq = 0.0;      auto lo_iface = _rx_lo; @@ -243,7 +244,12 @@ double magnesium_radio_ctrl_impl::set_tx_gain(          const size_t chan  ) {      radio_ctrl_impl::set_tx_gain(gain, chan); -    return _set_all_gain(gain, chan, TX_DIRECTION); +    return _set_all_gain( +        gain, +        radio_ctrl_impl::get_tx_frequency(chan), +        chan, +        TX_DIRECTION +    );  }  double magnesium_radio_ctrl_impl::set_rx_gain( @@ -253,7 +259,12 @@ double magnesium_radio_ctrl_impl::set_rx_gain(      UHD_LOG_TRACE(unique_id(),          "set_rx_gain(gain=" << gain << ", chan=" << chan << ")");      radio_ctrl_impl::set_rx_gain(gain, chan); -    return _set_all_gain(gain, chan, RX_DIRECTION); +    return _set_all_gain( +        gain, +        radio_ctrl_impl::get_rx_frequency(chan), +        chan, +        RX_DIRECTION +    );  }  std::vector<std::string> magnesium_radio_ctrl_impl::get_rx_lo_names( @@ -352,87 +363,4 @@ void magnesium_radio_ctrl_impl::set_rpc_client(      ;  } -/****************************************************************************** - * Helpers - *****************************************************************************/ -double magnesium_radio_ctrl_impl::_set_all_gain( -    const double gain, -    const size_t chan, -    const direction_t dir -) { -    UHD_LOG_TRACE(unique_id(), "Setting all gain " << gain); -    // just naively  distributed gain here -    _ad9371->set_gain(gain/2, chan, dir); -    _dsa_set_gain(gain/2, chan, dir); -    if(dir == RX_DIRECTION or dir == DX_DIRECTION) -    { -        _all_rx_gain = gain; -    } -    if(dir == TX_DIRECTION or dir == DX_DIRECTION) -    { -        _all_tx_gain = gain; -    } - -    return gain; -} - -double magnesium_radio_ctrl_impl::_get_all_gain( -    const size_t /* chan */, -    const direction_t dir -) { -    UHD_LOG_TRACE(unique_id(), "Getting all gain "); -    if (dir == RX_DIRECTION) { -       return _all_rx_gain; -    } -    return _all_tx_gain; -} - -/****************************************************************************** - * DSA Controls - *****************************************************************************/ -double magnesium_radio_ctrl_impl::_dsa_set_gain( -    const double gain, -    const size_t chan, -    const direction_t dir -) { -    uint32_t dsa_val = 63-2*gain; -    UHD_LOG_TRACE(unique_id(), "Setting dsa gain " << dsa_val); - -    _set_dsa_val(chan,  dir, dsa_val); -    if (dir == RX_DIRECTION or dir == DX_DIRECTION) { -        _dsa_rx_gain = gain; -    } -    if (dir == TX_DIRECTION or dir == DX_DIRECTION) { -        _dsa_tx_gain = gain; -    } -    return gain; -} - -double magnesium_radio_ctrl_impl::_dsa_get_gain( -    const size_t /*chan*/, -    const direction_t dir -) { -    if (dir == RX_DIRECTION) { -       return _dsa_rx_gain; -    } -    return _dsa_tx_gain; -} - -void magnesium_radio_ctrl_impl::_set_dsa_val( -    const size_t chan, -    const direction_t dir, -    const uint32_t dsa_val -) { -    if (dir == RX_DIRECTION or dir == DX_DIRECTION){ -        UHD_LOG_TRACE(unique_id(), -                "Chan: " << chan << " Setting RX DSA value" << dsa_val); -        _gpio[chan]->set_gpio_out(dsa_val, 0x3F); -    } -    if (dir == TX_DIRECTION or dir == DX_DIRECTION){ -        UHD_LOG_TRACE(unique_id(), -                "Chan: " << chan << " Setting TX DSA value" << dsa_val); -        _gpio[chan]->set_gpio_out(dsa_val, 0x0FC0); -    } -} -  UHD_RFNOC_BLOCK_REGISTER(magnesium_radio_ctrl, "MagnesiumRadio"); diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.hpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.hpp index 75a91d0b4..c8597fdf7 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.hpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.hpp @@ -123,19 +123,29 @@ private:      /**************************************************************************       * Gain Controls (implemented in magnesium_radio_ctrl_gain.cpp)       *************************************************************************/ -    double _dsa_set_gain( -            const double gain, +    //! Set the attenuation of the DSA +    double _dsa_set_att( +            const double att,              const size_t chan,              const direction_t dir      ); -    double _dsa_get_gain( +    double _dsa_get_att(              const size_t chan,              const direction_t dir      ); +    //! Write the DSA word +    void _set_dsa_val( +            const size_t chan, +            const direction_t dir, +            const uint32_t dsa_val +    ); + +      double _set_all_gain(          const double gain, +        const double freq,          const size_t chan,          const direction_t dir      ); @@ -145,22 +155,18 @@ private:          const direction_t dir      ); -    void _set_dsa_val( -            const size_t chan, -            const direction_t dir, -            const uint32_t dsa_val -    ); -      /**************************************************************************       * CPLD Controls (implemented in magnesium_radio_ctrl_cpld.cpp)       *************************************************************************/      void _update_rx_freq_switches(          const double freq, +        const bool bypass_lnas,          const size_t chan      );      void _update_tx_freq_switches(          const double freq, +        const bool bypass_amps,          const size_t chan      ); @@ -212,15 +218,22 @@ private:      //! Front panel GPIO controller. Note that only one radio block per      //  module can be the FP-GPIO master.      usrp::gpio_atr::gpio_atr_3000::sptr _fp_gpio; +      //! AD9371 gain      double _ad9371_rx_gain = 0.0;      double _ad9371_tx_gain = 0.0; -    //! DSA gain -    double _dsa_rx_gain = 0.0; -    double _dsa_tx_gain = 0.0; + +    //! DSA attenuation +    double _dsa_rx_att = 0.0; +    double _dsa_tx_att = 0.0; +      //! All gain      double _all_rx_gain = 0.0;      double _all_tx_gain = 0.0; + +    bool _rx_bypass_lnas = true; +    bool _tx_bypass_amp  = true; +      //! TRX switch state of 2 channels      std::map<magnesium_cpld_ctrl::chan_sel_t, magnesium_cpld_ctrl::sw_trx_t> _sw_trx = {          {magnesium_cpld_ctrl::CHAN1, diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_init.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_init.cpp index ed5cb61c3..0d047c5d9 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_init.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_init.cpp @@ -314,7 +314,7 @@ void magnesium_radio_ctrl_impl::_init_frontend_subtree(          })      ;      subtree->create<meta_range_t>(tx_fe_path / "gains" / "all" / "range") -        .set(meta_range_t(0.0, 60.0, 1.0)) // FIXME +        .set(meta_range_t(ALL_TX_MIN_GAIN, ALL_TX_MAX_GAIN, ALL_TX_GAIN_STEP))          .add_coerced_subscriber([](const meta_range_t &){              throw uhd::runtime_error(                  "Attempting to update bandwidth range!"); @@ -331,7 +331,7 @@ void magnesium_radio_ctrl_impl::_init_frontend_subtree(          })      ;      subtree->create<meta_range_t>(rx_fe_path / "gains" / "all" / "range") -        .set(meta_range_t(0.0, 60.0, 1.0)) // FIXME +        .set(meta_range_t(ALL_RX_MIN_GAIN, ALL_RX_MAX_GAIN, ALL_RX_GAIN_STEP))          .add_coerced_subscriber([](const meta_range_t &){              throw uhd::runtime_error(                  "Attempting to update bandwidth range!"); | 
