From 0cf54ce07335f60642a14df7e6107422a5aeb9a0 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 14 Nov 2019 13:12:20 -0800 Subject: mpm/mpmd: Expose APIs to drive GPIO sources The N310 has a feature that allows the front panel GPIOs to be driven by various sources: The PS, or any of the radio channels. The MPM-based APIs did not expose any way to change that. Changes: - Add MPM APIs to PeripheralManagerBase and n3xx classes - Improve comments and explanations - Add host-side hooks into these new APIs in mpmd_mb_controller - Implement these APIs for N3xx The N3xx devices will have the option to set the GPIO source to "PS", or to one of "RF0", "RF1", "RF2", "RF3" (if there are four channels; the N300 and N320 can only go up to RF1). Note: The N310 radio does not have separate FP-GPIO banks for channels 0 and 1, which needs to be fixed in a separate commit. --- host/lib/usrp/mpmd/mpmd_mb_controller.cpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'host/lib/usrp') diff --git a/host/lib/usrp/mpmd/mpmd_mb_controller.cpp b/host/lib/usrp/mpmd/mpmd_mb_controller.cpp index 13e57b273..9aa61a5a8 100644 --- a/host/lib/usrp/mpmd/mpmd_mb_controller.cpp +++ b/host/lib/usrp/mpmd/mpmd_mb_controller.cpp @@ -23,10 +23,18 @@ mpmd_mb_controller::mpmd_mb_controller( register_timekeeper(tk_idx, std::make_shared(tk_idx, _rpc)); } + // Enumerate sensors auto sensor_list = _rpc->request_with_token>("get_mb_sensors"); UHD_LOG_DEBUG("MPMD", "Found " << sensor_list.size() << " motherboard sensors."); _sensor_names.insert(sensor_list.cbegin(), sensor_list.cend()); + + // Enumerate GPIO banks that are under mb_controller control + _gpio_banks = _rpc->request_with_token>("get_gpio_banks"); + for (const auto& bank : _gpio_banks) { + _gpio_srcs.insert({bank, + _rpc->request_with_token>("get_gpio_srcs", bank)}); + } } /****************************************************************************** @@ -174,3 +182,35 @@ uhd::usrp::mboard_eeprom_t mpmd_mb_controller::get_eeprom() return mb_eeprom_dict; } +std::vector mpmd_mb_controller::get_gpio_banks() const +{ + return _gpio_banks; +} + +std::vector mpmd_mb_controller::get_gpio_srcs(const std::string& bank) const +{ + if (!_gpio_srcs.count(bank)) { + UHD_LOG_ERROR("MPMD", "Invalid GPIO bank: `" << bank << "'"); + throw uhd::key_error(std::string("Invalid GPIO bank: ") + bank); + } + return _gpio_srcs.at(bank); +} + +std::vector mpmd_mb_controller::get_gpio_src(const std::string& bank) +{ + if (!_gpio_srcs.count(bank)) { + UHD_LOG_ERROR("MPMD", "Invalid GPIO bank: `" << bank << "'"); + throw uhd::key_error(std::string("Invalid GPIO bank: ") + bank); + } + return _rpc->request_with_token>("get_gpio_srcs", bank); +} + +void mpmd_mb_controller::set_gpio_src( + const std::string& bank, const std::vector& src) +{ + if (!_gpio_srcs.count(bank)) { + UHD_LOG_ERROR("MPMD", "Invalid GPIO bank: `" << bank << "'"); + throw uhd::key_error(std::string("Invalid GPIO bank: ") + bank); + } + _rpc->notify_with_token("set_gpio_src", bank, src); +} -- cgit v1.2.3