From 568ee85778bcf0ef304b5f330ee71c113f403ed8 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Mon, 25 Oct 2021 15:54:25 -0500 Subject: host: Add gpio_voltage discoverable feature --- host/include/uhd/features/discoverable_feature.hpp | 1 + host/include/uhd/features/gpio_power_iface.hpp | 84 ++++++++++++++++++++++ .../uhdlib/usrp/common/mpmd_mb_controller.hpp | 21 ++++++ host/lib/usrp/mpmd/mpmd_mb_controller.cpp | 41 +++++++++++ 4 files changed, 147 insertions(+) create mode 100644 host/include/uhd/features/gpio_power_iface.hpp diff --git a/host/include/uhd/features/discoverable_feature.hpp b/host/include/uhd/features/discoverable_feature.hpp index b1a03eaea..e56c3f6e3 100644 --- a/host/include/uhd/features/discoverable_feature.hpp +++ b/host/include/uhd/features/discoverable_feature.hpp @@ -35,6 +35,7 @@ public: ADC_SELF_CALIBRATION, REF_CLK_CALIBRATION, TRIG_IO_MODE, + GPIO_POWER, }; virtual ~discoverable_feature() = default; diff --git a/host/include/uhd/features/gpio_power_iface.hpp b/host/include/uhd/features/gpio_power_iface.hpp new file mode 100644 index 000000000..5f236cfec --- /dev/null +++ b/host/include/uhd/features/gpio_power_iface.hpp @@ -0,0 +1,84 @@ +// +// Copyright 2021 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#pragma once + +#include +#include +#include +#include + +namespace uhd { namespace features { + +/*! Interface to provide access to configuring the voltage level and external + * power export configurations of GPIO banks. + */ +class gpio_power_iface : public discoverable_feature +{ +public: + using sptr = std::shared_ptr; + + static discoverable_feature::feature_id_t get_feature_id() + { + return discoverable_feature::GPIO_POWER; + } + + std::string get_feature_name() const + { + return "GPIO power configuration"; + } + + virtual ~gpio_power_iface() = default; + + /*! Return what I/O voltage levels are supported on the given port. Voltages + * use a V in place of the decimal point - typical values include "1V8" for + * 1.8 volts, "3V3" for 3.3 volts, et cetera. + * + * \param port Port to list supported voltages for. + * \return A vector of supported voltage levels. + */ + virtual std::vector get_supported_voltages( + const std::string& port) const = 0; + + /*! Set the I/O voltage on the given port to the given value. + * + * \param port Port to set the voltage on. + * \param voltage Voltage level to set. See \ref get_supported_voltages for a list + * of supported voltages. + */ + virtual void set_port_voltage( + const std::string& port, const std::string& voltage) = 0; + + /*! Gets the current I/O voltage level that the port is set to. + * + * \param port Port to retrieve the voltage level for + * \return The voltage level for the given port + */ + virtual std::string get_port_voltage(const std::string& port) const = 0; + + /*! Enables or disables the power supply exposed through the GPIO ports. The + * GPIO lines will function without external power enabled - the power supply + * is simply to provide a means for external circuitry to receive power from + * the device. See your device's documentation for more information on the + * voltage and current specifications of the external power supply. + * + * \param port The port to export power through. + * \param enable true to enable power, false to disable. + */ + virtual void set_external_power(const std::string& port, bool enable) = 0; + + /*! Retrieve the status of the external power on the given port. The status + * can be one of three values: + * "OFF" - External power is disabled (the default) + * "ON" - External power is on and functioning normally + * "FAULT" - The external power supply has encountered a fault condition. + * + * \param port Port to retrieve status from + */ + virtual std::string get_external_power_status(const std::string& port) const = 0; +}; + +}} // namespace uhd::features diff --git a/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp b/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp index 2d751a4e5..f4f6e0ba7 100644 --- a/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp +++ b/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include namespace uhd { namespace rfnoc { @@ -169,9 +171,28 @@ public: uhd::usrp::mpmd_rpc_iface::sptr _rpcc; }; + class gpio_power : public uhd::features::gpio_power_iface + { + public: + using sptr = std::shared_ptr; + + gpio_power(uhd::usrp::dio_rpc_iface::sptr rpcc, const std::vector& ports); + + std::vector get_supported_voltages(const std::string& port) const override; + void set_port_voltage(const std::string& port, const std::string& voltage) override; + std::string get_port_voltage(const std::string& port) const override; + void set_external_power(const std::string& port, bool enable) override; + std::string get_external_power_status(const std::string& port) const override; + + private: + uhd::usrp::dio_rpc_iface::sptr _rpcc; + const std::vector _ports; + }; + fpga_onload::sptr _fpga_onload; ref_clk_calibration::sptr _ref_clk_cal; trig_io_mode::sptr _trig_io_mode; + gpio_power::sptr _gpio_power; }; }} // namespace uhd::rfnoc diff --git a/host/lib/usrp/mpmd/mpmd_mb_controller.cpp b/host/lib/usrp/mpmd/mpmd_mb_controller.cpp index b79abcee0..cdc86b086 100644 --- a/host/lib/usrp/mpmd/mpmd_mb_controller.cpp +++ b/host/lib/usrp/mpmd/mpmd_mb_controller.cpp @@ -74,6 +74,41 @@ void mpmd_mb_controller::trig_io_mode::set_trig_io_mode(const uhd::trig_io_mode_ } } +mpmd_mb_controller::gpio_power::gpio_power( + uhd::usrp::dio_rpc_iface::sptr rpcc, const std::vector& ports) + : _rpcc(rpcc), _ports(ports) +{} + +std::vector mpmd_mb_controller::gpio_power::get_supported_voltages( + const std::string& port) const +{ + return _rpcc->dio_get_supported_voltage_levels(port); +} + +void mpmd_mb_controller::gpio_power::set_port_voltage( + const std::string& port, const std::string& voltage) +{ + _rpcc->dio_set_voltage_level(port, voltage); +} + +std::string mpmd_mb_controller::gpio_power::get_port_voltage( + const std::string& port) const +{ + return _rpcc->dio_get_voltage_level(port); +} + +void mpmd_mb_controller::gpio_power::set_external_power( + const std::string& port, bool enable) +{ + _rpcc->dio_set_external_power(port, enable); +} + +std::string mpmd_mb_controller::gpio_power::get_external_power_status( + const std::string& port) const +{ + return _rpcc->dio_get_external_power_state(port); +} + mpmd_mb_controller::mpmd_mb_controller( uhd::usrp::mpmd_rpc_iface::sptr rpcc, uhd::device_addr_t device_info) : _rpc(rpcc), _device_info(device_info) @@ -106,6 +141,12 @@ mpmd_mb_controller::mpmd_mb_controller( _trig_io_mode = std::make_shared(_rpc); register_feature(_trig_io_mode); } + + if (_rpc->supports_feature("gpio_power")) { + _gpio_power = std::make_shared( + std::make_shared(get_rpc_client()), _gpio_banks); + register_feature(_gpio_power); + } } /****************************************************************************** -- cgit v1.2.3