diff options
author | eklai <eric@skysafe.io> | 2020-01-23 18:47:28 -0800 |
---|---|---|
committer | atrnati <54334261+atrnati@users.noreply.github.com> | 2020-02-18 07:21:24 -0600 |
commit | d7304cc724de43b0d61d5b9d61a528d58898f004 (patch) | |
tree | 05304ad4d65c507c6d43fcbc407c566c351053c3 /host/lib/usrp/x300 | |
parent | c0a6bb1720a3db8ac9a40bdd5ca19de8be40d500 (diff) | |
download | uhd-d7304cc724de43b0d61d5b9d61a528d58898f004.tar.gz uhd-d7304cc724de43b0d61d5b9d61a528d58898f004.tar.bz2 uhd-d7304cc724de43b0d61d5b9d61a528d58898f004.zip |
x300: add front-panel GPIO source control
Adds a ZPU register to control the FP GPIO source. These are 2bits
per GPIO pin, totalling 24 bits. 0 corresponds to RF-A, 1 corresponds
to RF-B. The following Python code will control the upper 6 bits of the
front-panel GPIO from the B-side radio on an X300:
>>> import uhd
>>> U = uhd.usrp.MultiUSRP("type=x300")
>>> U.get_gpio_src_banks()
['FP0']
>>> U.get_gpio_src("FP0")
['RFA', 'RFA', 'RFA', 'RFA', 'RFA', 'RFA', 'RFA', 'RFA', 'RFA', 'RFA',
'RFA', 'RFA']
>>> U.set_gpio_src("FP0", ['RFA', 'RFA', 'RFA', 'RFA', 'RFA', 'RFA',
'RFB', 'RFB', 'RFB', 'RFB', 'RFB', 'RFB'])
>>> U.get_gpio_src("FP0")
['RFA', 'RFA', 'RFA', 'RFA', 'RFA', 'RFA', 'RFB', 'RFB', 'RFB', 'RFB',
'RFB', 'RFB']
>>> # Make all GPIOs outputs:
>>> U.set_gpio_attr("FP0A", "DDR", 0xFFF)
>>> U.set_gpio_attr("FP0B", "DDR", 0xFFF)
>>> # Control all GPIOs from software (not ATR):
>>> U.set_gpio_attr("FP0A", "CTRL", 0x000)
>>> U.set_gpio_attr("FP0B", "CTRL", 0x000)
>>> # Bottom 3 pins go high from radio A
>>> U.set_gpio_attr("FP0A", "OUT", 0x007)
>>> # Top 3 pins go high from radio B
>>> U.set_gpio_attr("FP0B", "OUT", 0xE00)
Amends the gpio.cpp example to allow switching the source.
Co-authored-by: Brent Stapleton <brent.stapleton@ettus.com>
Diffstat (limited to 'host/lib/usrp/x300')
-rw-r--r-- | host/lib/usrp/x300/x300_mb_controller.cpp | 105 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_mb_controller.hpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_radio_control.cpp | 47 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_regs.hpp | 4 |
4 files changed, 117 insertions, 43 deletions
diff --git a/host/lib/usrp/x300/x300_mb_controller.cpp b/host/lib/usrp/x300/x300_mb_controller.cpp index fd70526ab..28567e62e 100644 --- a/host/lib/usrp/x300/x300_mb_controller.cpp +++ b/host/lib/usrp/x300/x300_mb_controller.cpp @@ -1,5 +1,5 @@ // -// Copyright 2019 Ettus Research, a National Instruments Brand +// Copyright 2019-2020 Ettus Research, a National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -26,7 +26,7 @@ constexpr uint32_t ADC_SELF_TEST_DURATION = 100; // ms // When these regs are fixed, there is another fixme below to actually init the // timekeepers -constexpr uint32_t TK_NUM_TIMEKEEPERS = 12; //Read-only +constexpr uint32_t TK_NUM_TIMEKEEPERS = 12; // Read-only constexpr uint32_t TK_REG_BASE = 100; constexpr uint32_t TK_REG_OFFSET = 48; constexpr uint32_t TK_REG_TICKS_NOW_LO = 0x00; // Read-only @@ -41,6 +41,11 @@ constexpr uint32_t TK_REG_TICKS_PERIOD_HI = 0x20; // Read-Write constexpr char LOG_ID[] = "X300::MB_CTRL"; +constexpr char GPIO_SRC_BANK[] = "FP0"; +constexpr char GPIO_SRC_RFA[] = "RFA"; +constexpr char GPIO_SRC_RFB[] = "RFB"; +constexpr size_t GPIO_SRC_NUM_PINS = 12; + } // namespace @@ -75,7 +80,9 @@ x300_mb_controller::x300_mb_controller(const size_t hw_rev, const size_t num_tks = _zpu_ctrl->peek32(SR_ADDR(SET0_BASE, TK_NUM_TIMEKEEPERS)); for (size_t i = 0; i < num_tks; i++) { - register_timekeeper(i, std::make_shared<x300_timekeeper>(i, _zpu_ctrl, clock_ctrl->get_master_clock_rate())); + register_timekeeper(i, + std::make_shared<x300_timekeeper>( + i, _zpu_ctrl, clock_ctrl->get_master_clock_rate())); } init_gps(); @@ -107,8 +114,7 @@ void x300_mb_controller::x300_timekeeper::set_ticks_now(const uint64_t ticks) get_tk_addr(TK_REG_TICKS_EVENT_LO), narrow_cast<uint32_t>(ticks & 0xFFFFFFFF)); _zpu_ctrl->poke32( get_tk_addr(TK_REG_TICKS_EVENT_HI), narrow_cast<uint32_t>(ticks >> 32)); - _zpu_ctrl->poke32( - get_tk_addr(TK_REG_TICKS_CTRL), narrow_cast<uint32_t>(0x1)); + _zpu_ctrl->poke32(get_tk_addr(TK_REG_TICKS_CTRL), narrow_cast<uint32_t>(0x1)); } void x300_mb_controller::x300_timekeeper::set_ticks_next_pps(const uint64_t ticks) @@ -117,16 +123,15 @@ void x300_mb_controller::x300_timekeeper::set_ticks_next_pps(const uint64_t tick get_tk_addr(TK_REG_TICKS_EVENT_LO), narrow_cast<uint32_t>(ticks & 0xFFFFFFFF)); _zpu_ctrl->poke32( get_tk_addr(TK_REG_TICKS_EVENT_HI), narrow_cast<uint32_t>(ticks >> 32)); - _zpu_ctrl->poke32( - get_tk_addr(TK_REG_TICKS_CTRL), narrow_cast<uint32_t>(0x2)); + _zpu_ctrl->poke32(get_tk_addr(TK_REG_TICKS_CTRL), narrow_cast<uint32_t>(0x2)); } void x300_mb_controller::x300_timekeeper::set_period(const uint64_t period_ns) { _zpu_ctrl->poke32(get_tk_addr(TK_REG_TICKS_PERIOD_LO), narrow_cast<uint32_t>(period_ns & 0xFFFFFFFF)); - _zpu_ctrl->poke32(get_tk_addr(TK_REG_TICKS_PERIOD_HI), - narrow_cast<uint32_t>(period_ns >> 32)); + _zpu_ctrl->poke32( + get_tk_addr(TK_REG_TICKS_PERIOD_HI), narrow_cast<uint32_t>(period_ns >> 32)); } uint32_t x300_mb_controller::x300_timekeeper::get_tk_addr(const uint32_t tk_addr) @@ -247,8 +252,8 @@ void x300_mb_controller::set_clock_source(const std::string& source) .str()); } else { // TODO: Re-enable this warning when we figure out a reliable lock time - // UHD_LOGGER_WARNING("X300::MB_CTRL") << "Reference clock failed to lock to " + - // source + " during device initialization. " << + // UHD_LOGGER_WARNING("X300::MB_CTRL") << "Reference clock failed to lock + // to " + source + " during device initialization. " << // "Check for the lock before operation or ignore this warning if using // another clock source." ; } @@ -311,7 +316,8 @@ void x300_mb_controller::set_sync_source( set_sync_source(sync_args); } -void x300_mb_controller::set_sync_source(const device_addr_t& sync_source) { +void x300_mb_controller::set_sync_source(const device_addr_t& sync_source) +{ if (sync_source.has_key("clock_source")) { set_clock_source(sync_source["clock_source"]); } @@ -338,8 +344,7 @@ std::vector<device_addr_t> x300_mb_controller::get_sync_sources() {"external", "internal"}, {"external", "external"}, {"gpsdo", "gpsdo"}, - {"gpsdo", "internal"} - }; + {"gpsdo", "internal"}}; // Now convert to vector of device_addr_t std::vector<device_addr_t> sync_sources; @@ -484,6 +489,78 @@ bool x300_mb_controller::synchronize(std::vector<mb_controller::sptr>& mb_contro throw uhd::runtime_error(err_str); } +std::vector<std::string> x300_mb_controller::get_gpio_banks() const +{ + return {GPIO_SRC_BANK}; +} + +std::vector<std::string> x300_mb_controller::get_gpio_srcs(const std::string& bank) const +{ + if (bank != GPIO_SRC_BANK) { + UHD_LOG_ERROR(LOG_ID, + "Invalid GPIO source bank: " << bank << ". Only supported bank is " + << GPIO_SRC_BANK); + throw uhd::runtime_error( + std::string("Invalid GPIO source bank: ") + GPIO_SRC_BANK); + } + return {GPIO_SRC_RFA, GPIO_SRC_RFB}; +} + +std::vector<std::string> x300_mb_controller::get_gpio_src(const std::string& bank) +{ + if (bank != GPIO_SRC_BANK) { + UHD_LOG_ERROR(LOG_ID, + "Invalid GPIO source bank: " << bank << ". Only supported bank is " + << GPIO_SRC_BANK); + throw uhd::runtime_error( + std::string("Invalid GPIO source bank: ") + GPIO_SRC_BANK); + } + uint32_t fp_gpio_src = _zpu_ctrl->peek32(SR_ADDR(SET0_BASE, ZPU_RB_FP_GPIO_SRC)); + const auto gpio_srcs = get_gpio_srcs(bank); + std::vector<std::string> gpio_src; + for (size_t ii = 0; ii < GPIO_SRC_NUM_PINS; ++ii) { + const uint32_t this_src = (fp_gpio_src >> (2 * ii)) & 0x3; + if (this_src > 1) { + UHD_LOG_WARNING(LOG_ID, + "get_gpio_src() read back invalid GPIO source index: " + << this_src << ". Falling back to " << (this_src & 0x1)); + } + gpio_src.push_back(gpio_srcs[this_src & 0x1]); + } + return gpio_src; +} + +void x300_mb_controller::set_gpio_src( + const std::string& bank, const std::vector<std::string>& srcs) +{ + if (srcs.size() > GPIO_SRC_NUM_PINS) { + UHD_LOG_WARNING(LOG_ID, "set_gpio_src(): Provided more sources than pins!"); + } + uint32_t fp_gpio_src = _zpu_ctrl->peek32(SR_ADDR(SET0_BASE, ZPU_RB_FP_GPIO_SRC)); + size_t pins_configured = 0; + + const auto gpio_srcs = get_gpio_srcs(bank); + for (auto src : srcs) { + const uint32_t pins = [src]() { + if (src == GPIO_SRC_RFA) { + return 0; + } + if (src == GPIO_SRC_RFB) { + return 1; + } + UHD_LOG_ERROR(LOG_ID, "Invalid GPIO source provided: " << src); + throw uhd::runtime_error("Invalid GPIO source provided!"); + }(); + uint32_t pin_mask = ~(uint32_t(0x3) << (2 * pins_configured)); + fp_gpio_src = (fp_gpio_src & pin_mask) | (pins << 2 * pins_configured); + pins_configured++; + if (pins_configured > GPIO_SRC_NUM_PINS) { + break; + } + } + _zpu_ctrl->poke32(SR_ADDR(SET0_BASE, ZPU_SR_FP_GPIO_SRC), fp_gpio_src); +} + /****************************************************************************** * Private Methods *****************************************************************************/ diff --git a/host/lib/usrp/x300/x300_mb_controller.hpp b/host/lib/usrp/x300/x300_mb_controller.hpp index 53f166a0e..92844f1b9 100644 --- a/host/lib/usrp/x300/x300_mb_controller.hpp +++ b/host/lib/usrp/x300/x300_mb_controller.hpp @@ -120,6 +120,10 @@ public: bool synchronize(std::vector<mb_controller::sptr>& mb_controllers, const uhd::time_spec_t& time_spec = uhd::time_spec_t(0.0), const bool quiet = false); + std::vector<std::string> get_gpio_banks() const; + std::vector<std::string> get_gpio_srcs(const std::string&) const; + std::vector<std::string> get_gpio_src(const std::string&); + void set_gpio_src(const std::string&, const std::vector<std::string>&); private: //! Return a string X300::MB_CTRL#N diff --git a/host/lib/usrp/x300/x300_radio_control.cpp b/host/lib/usrp/x300/x300_radio_control.cpp index c41a19401..48b484467 100644 --- a/host/lib/usrp/x300/x300_radio_control.cpp +++ b/host/lib/usrp/x300/x300_radio_control.cpp @@ -147,27 +147,24 @@ public: _init_codecs(); _x300_mb_control->register_reset_codec_cb([this]() { this->reset_codec(); }); // FP-GPIO - if (_radio_type == PRIMARY) { - RFNOC_LOG_TRACE("Creating FP-GPIO interface..."); - _fp_gpio = gpio_atr::gpio_atr_3000::make(_wb_iface, - x300_regs::SR_FP_GPIO, - x300_regs::RB_FP_GPIO, - x300_regs::PERIPH_REG_OFFSET); - // Create the GPIO banks and attributes, and populate them with some default - // values - // TODO: Do we need this section? Since the _fp_gpio handles state now, we - // don't need to stash values here. We only need this if we want to set - // anything to a default value. - for (const gpio_atr::gpio_attr_map_t::value_type attr : - gpio_atr::gpio_attr_map) { - // TODO: Default values? - if (attr.first == usrp::gpio_atr::GPIO_SRC) { - // Don't set the SRC - // TODO: Remove from the map?? - continue; - } - set_gpio_attr("FP0", usrp::gpio_atr::gpio_attr_map.at(attr.first), 0); + RFNOC_LOG_TRACE("Creating FP-GPIO interface..."); + _fp_gpio = gpio_atr::gpio_atr_3000::make(_wb_iface, + x300_regs::SR_FP_GPIO, + x300_regs::RB_FP_GPIO, + x300_regs::PERIPH_REG_OFFSET); + // Create the GPIO banks and attributes, and populate them with some default + // values + // TODO: Do we need this section? Since the _fp_gpio handles state now, we + // don't need to stash values here. We only need this if we want to set + // anything to a default value. + for (const gpio_atr::gpio_attr_map_t::value_type attr : gpio_atr::gpio_attr_map) { + // TODO: Default values? + if (attr.first == usrp::gpio_atr::GPIO_SRC) { + // Don't set the SRC + // TODO: Remove from the map?? + continue; } + set_gpio_attr("FP0", usrp::gpio_atr::gpio_attr_map.at(attr.first), 0); } // DB Initialization _init_db(); // This does not init the dboards themselves! @@ -855,17 +852,13 @@ public: /*** GPIO API ************************************************************/ std::vector<std::string> get_gpio_banks() const { - std::vector<std::string> banks{"RX", "TX"}; - if (_fp_gpio) { - banks.push_back("FP0"); - } - return banks; + return {"RX", "TX", "FP0"}; } void set_gpio_attr( const std::string& bank, const std::string& attr, const uint32_t value) { - if (bank == "FP0" and _fp_gpio) { + if (bank == "FP0") { _fp_gpio->set_gpio_attr(usrp::gpio_atr::gpio_attr_rev_map.at(attr), value); return; } @@ -909,7 +902,7 @@ public: uint32_t get_gpio_attr(const std::string& bank, const std::string& attr) { - if (bank == "FP0" and _fp_gpio) { + if (bank == "FP0") { return _fp_gpio->get_attr_reg(usrp::gpio_atr::gpio_attr_rev_map.at(attr)); } if (bank.size() >= 2 and bank[1] == 'X') { diff --git a/host/lib/usrp/x300/x300_regs.hpp b/host/lib/usrp/x300/x300_regs.hpp index 64ff63d77..86ffd46c4 100644 --- a/host/lib/usrp/x300/x300_regs.hpp +++ b/host/lib/usrp/x300/x300_regs.hpp @@ -35,8 +35,7 @@ static const int ZPU_SR_REF_FREQ = 04; static const int ZPU_SR_SPI = 32; static const int ZPU_SR_ETHINT0 = 40; static const int ZPU_SR_ETHINT1 = 56; -static const int ZPU_SR_DRAM_FIFO0 = 72; -static const int ZPU_SR_DRAM_FIFO1 = 80; +static const int ZPU_SR_FP_GPIO_SRC = 72; // reset bits #define ZPU_SR_SW_RST_ETH_PHY (1 << 0) @@ -51,6 +50,7 @@ static const int ZPU_RB_NUM_CE = 7; static const int ZPU_RB_GIT_HASH = 10; static const int ZPU_RB_SFP0_TYPE = 4; static const int ZPU_RB_SFP1_TYPE = 5; +static const int ZPU_RB_FP_GPIO_SRC = 13; static const uint32_t RB_SFP_1G_ETH = 0; static const uint32_t RB_SFP_10G_ETH = 1; |