From bc8713e7af36377abe1c0e969c095c6b627b00c7 Mon Sep 17 00:00:00 2001 From: Martin Anderseck Date: Thu, 17 Mar 2022 13:34:15 +0100 Subject: host: SPI: Read number of supported SPI slaves from device Add support for reading the number of supported SPI slaves from the device. This has become necessary because we may have bitfiles with different capabilities and we want to report this back correctly. --- host/lib/usrp/x400/x400_radio_control.cpp | 41 ++++++++++++++++++++----------- host/lib/usrp/x400/x400_radio_control.hpp | 3 +++ 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'host/lib/usrp/x400') diff --git a/host/lib/usrp/x400/x400_radio_control.cpp b/host/lib/usrp/x400/x400_radio_control.cpp index ef2d6bd21..59207d486 100644 --- a/host/lib/usrp/x400/x400_radio_control.cpp +++ b/host/lib/usrp/x400/x400_radio_control.cpp @@ -191,20 +191,32 @@ x400_radio_control_impl::x400_radio_control_impl(make_args_ptr make_args) auto gpio_port_mapper = std::shared_ptr( new uhd::rfnoc::x400::x400_gpio_port_mapping); - auto spicore = uhd::cores::spi_core_4000::make( - [this](const uint32_t addr, const uint32_t data) { - regs().poke32(addr, data, get_command_time(0)); - }, - [this]( - const uint32_t addr) { return regs().peek32(addr, get_command_time(0)); }, - x400_regs::SPI_SLAVE_CFG, - x400_regs::SPI_TRANSACTION_CFG_REG, - x400_regs::SPI_TRANSACTION_GO_REG, - x400_regs::SPI_STATUS_REG, - gpio_port_mapper); - - _spi_getter_iface = std::make_shared(spicore); - register_feature(_spi_getter_iface); + + // Check if SPI is available as GPIO source, otherwise don't register + // SPI_GETTER_IFace + auto gpio_srcs = _mb_control->get_gpio_srcs("GPIO0"); + if (std::count(gpio_srcs.begin(), gpio_srcs.end(), "DB0_SPI") > 0) { + auto spicore = uhd::cores::spi_core_4000::make( + [this](const uint32_t addr, const uint32_t data) { + regs().poke32(addr, data, get_command_time(0)); + }, + [this](const uint32_t addr) { + return regs().peek32(addr, get_command_time(0)); + }, + x400_regs::SPI_SLAVE_CFG, + x400_regs::SPI_TRANSACTION_CFG_REG, + x400_regs::SPI_TRANSACTION_GO_REG, + x400_regs::SPI_STATUS_REG, + x400_regs::SPI_CONTROLLER_INFO_REG, + gpio_port_mapper); + + _spi_getter_iface = std::make_shared(spicore); + register_feature(_spi_getter_iface); + } else { + UHD_LOG_INFO("x400_radio_control", + "SPI functionality not available in this FPGA image. Please update to at " + "least version 7.7 to use SPI."); + } } } @@ -816,5 +828,4 @@ std::string x400_radio_control_impl::get_dboard_fe_from_chan( UHD_RFNOC_BLOCK_REGISTER_FOR_DEVICE_DIRECT( x400_radio_control, RADIO_BLOCK, X400, "Radio", true, "radio_clk", "ctrl_clk") - }} // namespace uhd::rfnoc diff --git a/host/lib/usrp/x400/x400_radio_control.hpp b/host/lib/usrp/x400/x400_radio_control.hpp index cd45291bc..7fcf9a12a 100644 --- a/host/lib/usrp/x400/x400_radio_control.hpp +++ b/host/lib/usrp/x400/x400_radio_control.hpp @@ -54,6 +54,9 @@ constexpr uint32_t SPI_TRANSACTION_GO_REG = SPI_SLAVE_CFG + 0x0014; //! Base address for SPI_STATUS Register constexpr uint32_t SPI_STATUS_REG = SPI_SLAVE_CFG + 0x0018; +//! Base address for SPI_CONTROLLER_INFO Register +constexpr uint32_t SPI_CONTROLLER_INFO_REG = SPI_SLAVE_CFG + 0x001C; + } // namespace x400_regs class x400_radio_control_impl : public radio_control_impl -- cgit v1.2.3