host: Add gpio_voltage discoverable feature

This commit is contained in:
Lane Kolbly 2021-10-25 15:54:25 -05:00 committed by Aaron Rossetto
parent 0bb02043a3
commit 568ee85778
4 changed files with 147 additions and 0 deletions

View File

@ -35,6 +35,7 @@ public:
ADC_SELF_CALIBRATION,
REF_CLK_CALIBRATION,
TRIG_IO_MODE,
GPIO_POWER,
};
virtual ~discoverable_feature() = default;

View File

@ -0,0 +1,84 @@
//
// Copyright 2021 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/features/discoverable_feature.hpp>
#include <memory>
#include <string>
#include <vector>
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<gpio_power_iface>;
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<std::string> 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

View File

@ -6,6 +6,7 @@
#pragma once
#include <uhd/features/gpio_power_iface.hpp>
#include <uhd/features/ref_clk_calibration_iface.hpp>
#include <uhd/features/trig_io_mode_iface.hpp>
#include <uhd/rfnoc/mb_controller.hpp>
@ -13,6 +14,7 @@
#include <uhdlib/features/fpga_load_notification_iface.hpp>
#include <uhdlib/usrp/common/rpc.hpp>
#include <uhdlib/utils/rpc.hpp>
#include <map>
#include <memory>
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>;
gpio_power(uhd::usrp::dio_rpc_iface::sptr rpcc, const std::vector<std::string>& ports);
std::vector<std::string> 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<std::string> _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

View File

@ -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<std::string>& ports)
: _rpcc(rpcc), _ports(ports)
{}
std::vector<std::string> 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<trig_io_mode>(_rpc);
register_feature(_trig_io_mode);
}
if (_rpc->supports_feature("gpio_power")) {
_gpio_power = std::make_shared<gpio_power>(
std::make_shared<uhd::usrp::dio_rpc>(get_rpc_client()), _gpio_banks);
register_feature(_gpio_power);
}
}
/******************************************************************************