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/x300_radio_control.cpp | |
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/x300_radio_control.cpp')
-rw-r--r-- | host/lib/usrp/x300/x300_radio_control.cpp | 47 |
1 files changed, 20 insertions, 27 deletions
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') { |