diff options
Diffstat (limited to 'host/lib/usrp/b200')
-rw-r--r-- | host/lib/usrp/b200/b200_cores.cpp | 29 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_cores.hpp | 26 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_iface.cpp | 527 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_iface.hpp | 103 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_image_loader.cpp | 132 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_impl.cpp | 1110 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_impl.hpp | 183 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_io_impl.cpp | 20 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_mb_eeprom.cpp | 56 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_regs.hpp | 136 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_uart.cpp | 63 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_uart.hpp | 2 |
12 files changed, 1280 insertions, 1107 deletions
diff --git a/host/lib/usrp/b200/b200_cores.cpp b/host/lib/usrp/b200/b200_cores.cpp index 688af2535..3c55d3995 100644 --- a/host/lib/usrp/b200/b200_cores.cpp +++ b/host/lib/usrp/b200/b200_cores.cpp @@ -6,23 +6,20 @@ // #include "b200_cores.hpp" -#include "b200_regs.hpp" #include "b200_impl.hpp" +#include "b200_regs.hpp" #include <mutex> -b200_local_spi_core::b200_local_spi_core( - uhd::wb_iface::sptr iface, - perif_t default_perif) : - _spi_core(spi_core_3000::make(iface, TOREG(SR_CORE_SPI), RB32_CORE_SPI)), - _current_perif(default_perif), - _last_perif(default_perif) +b200_local_spi_core::b200_local_spi_core(uhd::wb_iface::sptr iface, perif_t default_perif) + : _spi_core(spi_core_3000::make(iface, TOREG(SR_CORE_SPI), RB32_CORE_SPI)) + , _current_perif(default_perif) + , _last_perif(default_perif) { change_perif(default_perif); } -uint32_t b200_local_spi_core::transact_spi( - int which_slave, - const uhd::spi_config_t &config, +uint32_t b200_local_spi_core::transact_spi(int which_slave, + const uhd::spi_config_t& config, uint32_t data, size_t num_bits, bool readback) @@ -34,15 +31,15 @@ uint32_t b200_local_spi_core::transact_spi( void b200_local_spi_core::change_perif(perif_t perif) { std::lock_guard<std::mutex> lock(_mutex); - _last_perif = _current_perif; + _last_perif = _current_perif; _current_perif = perif; switch (_current_perif) { case CODEC: - _spi_core->set_divider(B200_BUS_CLOCK_RATE/AD9361_SPI_RATE); + _spi_core->set_divider(B200_BUS_CLOCK_RATE / AD9361_SPI_RATE); break; case PLL: - _spi_core->set_divider(B200_BUS_CLOCK_RATE/ADF4001_SPI_RATE); + _spi_core->set_divider(B200_BUS_CLOCK_RATE / ADF4001_SPI_RATE); break; } } @@ -52,9 +49,8 @@ void b200_local_spi_core::restore_perif() change_perif(_last_perif); } -b200_ref_pll_ctrl::b200_ref_pll_ctrl(b200_local_spi_core::sptr spi) : - uhd::usrp::adf4001_ctrl(spi, ADF4001_SLAVENO), - _spi(spi) +b200_ref_pll_ctrl::b200_ref_pll_ctrl(b200_local_spi_core::sptr spi) + : uhd::usrp::adf4001_ctrl(spi, ADF4001_SLAVENO), _spi(spi) { } @@ -71,4 +67,3 @@ b200_local_spi_core::sptr b200_local_spi_core::make( { return sptr(new b200_local_spi_core(iface, default_perif)); } - diff --git a/host/lib/usrp/b200/b200_cores.hpp b/host/lib/usrp/b200/b200_cores.hpp index 324938a73..7054fd068 100644 --- a/host/lib/usrp/b200/b200_cores.hpp +++ b/host/lib/usrp/b200/b200_cores.hpp @@ -10,25 +10,22 @@ #define INCLUDED_B200_CORES_HPP #include <uhd/utils/noncopyable.hpp> -#include <uhdlib/usrp/cores/spi_core_3000.hpp> #include <uhdlib/usrp/common/adf4001_ctrl.hpp> +#include <uhdlib/usrp/cores/spi_core_3000.hpp> #include <memory> #include <mutex> -class b200_local_spi_core : uhd::noncopyable, public uhd::spi_iface { - +class b200_local_spi_core : uhd::noncopyable, public uhd::spi_iface +{ public: typedef std::shared_ptr<b200_local_spi_core> sptr; - enum perif_t { - CODEC, PLL - }; + enum perif_t { CODEC, PLL }; b200_local_spi_core(uhd::wb_iface::sptr iface, perif_t default_perif); - virtual uint32_t transact_spi( - int which_slave, - const uhd::spi_config_t &config, + virtual uint32_t transact_spi(int which_slave, + const uhd::spi_config_t& config, uint32_t data, size_t num_bits, bool readback); @@ -39,13 +36,14 @@ public: static sptr make(uhd::wb_iface::sptr iface, perif_t default_perif = CODEC); private: - spi_core_3000::sptr _spi_core; - perif_t _current_perif; - perif_t _last_perif; - std::mutex _mutex; + spi_core_3000::sptr _spi_core; + perif_t _current_perif; + perif_t _last_perif; + std::mutex _mutex; }; -class b200_ref_pll_ctrl : public uhd::usrp::adf4001_ctrl { +class b200_ref_pll_ctrl : public uhd::usrp::adf4001_ctrl +{ public: typedef std::shared_ptr<b200_ref_pll_ctrl> sptr; diff --git a/host/lib/usrp/b200/b200_iface.cpp b/host/lib/usrp/b200/b200_iface.cpp index c2bd9bace..2efc9efb5 100644 --- a/host/lib/usrp/b200/b200_iface.cpp +++ b/host/lib/usrp/b200/b200_iface.cpp @@ -27,8 +27,7 @@ //! libusb_error_name is only in newer API #ifndef HAVE_LIBUSB_ERROR_NAME - #define libusb_error_name(code) \ - str(boost::format("LIBUSB_ERROR_CODE %d") % code) +# define libusb_error_name(code) str(boost::format("LIBUSB_ERROR_CODE %d") % code) #endif using namespace uhd; @@ -41,34 +40,32 @@ const static uint8_t FX3_FIRMWARE_LOAD = 0xA0; // 32 KB - 256 bytes for EEPROM storage constexpr size_t BOOTLOADER_MAX_SIZE = 32512; -const static uint8_t VRT_VENDOR_OUT = (LIBUSB_REQUEST_TYPE_VENDOR - | LIBUSB_ENDPOINT_OUT); -const static uint8_t VRT_VENDOR_IN = (LIBUSB_REQUEST_TYPE_VENDOR - | LIBUSB_ENDPOINT_IN); -const static uint8_t B200_VREQ_FPGA_START = 0x02; -const static uint8_t B200_VREQ_FPGA_DATA = 0x12; -const static uint8_t B200_VREQ_GET_COMPAT = 0x15; +const static uint8_t VRT_VENDOR_OUT = (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT); +const static uint8_t VRT_VENDOR_IN = (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN); +const static uint8_t B200_VREQ_FPGA_START = 0x02; +const static uint8_t B200_VREQ_FPGA_DATA = 0x12; +const static uint8_t B200_VREQ_GET_COMPAT = 0x15; const static uint8_t B200_VREQ_SET_FPGA_HASH = 0x1C; const static uint8_t B200_VREQ_GET_FPGA_HASH = 0x1D; -const static uint8_t B200_VREQ_SET_FW_HASH = 0x1E; -const static uint8_t B200_VREQ_GET_FW_HASH = 0x1F; -const static uint8_t B200_VREQ_LOOP = 0x22; -const static uint8_t B200_VREQ_FPGA_CONFIG = 0x55; -//const static uint8_t B200_VREQ_FPGA_RESET = 0x62; -const static uint8_t B200_VREQ_GPIF_RESET = 0x72; -const static uint8_t B200_VREQ_GET_USB = 0x80; -const static uint8_t B200_VREQ_GET_STATUS = 0x83; -const static uint8_t B200_VREQ_FX3_RESET = 0x99; +const static uint8_t B200_VREQ_SET_FW_HASH = 0x1E; +const static uint8_t B200_VREQ_GET_FW_HASH = 0x1F; +const static uint8_t B200_VREQ_LOOP = 0x22; +const static uint8_t B200_VREQ_FPGA_CONFIG = 0x55; +// const static uint8_t B200_VREQ_FPGA_RESET = 0x62; +const static uint8_t B200_VREQ_GPIF_RESET = 0x72; +const static uint8_t B200_VREQ_GET_USB = 0x80; +const static uint8_t B200_VREQ_GET_STATUS = 0x83; +const static uint8_t B200_VREQ_FX3_RESET = 0x99; const static uint8_t B200_VREQ_EEPROM_WRITE = 0xBA; -const static uint8_t B200_VREQ_EEPROM_READ = 0xBB; +const static uint8_t B200_VREQ_EEPROM_READ = 0xBB; -const static uint8_t FX3_STATE_UNDEFINED = 0x00; -const static uint8_t FX3_STATE_FPGA_READY = 0x01; +const static uint8_t FX3_STATE_UNDEFINED = 0x00; +const static uint8_t FX3_STATE_FPGA_READY = 0x01; const static uint8_t FX3_STATE_CONFIGURING_FPGA = 0x02; -const static uint8_t FX3_STATE_BUSY = 0x03; -const static uint8_t FX3_STATE_RUNNING = 0x04; -const static uint8_t FX3_STATE_UNCONFIGURED = 0x05; -const static uint8_t FX3_STATE_ERROR = 0x06; +const static uint8_t FX3_STATE_BUSY = 0x03; +const static uint8_t FX3_STATE_RUNNING = 0x04; +const static uint8_t FX3_STATE_UNCONFIGURED = 0x05; +const static uint8_t FX3_STATE_ERROR = 0x06; const static int VREQ_MAX_SIZE_USB2 = 64; const static int VREQ_MAX_SIZE_USB3 = 512; @@ -87,13 +84,13 @@ typedef uint32_t hash_type; * \param filename file used to generate hash value * \return hash value in a uint32_t type */ -static hash_type generate_hash(const char *filename) +static hash_type generate_hash(const char* filename) { if (filename == NULL) return hash_type(0); std::ifstream file(filename); - if (not file){ + if (not file) { throw uhd::io_error(std::string("cannot open input file ") + filename); } @@ -103,16 +100,16 @@ static hash_type generate_hash(const char *filename) long long count = 0; while (file.get(ch)) { count++; - //hash algorithm derived from boost hash_combine - //http://www.boost.org/doc/libs/1_35_0/doc/html/boost/hash_combine_id241013.html - hash ^= ch + 0x9e3779b9 + (hash<<6) + (hash>>2); + // hash algorithm derived from boost hash_combine + // http://www.boost.org/doc/libs/1_35_0/doc/html/boost/hash_combine_id241013.html + hash ^= ch + 0x9e3779b9 + (hash << 6) + (hash >> 2); } - if (count == 0){ + if (count == 0) { throw uhd::io_error(std::string("empty input file ") + filename); } - if (not file.eof()){ + if (not file.eof()) { throw uhd::io_error(std::string("file error ") + filename); } @@ -124,45 +121,47 @@ static hash_type generate_hash(const char *filename) /*********************************************************************** * The implementation class **********************************************************************/ -class b200_iface_impl : public b200_iface{ +class b200_iface_impl : public b200_iface +{ public: - - b200_iface_impl(usb_control::sptr usb_ctrl): - _usb_ctrl(usb_ctrl) { - //NOP + b200_iface_impl(usb_control::sptr usb_ctrl) : _usb_ctrl(usb_ctrl) + { + // NOP } int fx3_control_write(uint8_t request, - uint16_t value, - uint16_t index, - unsigned char *buff, - uint16_t length, - uint32_t timeout = 0) { - return _usb_ctrl->submit(VRT_VENDOR_OUT, // bmReqeustType - request, // bRequest - value, // wValue - index, // wIndex - buff, // data - length, // wLength - timeout); // timeout + uint16_t value, + uint16_t index, + unsigned char* buff, + uint16_t length, + uint32_t timeout = 0) + { + return _usb_ctrl->submit(VRT_VENDOR_OUT, // bmReqeustType + request, // bRequest + value, // wValue + index, // wIndex + buff, // data + length, // wLength + timeout); // timeout } int fx3_control_read(uint8_t request, - uint16_t value, - uint16_t index, - unsigned char *buff, - uint16_t length, - uint32_t timeout = 0) { - return _usb_ctrl->submit(VRT_VENDOR_IN, // bmReqeustType - request, // bRequest - value, // wValue - index, // wIndex - buff, // data - length, // wLength - timeout); // timeout + uint16_t value, + uint16_t index, + unsigned char* buff, + uint16_t length, + uint32_t timeout = 0) + { + return _usb_ctrl->submit(VRT_VENDOR_IN, // bmReqeustType + request, // bRequest + value, // wValue + index, // wIndex + buff, // data + length, // wLength + timeout); // timeout } - void write_i2c(UHD_UNUSED(uint16_t addr), UHD_UNUSED(const byte_vector_t &bytes)) + void write_i2c(UHD_UNUSED(uint16_t addr), UHD_UNUSED(const byte_vector_t& bytes)) { throw uhd::not_implemented_error("b200 write i2c"); } @@ -173,33 +172,43 @@ public: throw uhd::not_implemented_error("b200 read i2c"); } - void write_eeprom(uint16_t addr, uint16_t offset, - const byte_vector_t &bytes) { + void write_eeprom(uint16_t addr, uint16_t offset, const byte_vector_t& bytes) + { int ret = fx3_control_write(B200_VREQ_EEPROM_WRITE, - 0, offset | (uint16_t(addr) << 8), - (unsigned char *) &bytes[0], - bytes.size()); + 0, + offset | (uint16_t(addr) << 8), + (unsigned char*)&bytes[0], + bytes.size()); if (ret < 0) - throw uhd::io_error((boost::format("Failed to write EEPROM (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to write EEPROM (%d: %s)") % ret + % libusb_error_name(ret)) + .str()); else if ((size_t)ret != bytes.size()) - throw uhd::io_error((boost::format("Short write on write EEPROM (expecting: %d, returned: %d)") % bytes.size() % ret).str()); + throw uhd::io_error(( + boost::format("Short write on write EEPROM (expecting: %d, returned: %d)") + % bytes.size() % ret) + .str()); } - byte_vector_t read_eeprom( - uint16_t addr, - uint16_t offset, - size_t num_bytes) { + byte_vector_t read_eeprom(uint16_t addr, uint16_t offset, size_t num_bytes) + { byte_vector_t recv_bytes(num_bytes); int bytes_read = fx3_control_read(B200_VREQ_EEPROM_READ, - 0, offset | (uint16_t(addr) << 8), - (unsigned char*) &recv_bytes[0], - num_bytes); + 0, + offset | (uint16_t(addr) << 8), + (unsigned char*)&recv_bytes[0], + num_bytes); if (bytes_read < 0) - throw uhd::io_error((boost::format("Failed to read EEPROM (%d: %s)") % bytes_read % libusb_error_name(bytes_read)).str()); + throw uhd::io_error((boost::format("Failed to read EEPROM (%d: %s)") + % bytes_read % libusb_error_name(bytes_read)) + .str()); else if ((size_t)bytes_read != num_bytes) - throw uhd::io_error((boost::format("Short read on read EEPROM (expecting: %d, returned: %d)") % num_bytes % bytes_read).str()); + throw uhd::io_error( + (boost::format("Short read on read EEPROM (expecting: %d, returned: %d)") + % num_bytes % bytes_read) + .str()); return recv_bytes; } @@ -207,25 +216,27 @@ public: void load_firmware(const std::string filestring, UHD_UNUSED(bool force) = false) { if (load_img_msg) { - UHD_LOGGER_INFO("B200") << "Loading firmware image: " - << filestring << "..."; + UHD_LOGGER_INFO("B200") << "Loading firmware image: " << filestring << "..."; } ihex_reader file_reader(filestring); try { - file_reader.read( - std::bind( - &b200_iface_impl::fx3_control_write, this, - FX3_FIRMWARE_LOAD, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, 0 - ) - ); - } catch (const uhd::io_error &e) { - throw uhd::io_error(str(boost::format("Could not load firmware: \n%s") % e.what())); + file_reader.read(std::bind(&b200_iface_impl::fx3_control_write, + this, + FX3_FIRMWARE_LOAD, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3, + std::placeholders::_4, + 0)); + } catch (const uhd::io_error& e) { + throw uhd::io_error( + str(boost::format("Could not load firmware: \n%s") % e.what())); } - //TODO - //usrp_set_firmware_hash(hash); //set hash before reset + // TODO + // usrp_set_firmware_hash(hash); //set hash before reset /* Success! Let the system settle. */ // TODO: Replace this with a polling loop in the FX3, or find out @@ -233,33 +244,47 @@ public: std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } - void reset_fx3(void) { + void reset_fx3(void) + { unsigned char data[4]; memset(data, 0x00, sizeof(data)); const int bytes_to_send = sizeof(data); int ret = fx3_control_write(B200_VREQ_FX3_RESET, 0x00, 0x00, data, bytes_to_send); if (ret < 0) - throw uhd::io_error((boost::format("Failed to reset FX3 (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to reset FX3 (%d: %s)") % ret + % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_send) - throw uhd::io_error((boost::format("Short write on reset FX3 (expecting: %d, returned: %d)") % bytes_to_send % ret).str()); + throw uhd::io_error( + (boost::format("Short write on reset FX3 (expecting: %d, returned: %d)") + % bytes_to_send % ret) + .str()); } - void reset_gpif(void) { + void reset_gpif(void) + { unsigned char data[4]; memset(data, 0x00, sizeof(data)); const int bytes_to_send = sizeof(data); - int ret = fx3_control_write(B200_VREQ_GPIF_RESET, 0x00, 0x00, data, bytes_to_send); + int ret = + fx3_control_write(B200_VREQ_GPIF_RESET, 0x00, 0x00, data, bytes_to_send); if (ret < 0) - throw uhd::io_error((boost::format("Failed to reset GPIF (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to reset GPIF (%d: %s)") % ret + % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_send) - throw uhd::io_error((boost::format("Short write on reset GPIF (expecting: %d, returned: %d)") % bytes_to_send % ret).str()); + throw uhd::io_error( + (boost::format("Short write on reset GPIF (expecting: %d, returned: %d)") + % bytes_to_send % ret) + .str()); } - void set_fpga_reset_pin(const bool reset) { + void set_fpga_reset_pin(const bool reset) + { unsigned char data[4]; - memset(data, (reset)? 0xFF : 0x00, sizeof(data)); + memset(data, (reset) ? 0xFF : 0x00, sizeof(data)); UHD_THROW_INVALID_CODE_PATH(); @@ -268,113 +293,178 @@ public: /* const int bytes_to_send = sizeof(data); - int ret = fx3_control_write(B200_VREQ_FPGA_RESET, 0x00, 0x00, data, bytes_to_send); - if (ret < 0) - throw uhd::io_error((boost::format("Failed to reset FPGA (%d: %s)") % ret % libusb_error_name(ret)).str()); - else if (ret != bytes_to_send) - throw uhd::io_error((boost::format("Short write on reset FPGA (expecting: %d, returned: %d)") % bytes_to_send % ret).str()); + int ret = fx3_control_write(B200_VREQ_FPGA_RESET, 0x00, 0x00, data, + bytes_to_send); if (ret < 0) throw uhd::io_error((boost::format("Failed to reset + FPGA (%d: %s)") % ret % libusb_error_name(ret)).str()); else if (ret != + bytes_to_send) throw uhd::io_error((boost::format("Short write on reset FPGA + (expecting: %d, returned: %d)") % bytes_to_send % ret).str()); */ } - uint8_t get_usb_speed(void) { - + uint8_t get_usb_speed(void) + { unsigned char rx_data[1]; memset(rx_data, 0x00, sizeof(rx_data)); const int bytes_to_recv = sizeof(rx_data); int ret = fx3_control_read(B200_VREQ_GET_USB, 0x00, 0x00, rx_data, bytes_to_recv); if (ret < 0) - throw uhd::io_error((boost::format("Failed to get USB speed (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to get USB speed (%d: %s)") % ret + % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_recv) - throw uhd::io_error((boost::format("Short read on get USB speed (expecting: %d, returned: %d)") % bytes_to_recv % ret).str()); + throw uhd::io_error(( + boost::format("Short read on get USB speed (expecting: %d, returned: %d)") + % bytes_to_recv % ret) + .str()); return boost::lexical_cast<uint8_t>(rx_data[0]); } - uint8_t get_fx3_status(void) { - + uint8_t get_fx3_status(void) + { unsigned char rx_data[1]; memset(rx_data, 0x00, sizeof(rx_data)); const int bytes_to_recv = sizeof(rx_data); - int ret = fx3_control_read(B200_VREQ_GET_STATUS, 0x00, 0x00, rx_data, bytes_to_recv); + int ret = + fx3_control_read(B200_VREQ_GET_STATUS, 0x00, 0x00, rx_data, bytes_to_recv); if (ret < 0) - throw uhd::io_error((boost::format("Failed to get FX3 status (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to get FX3 status (%d: %s)") % ret + % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_recv) - throw uhd::io_error((boost::format("Short read on get FX3 status (expecting: %d, returned: %d)") % bytes_to_recv % ret).str()); + throw uhd::io_error( + (boost::format( + "Short read on get FX3 status (expecting: %d, returned: %d)") + % bytes_to_recv % ret) + .str()); return boost::lexical_cast<uint8_t>(rx_data[0]); } - uint16_t get_compat_num(void) { - + uint16_t get_compat_num(void) + { unsigned char rx_data[2]; memset(rx_data, 0x00, sizeof(rx_data)); const int bytes_to_recv = sizeof(rx_data); - int ret = fx3_control_read(B200_VREQ_GET_COMPAT , 0x00, 0x00, rx_data, bytes_to_recv); + int ret = + fx3_control_read(B200_VREQ_GET_COMPAT, 0x00, 0x00, rx_data, bytes_to_recv); if (ret < 0) - throw uhd::io_error((boost::format("Failed to get compat num (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to get compat num (%d: %s)") % ret + % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_recv) - throw uhd::io_error((boost::format("Short read on get compat num (expecting: %d, returned: %d)") % bytes_to_recv % ret).str()); + throw uhd::io_error( + (boost::format( + "Short read on get compat num (expecting: %d, returned: %d)") + % bytes_to_recv % ret) + .str()); return (((uint16_t)rx_data[0]) << 8) | rx_data[1]; } - void usrp_get_firmware_hash(hash_type &hash) { + void usrp_get_firmware_hash(hash_type& hash) + { const int bytes_to_recv = 4; if (sizeof(hash_type) != bytes_to_recv) - throw uhd::type_error((boost::format("hash_type is %d bytes but transfer length is %d bytes") % sizeof(hash_type) % bytes_to_recv).str()); + throw uhd::type_error( + (boost::format("hash_type is %d bytes but transfer length is %d bytes") + % sizeof(hash_type) % bytes_to_recv) + .str()); - int ret = fx3_control_read(B200_VREQ_GET_FW_HASH, 0x00, 0x00, (unsigned char*) &hash, bytes_to_recv, 500); + int ret = fx3_control_read( + B200_VREQ_GET_FW_HASH, 0x00, 0x00, (unsigned char*)&hash, bytes_to_recv, 500); if (ret < 0) - throw uhd::io_error((boost::format("Failed to get firmware hash (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to get firmware hash (%d: %s)") + % ret % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_recv) - throw uhd::io_error((boost::format("Short read on get firmware hash (expecting: %d, returned: %d)") % bytes_to_recv % ret).str()); + throw uhd::io_error( + (boost::format( + "Short read on get firmware hash (expecting: %d, returned: %d)") + % bytes_to_recv % ret) + .str()); } - void usrp_set_firmware_hash(hash_type hash) { + void usrp_set_firmware_hash(hash_type hash) + { const int bytes_to_send = 4; if (sizeof(hash_type) != bytes_to_send) - throw uhd::type_error((boost::format("hash_type is %d bytes but transfer length is %d bytes") % sizeof(hash_type) % bytes_to_send).str()); + throw uhd::type_error( + (boost::format("hash_type is %d bytes but transfer length is %d bytes") + % sizeof(hash_type) % bytes_to_send) + .str()); - int ret = fx3_control_write(B200_VREQ_SET_FW_HASH, 0x00, 0x00, (unsigned char*) &hash, bytes_to_send); + int ret = fx3_control_write( + B200_VREQ_SET_FW_HASH, 0x00, 0x00, (unsigned char*)&hash, bytes_to_send); if (ret < 0) - throw uhd::io_error((boost::format("Failed to set firmware hash (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to set firmware hash (%d: %s)") + % ret % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_send) - throw uhd::io_error((boost::format("Short write on set firmware hash (expecting: %d, returned: %d)") % bytes_to_send % ret).str()); + throw uhd::io_error( + (boost::format( + "Short write on set firmware hash (expecting: %d, returned: %d)") + % bytes_to_send % ret) + .str()); } - void usrp_get_fpga_hash(hash_type &hash) { + void usrp_get_fpga_hash(hash_type& hash) + { const int bytes_to_recv = 4; if (sizeof(hash_type) != bytes_to_recv) - throw uhd::type_error((boost::format("hash_type is %d bytes but transfer length is %d bytes") % sizeof(hash_type) % bytes_to_recv).str()); + throw uhd::type_error( + (boost::format("hash_type is %d bytes but transfer length is %d bytes") + % sizeof(hash_type) % bytes_to_recv) + .str()); - int ret = fx3_control_read(B200_VREQ_GET_FPGA_HASH, 0x00, 0x00, (unsigned char*) &hash, bytes_to_recv, 500); + int ret = fx3_control_read(B200_VREQ_GET_FPGA_HASH, + 0x00, + 0x00, + (unsigned char*)&hash, + bytes_to_recv, + 500); if (ret < 0) - throw uhd::io_error((boost::format("Failed to get FPGA hash (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to get FPGA hash (%d: %s)") % ret + % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_recv) - throw uhd::io_error((boost::format("Short read on get FPGA hash (expecting: %d, returned: %d)") % bytes_to_recv % ret).str()); + throw uhd::io_error(( + boost::format("Short read on get FPGA hash (expecting: %d, returned: %d)") + % bytes_to_recv % ret) + .str()); } - void usrp_set_fpga_hash(hash_type hash) { + void usrp_set_fpga_hash(hash_type hash) + { const int bytes_to_send = 4; if (sizeof(hash_type) != bytes_to_send) - throw uhd::type_error((boost::format("hash_type is %d bytes but transfer length is %d bytes") % sizeof(hash_type) % bytes_to_send).str()); + throw uhd::type_error( + (boost::format("hash_type is %d bytes but transfer length is %d bytes") + % sizeof(hash_type) % bytes_to_send) + .str()); - int ret = fx3_control_write(B200_VREQ_SET_FPGA_HASH, 0x00, 0x00, (unsigned char*) &hash, bytes_to_send); + int ret = fx3_control_write( + B200_VREQ_SET_FPGA_HASH, 0x00, 0x00, (unsigned char*)&hash, bytes_to_send); if (ret < 0) - throw uhd::io_error((boost::format("Failed to set FPGA hash (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to set FPGA hash (%d: %s)") % ret + % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_send) - throw uhd::io_error((boost::format("Short write on set FPGA hash (expecting: %d, returned: %d)") % bytes_to_send % ret).str()); + throw uhd::io_error( + (boost::format( + "Short write on set FPGA hash (expecting: %d, returned: %d)") + % bytes_to_send % ret) + .str()); } - // Establish default largest possible control request transfer size based on operating + // Establish default largest possible control request transfer size based on operating // USB speed int _get_transfer_size() { - switch (get_usb_speed()) - { + switch (get_usb_speed()) { case 2: return VREQ_DEFAULT_SIZE; case 3: @@ -385,25 +475,27 @@ public: } } - size_t _get_file_size(const char * filename) + size_t _get_file_size(const char* filename) { boost::filesystem::path path(filename); auto filesize = boost::filesystem::file_size(path); return static_cast<size_t>(filesize); } - uint32_t load_fpga(const std::string filestring, bool force) { - + uint32_t load_fpga(const std::string filestring, bool force) + { uint8_t fx3_state = 0; uint32_t wait_count; - int ret = 0; + int ret = 0; int bytes_to_xfer = 0; - const char *filename = filestring.c_str(); + const char* filename = filestring.c_str(); hash_type hash = generate_hash(filename); - hash_type loaded_hash; usrp_get_fpga_hash(loaded_hash); - if (hash == loaded_hash and !force) return 0; + hash_type loaded_hash; + usrp_get_fpga_hash(loaded_hash); + if (hash == loaded_hash and !force) + return 0; const int transfer_size = _get_transfer_size(); @@ -411,12 +503,21 @@ public: unsigned char out_buff[VREQ_MAX_SIZE]; - // Request loopback read, which will indicate the firmware's current control request buffer size + // Request loopback read, which will indicate the firmware's current control + // request buffer size int nread = fx3_control_read(B200_VREQ_LOOP, 0, 0, out_buff, transfer_size, 1000); if (nread < 0) - throw uhd::io_error((boost::format("load_fpga: unable to complete firmware loopback request (%d: %s)") % nread % libusb_error_name(nread)).str()); + throw uhd::io_error( + (boost::format( + "load_fpga: unable to complete firmware loopback request (%d: %s)") + % nread % libusb_error_name(nread)) + .str()); else if (nread != transfer_size) - throw uhd::io_error((boost::format("load_fpga: short read on firmware loopback request (expecting: %d, returned: %d)") % transfer_size % nread).str()); + throw uhd::io_error( + (boost::format("load_fpga: short read on firmware loopback request " + "(expecting: %d, returned: %d)") + % transfer_size % nread) + .str()); const size_t file_size = _get_file_size(filename); @@ -427,84 +528,107 @@ public: throw uhd::io_error("load_fpga: cannot open FPGA input file."); } - // Zero the hash, in case we abort programming another image and revert to the previously programmed image + // Zero the hash, in case we abort programming another image and revert to the + // previously programmed image usrp_set_fpga_hash(0); memset(out_buff, 0x00, sizeof(out_buff)); bytes_to_xfer = 1; - ret = fx3_control_write(B200_VREQ_FPGA_CONFIG, 0, 0, out_buff, bytes_to_xfer, 1000); + ret = + fx3_control_write(B200_VREQ_FPGA_CONFIG, 0, 0, out_buff, bytes_to_xfer, 1000); if (ret < 0) - throw uhd::io_error((boost::format("Failed to start FPGA config (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to start FPGA config (%d: %s)") + % ret % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_xfer) - throw uhd::io_error((boost::format("Short write on start FPGA config (expecting: %d, returned: %d)") % bytes_to_xfer % ret).str()); + throw uhd::io_error( + (boost::format( + "Short write on start FPGA config (expecting: %d, returned: %d)") + % bytes_to_xfer % ret) + .str()); wait_count = 0; do { fx3_state = get_fx3_status(); - if((wait_count >= 500) || (fx3_state == FX3_STATE_ERROR) || (fx3_state == FX3_STATE_UNDEFINED)) { + if ((wait_count >= 500) || (fx3_state == FX3_STATE_ERROR) + || (fx3_state == FX3_STATE_UNDEFINED)) { return fx3_state; } std::this_thread::sleep_for(std::chrono::milliseconds(10)); wait_count++; - } while(fx3_state != FX3_STATE_FPGA_READY); + } while (fx3_state != FX3_STATE_FPGA_READY); if (load_img_msg) { - UHD_LOGGER_INFO("B200") << "Loading FPGA image: " - << filestring << "..."; + UHD_LOGGER_INFO("B200") << "Loading FPGA image: " << filestring << "..."; } bytes_to_xfer = 1; - ret = fx3_control_write(B200_VREQ_FPGA_START, 0, 0, out_buff, bytes_to_xfer, 1000); + ret = + fx3_control_write(B200_VREQ_FPGA_START, 0, 0, out_buff, bytes_to_xfer, 1000); if (ret < 0) - throw uhd::io_error((boost::format("Failed to start FPGA bitstream (%d: %s)") % ret % libusb_error_name(ret)).str()); + throw uhd::io_error((boost::format("Failed to start FPGA bitstream (%d: %s)") + % ret % libusb_error_name(ret)) + .str()); else if (ret != bytes_to_xfer) - throw uhd::io_error((boost::format("Short write on start FPGA bitstream (expecting: %d, returned: %d)") % bytes_to_xfer % ret).str()); + throw uhd::io_error( + (boost::format( + "Short write on start FPGA bitstream (expecting: %d, returned: %d)") + % bytes_to_xfer % ret) + .str()); wait_count = 0; do { fx3_state = get_fx3_status(); - if((wait_count >= 1000) || (fx3_state == FX3_STATE_ERROR) || (fx3_state == FX3_STATE_UNDEFINED)) { + if ((wait_count >= 1000) || (fx3_state == FX3_STATE_ERROR) + || (fx3_state == FX3_STATE_UNDEFINED)) { return fx3_state; } std::this_thread::sleep_for(std::chrono::milliseconds(10)); wait_count++; - } while(fx3_state != FX3_STATE_CONFIGURING_FPGA); + } while (fx3_state != FX3_STATE_CONFIGURING_FPGA); size_t bytes_sent = 0; while (!file.eof()) { - file.read((char *) out_buff, transfer_size); + file.read((char*)out_buff, transfer_size); const std::streamsize n = file.gcount(); - if(n == 0) + if (n == 0) continue; uint16_t transfer_count = uint16_t(n); /* Send the data to the device. */ - int nwritten = fx3_control_write(B200_VREQ_FPGA_DATA, 0, 0, out_buff, transfer_count, 5000); + int nwritten = fx3_control_write( + B200_VREQ_FPGA_DATA, 0, 0, out_buff, transfer_count, 5000); if (nwritten < 0) - throw uhd::io_error((boost::format("load_fpga: cannot write bitstream to FX3 (%d: %s)") % nwritten % libusb_error_name(nwritten)).str()); + throw uhd::io_error( + (boost::format("load_fpga: cannot write bitstream to FX3 (%d: %s)") + % nwritten % libusb_error_name(nwritten)) + .str()); else if (nwritten != transfer_count) - throw uhd::io_error((boost::format("load_fpga: short write while transferring bitstream to FX3 (expecting: %d, returned: %d)") % transfer_count % nwritten).str()); + throw uhd::io_error( + (boost::format("load_fpga: short write while transferring bitstream " + "to FX3 (expecting: %d, returned: %d)") + % transfer_count % nwritten) + .str()); const size_t LOG_GRANULARITY = 10; // %. Keep this an integer divisor of 100. - if (load_img_msg) - { - if (bytes_sent == 0) UHD_LOGGER_DEBUG("B200") << "FPGA load: 0%" << std::flush; + if (load_img_msg) { + if (bytes_sent == 0) + UHD_LOGGER_DEBUG("B200") << "FPGA load: 0%" << std::flush; const size_t percent_before = - size_t((bytes_sent*100)/file_size) - - (size_t((bytes_sent*100)/file_size) % LOG_GRANULARITY); + size_t((bytes_sent * 100) / file_size) + - (size_t((bytes_sent * 100) / file_size) % LOG_GRANULARITY); bytes_sent += transfer_count; const size_t percent_after = - size_t((bytes_sent*100)/file_size) - - (size_t((bytes_sent*100)/file_size) % LOG_GRANULARITY); - if (percent_before != percent_after) - { + size_t((bytes_sent * 100) / file_size) + - (size_t((bytes_sent * 100) / file_size) % LOG_GRANULARITY); + if (percent_before != percent_after) { UHD_LOGGER_DEBUG("B200") << "FPGA load: " << std::setw(3) << percent_after << "%"; } @@ -517,14 +641,15 @@ public: do { fx3_state = get_fx3_status(); - if((wait_count >= 500) || (fx3_state == FX3_STATE_ERROR) || (fx3_state == FX3_STATE_UNDEFINED)) { + if ((wait_count >= 500) || (fx3_state == FX3_STATE_ERROR) + || (fx3_state == FX3_STATE_UNDEFINED)) { return fx3_state; } std::this_thread::sleep_for(std::chrono::milliseconds(10)); wait_count++; - } while(fx3_state != FX3_STATE_RUNNING); + } while (fx3_state != FX3_STATE_RUNNING); usrp_set_fpga_hash(hash); @@ -598,8 +723,12 @@ public: uint16_t transfer_count = uint16_t(n); // Send the data to the device - int nwritten = fx3_control_write( - B200_VREQ_EEPROM_WRITE, 0, bytes_sent, out_buff.data(), transfer_count, 5000); + int nwritten = fx3_control_write(B200_VREQ_EEPROM_WRITE, + 0, + bytes_sent, + out_buff.data(), + transfer_count, + 5000); if (nwritten < 0) { throw uhd::io_error( (boost::format( @@ -627,7 +756,8 @@ public: size_t((bytes_sent * 100) / file_size) - (size_t((bytes_sent * 100) / file_size) % LOG_GRANULARITY); if (percent_before != percent_after) { - UHD_LOGGER_DEBUG("B200") << "Bootloader load: " << std::setw(3) << percent_after << "%"; + UHD_LOGGER_DEBUG("B200") + << "Bootloader load: " << std::setw(3) << percent_after << "%"; } } @@ -654,22 +784,21 @@ private: std::string b200_iface::fx3_state_string(uint8_t state) { - switch (state) - { - case FX3_STATE_FPGA_READY: - return std::string("Ready"); - case FX3_STATE_CONFIGURING_FPGA: - return std::string("Configuring FPGA"); - case FX3_STATE_BUSY: - return std::string("Busy"); - case FX3_STATE_RUNNING: - return std::string("Running"); - case FX3_STATE_UNCONFIGURED: - return std::string("Unconfigured"); - case FX3_STATE_ERROR: - return std::string("Error"); - default: - break; + switch (state) { + case FX3_STATE_FPGA_READY: + return std::string("Ready"); + case FX3_STATE_CONFIGURING_FPGA: + return std::string("Configuring FPGA"); + case FX3_STATE_BUSY: + return std::string("Busy"); + case FX3_STATE_RUNNING: + return std::string("Running"); + case FX3_STATE_UNCONFIGURED: + return std::string("Unconfigured"); + case FX3_STATE_ERROR: + return std::string("Error"); + default: + break; } return std::string("Unknown"); } diff --git a/host/lib/usrp/b200/b200_iface.hpp b/host/lib/usrp/b200/b200_iface.hpp index a3059bacf..7d7e169d4 100644 --- a/host/lib/usrp/b200/b200_iface.hpp +++ b/host/lib/usrp/b200/b200_iface.hpp @@ -9,75 +9,54 @@ #define INCLUDED_B200_IFACE_HPP #include <uhd/transport/usb_control.hpp> -#include <uhd/types/serial.hpp> //i2c iface #include <uhd/types/dict.hpp> +#include <uhd/types/serial.hpp> //i2c iface +#include <uhd/utils/noncopyable.hpp> #include <uhdlib/usrp/common/ad9361_ctrl.hpp> +#include <stdint.h> #include <boost/assign/list_of.hpp> #include <memory> -#include <uhd/utils/noncopyable.hpp> -#include <stdint.h> -enum b200_product_t { - B200, - B210, - B200MINI, - B205MINI -}; +enum b200_product_t { B200, B210, B200MINI, B205MINI }; // These are actual USB PIDs (not Ettus Product IDs) -const static uint16_t B200_VENDOR_ID = 0x2500; -const static uint16_t B200_VENDOR_NI_ID = 0x3923; -const static uint16_t B200_PRODUCT_ID = 0x0020; -const static uint16_t B200MINI_PRODUCT_ID = 0x0021; -const static uint16_t B205MINI_PRODUCT_ID = 0x0022; -const static uint16_t B200_PRODUCT_NI_ID = 0x7813; -const static uint16_t B210_PRODUCT_NI_ID = 0x7814; -const static uint16_t FX3_VID = 0x04b4; -const static uint16_t FX3_DEFAULT_PID = 0x00f3; -const static uint16_t FX3_REENUM_PID = 0x00f0; +const static uint16_t B200_VENDOR_ID = 0x2500; +const static uint16_t B200_VENDOR_NI_ID = 0x3923; +const static uint16_t B200_PRODUCT_ID = 0x0020; +const static uint16_t B200MINI_PRODUCT_ID = 0x0021; +const static uint16_t B205MINI_PRODUCT_ID = 0x0022; +const static uint16_t B200_PRODUCT_NI_ID = 0x7813; +const static uint16_t B210_PRODUCT_NI_ID = 0x7814; +const static uint16_t FX3_VID = 0x04b4; +const static uint16_t FX3_DEFAULT_PID = 0x00f3; +const static uint16_t FX3_REENUM_PID = 0x00f0; //! Map the USB PID to the product (only for PIDs that map to a single product) -static const uhd::dict<uint16_t, b200_product_t> B2XX_PID_TO_PRODUCT = boost::assign::map_list_of - (B200_PRODUCT_NI_ID, B200) - (B210_PRODUCT_NI_ID, B210) - (B200MINI_PRODUCT_ID, B200MINI) - (B205MINI_PRODUCT_ID, B205MINI) -; +static const uhd::dict<uint16_t, b200_product_t> B2XX_PID_TO_PRODUCT = + boost::assign::map_list_of(B200_PRODUCT_NI_ID, B200)(B210_PRODUCT_NI_ID, B210)( + B200MINI_PRODUCT_ID, B200MINI)(B205MINI_PRODUCT_ID, B205MINI); -static const std::string B200_FW_FILE_NAME = "usrp_b200_fw.hex"; -static const std::string B200_BL_FILE_NAME = "usrp_b200_bl.img"; +static const std::string B200_FW_FILE_NAME = "usrp_b200_fw.hex"; +static const std::string B200_BL_FILE_NAME = "usrp_b200_bl.img"; //! Map the EEPROM product ID codes to the product -static const uhd::dict<uint16_t, b200_product_t> B2XX_PRODUCT_ID = boost::assign::map_list_of - (0x0001, B200) - (0x7737, B200) - (B200_PRODUCT_NI_ID, B200) - (0x0002, B210) - (0x7738, B210) - (B210_PRODUCT_NI_ID, B210) - (0x0003, B200MINI) - (0x7739, B200MINI) - (0x0004, B205MINI) - (0x773a, B205MINI) -; - - -static const uhd::dict<b200_product_t, std::string> B2XX_STR_NAMES = boost::assign::map_list_of - (B200, "B200") - (B210, "B210") - (B200MINI, "B200mini") - (B205MINI, "B205mini") -; - -static const uhd::dict<b200_product_t, std::string> B2XX_FPGA_FILE_NAME = boost::assign::map_list_of - (B200, "usrp_b200_fpga.bin") - (B210, "usrp_b210_fpga.bin") - (B200MINI, "usrp_b200mini_fpga.bin") - (B205MINI, "usrp_b205mini_fpga.bin") -; - - -class UHD_API b200_iface: uhd::noncopyable, public virtual uhd::i2c_iface { +static const uhd::dict<uint16_t, b200_product_t> B2XX_PRODUCT_ID = + boost::assign::map_list_of(0x0001, B200)(0x7737, B200)(B200_PRODUCT_NI_ID, B200)( + 0x0002, B210)(0x7738, B210)(B210_PRODUCT_NI_ID, B210)(0x0003, B200MINI)( + 0x7739, B200MINI)(0x0004, B205MINI)(0x773a, B205MINI); + + +static const uhd::dict<b200_product_t, std::string> B2XX_STR_NAMES = + boost::assign::map_list_of(B200, "B200")(B210, "B210")(B200MINI, "B200mini")( + B205MINI, "B205mini"); + +static const uhd::dict<b200_product_t, std::string> B2XX_FPGA_FILE_NAME = + boost::assign::map_list_of(B200, "usrp_b200_fpga.bin")(B210, "usrp_b210_fpga.bin")( + B200MINI, "usrp_b200mini_fpga.bin")(B205MINI, "usrp_b205mini_fpga.bin"); + + +class UHD_API b200_iface : uhd::noncopyable, public virtual uhd::i2c_iface +{ public: typedef std::shared_ptr<b200_iface> sptr; @@ -98,7 +77,7 @@ public: virtual uint16_t get_compat_num(void) = 0; //! load a firmware image - virtual void load_firmware(const std::string filestring, bool force=false) = 0; + virtual void load_firmware(const std::string filestring, bool force = false) = 0; //! reset the FX3 virtual void reset_fx3(void) = 0; @@ -110,14 +89,16 @@ public: virtual void set_fpga_reset_pin(const bool reset) = 0; //! load an FPGA image - virtual uint32_t load_fpga(const std::string filestring, bool force=false) = 0; + virtual uint32_t load_fpga(const std::string filestring, bool force = false) = 0; //! load a bootloader image onto device EEPROM virtual uint32_t load_bootloader(const std::string filestring) = 0; - virtual void write_eeprom(uint16_t addr, uint16_t offset, const uhd::byte_vector_t &bytes) = 0; + virtual void write_eeprom( + uint16_t addr, uint16_t offset, const uhd::byte_vector_t& bytes) = 0; - virtual uhd::byte_vector_t read_eeprom(uint16_t addr, uint16_t offset, size_t num_bytes) = 0; + virtual uhd::byte_vector_t read_eeprom( + uint16_t addr, uint16_t offset, size_t num_bytes) = 0; static std::string fx3_state_string(uint8_t state); }; diff --git a/host/lib/usrp/b200/b200_image_loader.cpp b/host/lib/usrp/b200/b200_image_loader.cpp index cf61ecb88..25bf7ce2f 100644 --- a/host/lib/usrp/b200/b200_image_loader.cpp +++ b/host/lib/usrp/b200/b200_image_loader.cpp @@ -5,77 +5,80 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <boost/assign.hpp> -#include <boost/lexical_cast.hpp> - +#include "b200_iface.hpp" +#include "b200_impl.hpp" #include <uhd/exception.hpp> #include <uhd/image_loader.hpp> #include <uhd/types/dict.hpp> #include <uhd/usrp/mboard_eeprom.hpp> #include <uhd/utils/paths.hpp> #include <uhd/utils/static.hpp> - -#include "b200_iface.hpp" -#include "b200_impl.hpp" +#include <boost/assign.hpp> +#include <boost/lexical_cast.hpp> using namespace uhd; using namespace uhd::usrp; using namespace uhd::transport; -namespace uhd{ - -static b200_iface::sptr get_b200_iface(const image_loader::image_loader_args_t& image_loader_args, - mboard_eeprom_t &mb_eeprom, usb_device_handle::sptr& handle, - bool user_specified){ +namespace uhd { - std::vector<usb_device_handle::sptr> dev_handles = get_b200_device_handles(image_loader_args.args); +static b200_iface::sptr get_b200_iface( + const image_loader::image_loader_args_t& image_loader_args, + mboard_eeprom_t& mb_eeprom, + usb_device_handle::sptr& handle, + bool user_specified) +{ + std::vector<usb_device_handle::sptr> dev_handles = + get_b200_device_handles(image_loader_args.args); std::vector<usb_device_handle::sptr> applicable_dev_handles; b200_iface::sptr iface; mboard_eeprom_t eeprom; // Internal use - if(dev_handles.size() > 0){ - for(usb_device_handle::sptr dev_handle: dev_handles){ - if(dev_handle->firmware_loaded()){ - iface = b200_iface::make(usb_control::make(dev_handle, 0)); + if (dev_handles.size() > 0) { + for (usb_device_handle::sptr dev_handle : dev_handles) { + if (dev_handle->firmware_loaded()) { + iface = b200_iface::make(usb_control::make(dev_handle, 0)); eeprom = b200_impl::get_mb_eeprom(iface); - if(user_specified){ - if(image_loader_args.args.has_key("serial") and - eeprom.get("serial") != image_loader_args.args.get("serial")){ - continue; + if (user_specified) { + if (image_loader_args.args.has_key("serial") + and eeprom.get("serial") + != image_loader_args.args.get("serial")) { + continue; } - if(image_loader_args.args.has_key("name") and - eeprom.get("name") != image_loader_args.args.get("name")){ - continue; + if (image_loader_args.args.has_key("name") + and eeprom.get("name") != image_loader_args.args.get("name")) { + continue; } applicable_dev_handles.push_back(dev_handle); - } - else applicable_dev_handles.push_back(dev_handle); + } else + applicable_dev_handles.push_back(dev_handle); } } // At this point, we should have a single B2XX - if(applicable_dev_handles.size() == 1){ + if (applicable_dev_handles.size() == 1) { mb_eeprom = eeprom; - handle = applicable_dev_handles[0]; + handle = applicable_dev_handles[0]; return iface; - } - else if(applicable_dev_handles.size() > 1){ - std::string err_msg = "Could not resolve given args to a single B2XX device.\n" - "Applicable devices:\n"; + } else if (applicable_dev_handles.size() > 1) { + std::string err_msg = + "Could not resolve given args to a single B2XX device.\n" + "Applicable devices:\n"; - for (usb_device_handle::sptr dev_handle: applicable_dev_handles) { + for (usb_device_handle::sptr dev_handle : applicable_dev_handles) { eeprom = b200_impl::get_mb_eeprom( - b200_iface::make(usb_control::make(dev_handle, 0)) - ); - err_msg += str(boost::format(" * %s (serial=%s)\n") - % B2XX_STR_NAMES.get(get_b200_product(dev_handle, mb_eeprom), "B2XX") - % mb_eeprom.get("serial")); + b200_iface::make(usb_control::make(dev_handle, 0))); + err_msg += str( + boost::format(" * %s (serial=%s)\n") + % B2XX_STR_NAMES.get(get_b200_product(dev_handle, mb_eeprom), "B2XX") + % mb_eeprom.get("serial")); } - err_msg += "\nSpecify one of these devices with the given args to load an image onto it."; + err_msg += "\nSpecify one of these devices with the given args to load an " + "image onto it."; throw uhd::runtime_error(err_msg); - } + } } // No applicable devices found, return empty sptr so we can exit @@ -84,45 +87,48 @@ static b200_iface::sptr get_b200_iface(const image_loader::image_loader_args_t& return iface; } -static bool b200_image_loader(const image_loader::image_loader_args_t &image_loader_args){ - if(!image_loader_args.load_fpga) +static bool b200_image_loader(const image_loader::image_loader_args_t& image_loader_args) +{ + if (!image_loader_args.load_fpga) return false; - bool user_specified = (image_loader_args.args.has_key("serial") or - image_loader_args.args.has_key("name")); + bool user_specified = (image_loader_args.args.has_key("serial") + or image_loader_args.args.has_key("name")); // See if a B2x0 with the given args is found mboard_eeprom_t mb_eeprom; usb_device_handle::sptr handle; - b200_iface::sptr iface = get_b200_iface(image_loader_args, mb_eeprom, handle, user_specified); - if(!iface) return false; // No initialized B2x0 found + b200_iface::sptr iface = + get_b200_iface(image_loader_args, mb_eeprom, handle, user_specified); + if (!iface) + return false; // No initialized B2x0 found std::string fpga_path; - if(image_loader_args.fpga_path == ""){ + if (image_loader_args.fpga_path == "") { /* * Normally, we can auto-generate the FPGA filename from what's in the EEPROM, * but if the applicable value is not in the EEPROM, the user must give a specific * filename for us to use. */ std::string product = mb_eeprom.get("product"); - if(not B2XX_PRODUCT_ID.has_key(boost::lexical_cast<uint16_t>(product))){ - if(user_specified){ + if (not B2XX_PRODUCT_ID.has_key(boost::lexical_cast<uint16_t>(product))) { + if (user_specified) { // The user specified a bad device but expects us to know what it is - throw uhd::runtime_error("Could not determine model. You must manually specify an FPGA image filename."); - } - else{ + throw uhd::runtime_error("Could not determine model. You must manually " + "specify an FPGA image filename."); + } else { return false; } + } else { + fpga_path = find_image_path( + B2XX_FPGA_FILE_NAME.get(get_b200_product(handle, mb_eeprom))); } - else{ - fpga_path = find_image_path(B2XX_FPGA_FILE_NAME.get(get_b200_product(handle, mb_eeprom))); - } - } - else fpga_path = image_loader_args.fpga_path; + } else + fpga_path = image_loader_args.fpga_path; std::cout << boost::format("Unit: USRP %s (%s)") - % B2XX_STR_NAMES.get(get_b200_product(handle, mb_eeprom), "B2XX") - % mb_eeprom.get("serial") + % B2XX_STR_NAMES.get(get_b200_product(handle, mb_eeprom), "B2XX") + % mb_eeprom.get("serial") << std::endl; iface->load_fpga(fpga_path, true); @@ -130,10 +136,12 @@ static bool b200_image_loader(const image_loader::image_loader_args_t &image_loa return true; } -UHD_STATIC_BLOCK(register_b200_image_loader){ - std::string recovery_instructions = "This device is likely in an unusable state. Power-cycle the\n" - "device, and the firmware/FPGA will be reloaded the next time\n" - "UHD uses the device."; +UHD_STATIC_BLOCK(register_b200_image_loader) +{ + std::string recovery_instructions = + "This device is likely in an unusable state. Power-cycle the\n" + "device, and the firmware/FPGA will be reloaded the next time\n" + "UHD uses the device."; image_loader::register_image_loader("b200", b200_image_loader, recovery_instructions); } diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index bf95d8e6b..1da682349 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -34,60 +34,78 @@ using namespace uhd::usrp::gpio_atr; using namespace uhd::transport; namespace { - constexpr int64_t REENUMERATION_TIMEOUT_MS = 3000; +constexpr int64_t REENUMERATION_TIMEOUT_MS = 3000; } // B200 + B210: -class b200_ad9361_client_t : public ad9361_params { +class b200_ad9361_client_t : public ad9361_params +{ public: ~b200_ad9361_client_t() {} - double get_band_edge(frequency_band_t band) { + double get_band_edge(frequency_band_t band) + { switch (band) { - case AD9361_RX_BAND0: return 2.2e9; // Port C - case AD9361_RX_BAND1: return 4.0e9; // Port B - case AD9361_TX_BAND0: return 2.5e9; // Port B - default: return 0; + case AD9361_RX_BAND0: + return 2.2e9; // Port C + case AD9361_RX_BAND1: + return 4.0e9; // Port B + case AD9361_TX_BAND0: + return 2.5e9; // Port B + default: + return 0; } } - clocking_mode_t get_clocking_mode() { + clocking_mode_t get_clocking_mode() + { return clocking_mode_t::AD9361_XTAL_N_CLK_PATH; } - digital_interface_mode_t get_digital_interface_mode() { + digital_interface_mode_t get_digital_interface_mode() + { return AD9361_DDR_FDD_LVCMOS; } - digital_interface_delays_t get_digital_interface_timing() { + digital_interface_delays_t get_digital_interface_timing() + { digital_interface_delays_t delays; - delays.rx_clk_delay = 0; + delays.rx_clk_delay = 0; delays.rx_data_delay = 0xF; - delays.tx_clk_delay = 0; + delays.tx_clk_delay = 0; delays.tx_data_delay = 0xF; return delays; } }; // B205 -class b2xxmini_ad9361_client_t : public ad9361_params { +class b2xxmini_ad9361_client_t : public ad9361_params +{ public: ~b2xxmini_ad9361_client_t() {} - double get_band_edge(frequency_band_t band) { + double get_band_edge(frequency_band_t band) + { switch (band) { - case AD9361_RX_BAND0: return 0; // Set these all to - case AD9361_RX_BAND1: return 0; // zero, so RF port A - case AD9361_TX_BAND0: return 0; // is used all the time - default: return 0; // On both Rx and Tx + case AD9361_RX_BAND0: + return 0; // Set these all to + case AD9361_RX_BAND1: + return 0; // zero, so RF port A + case AD9361_TX_BAND0: + return 0; // is used all the time + default: + return 0; // On both Rx and Tx } } - clocking_mode_t get_clocking_mode() { + clocking_mode_t get_clocking_mode() + { return clocking_mode_t::AD9361_XTAL_N_CLK_PATH; } - digital_interface_mode_t get_digital_interface_mode() { + digital_interface_mode_t get_digital_interface_mode() + { return AD9361_DDR_FDD_LVCMOS; } - digital_interface_delays_t get_digital_interface_timing() { + digital_interface_delays_t get_digital_interface_timing() + { digital_interface_delays_t delays; - delays.rx_clk_delay = 0; + delays.rx_clk_delay = 0; delays.rx_data_delay = 0xF; - delays.tx_clk_delay = 0; + delays.tx_clk_delay = 0; delays.tx_data_delay = 0xF; return delays; } @@ -96,16 +114,14 @@ public: /*********************************************************************** * Helpers **********************************************************************/ -std::string check_option_valid( - const std::string &name, - const std::vector<std::string> &valid_options, - const std::string &option -) { - if (std::find(valid_options.begin(), valid_options.end(), option) == valid_options.end()) { - throw uhd::runtime_error(str( - boost::format("Invalid option chosen for: %s") - % name - )); +std::string check_option_valid(const std::string& name, + const std::vector<std::string>& valid_options, + const std::string& option) +{ + if (std::find(valid_options.begin(), valid_options.end(), option) + == valid_options.end()) { + throw uhd::runtime_error( + str(boost::format("Invalid option chosen for: %s") % name)); } return option; @@ -117,7 +133,8 @@ std::string check_option_valid( //! Look up the type of B-Series device we're currently running. // Throws a uhd::runtime_error if the USB PID and the product ID stored // in the MB EEPROM are invalid, -b200_product_t get_b200_product(const usb_device_handle::sptr& handle, const mboard_eeprom_t &mb_eeprom) +b200_product_t get_b200_product( + const usb_device_handle::sptr& handle, const mboard_eeprom_t& mb_eeprom) { // Try USB PID first uint16_t product_id = handle->get_product_id(); @@ -130,40 +147,42 @@ b200_product_t get_b200_product(const usb_device_handle::sptr& handle, const mbo } product_id = boost::lexical_cast<uint16_t>(mb_eeprom["product"]); if (not B2XX_PRODUCT_ID.has_key(product_id)) { - throw uhd::runtime_error(str( - boost::format("B200 unknown product code: 0x%04x") - % product_id - )); + throw uhd::runtime_error( + str(boost::format("B200 unknown product code: 0x%04x") % product_id)); } return B2XX_PRODUCT_ID[product_id]; } -std::vector<usb_device_handle::sptr> get_b200_device_handles(const device_addr_t &hint) +std::vector<usb_device_handle::sptr> get_b200_device_handles(const device_addr_t& hint) { std::vector<usb_device_handle::vid_pid_pair_t> vid_pid_pair_list; - if(hint.has_key("vid") && hint.has_key("pid") && hint.has_key("type") && hint["type"] == "b200") { - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(uhd::cast::hexstr_cast<uint16_t>(hint.get("vid")), - uhd::cast::hexstr_cast<uint16_t>(hint.get("pid")))); + if (hint.has_key("vid") && hint.has_key("pid") && hint.has_key("type") + && hint["type"] == "b200") { + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t( + uhd::cast::hexstr_cast<uint16_t>(hint.get("vid")), + uhd::cast::hexstr_cast<uint16_t>(hint.get("pid")))); } else { vid_pid_pair_list = b200_vid_pid_pairs; } - //find the usrps and load firmware + // find the usrps and load firmware return usb_device_handle::get_device_list(vid_pid_pair_list); } -static device_addrs_t b200_find(const device_addr_t &hint) +static device_addrs_t b200_find(const device_addr_t& hint) { device_addrs_t b200_addrs; - //return an empty list of addresses when type is set to non-b200 - if (hint.has_key("type") and hint["type"] != "b200") return b200_addrs; + // return an empty list of addresses when type is set to non-b200 + if (hint.has_key("type") and hint["type"] != "b200") + return b200_addrs; - //Return an empty list of addresses when an address or resource is specified, - //since an address and resource is intended for a different, non-USB, device. - for(device_addr_t hint_i: separate_device_addr(hint)) { - if (hint_i.has_key("addr") || hint_i.has_key("resource")) return b200_addrs; + // Return an empty list of addresses when an address or resource is specified, + // since an address and resource is intended for a different, non-USB, device. + for (device_addr_t hint_i : separate_device_addr(hint)) { + if (hint_i.has_key("addr") || hint_i.has_key("resource")) + return b200_addrs; } // Important note: @@ -172,64 +191,66 @@ static device_addrs_t b200_find(const device_addr_t &hint) // so that re-enumeration after fw load can occur successfully. // This requirement is a courtesy of libusb1.0 on windows. size_t found = 0; - for(usb_device_handle::sptr handle: get_b200_device_handles(hint)) { - //extract the firmware path for the b200 + for (usb_device_handle::sptr handle : get_b200_device_handles(hint)) { + // extract the firmware path for the b200 std::string b200_fw_image; - try{ + try { b200_fw_image = hint.get("fw", B200_FW_FILE_NAME); - b200_fw_image = uhd::find_image_path(b200_fw_image, STR(UHD_IMAGES_DIR)); // FIXME - } - catch(uhd::exception &e){ + b200_fw_image = + uhd::find_image_path(b200_fw_image, STR(UHD_IMAGES_DIR)); // FIXME + } catch (uhd::exception& e) { UHD_LOGGER_WARNING("B200") << e.what(); return b200_addrs; } - UHD_LOGGER_DEBUG("B200") << "the firmware image: " << b200_fw_image ; + UHD_LOGGER_DEBUG("B200") << "the firmware image: " << b200_fw_image; usb_control::sptr control; - try{control = usb_control::make(handle, 0);} - catch(const uhd::exception &){continue;} //ignore claimed + try { + control = usb_control::make(handle, 0); + } catch (const uhd::exception&) { + continue; + } // ignore claimed - //check if fw was already loaded - if (!(handle->firmware_loaded())) - { + // check if fw was already loaded + if (!(handle->firmware_loaded())) { b200_iface::make(control)->load_firmware(b200_fw_image); } found++; } - const auto timeout_time = - std::chrono::steady_clock::now() - + std::chrono::milliseconds(REENUMERATION_TIMEOUT_MS); - //search for the device until found or timeout - while (std::chrono::steady_clock::now() < timeout_time - and b200_addrs.empty() - and found != 0) { - for(usb_device_handle::sptr handle: get_b200_device_handles(hint)) { + const auto timeout_time = std::chrono::steady_clock::now() + + std::chrono::milliseconds(REENUMERATION_TIMEOUT_MS); + // search for the device until found or timeout + while (std::chrono::steady_clock::now() < timeout_time and b200_addrs.empty() + and found != 0) { + for (usb_device_handle::sptr handle : get_b200_device_handles(hint)) { usb_control::sptr control; - try{control = usb_control::make(handle, 0);} - catch(const uhd::exception &){continue;} //ignore claimed + try { + control = usb_control::make(handle, 0); + } catch (const uhd::exception&) { + continue; + } // ignore claimed - b200_iface::sptr iface = b200_iface::make(control); + b200_iface::sptr iface = b200_iface::make(control); const mboard_eeprom_t mb_eeprom = b200_impl::get_mb_eeprom(iface); device_addr_t new_addr; - new_addr["type"] = "b200"; - new_addr["name"] = mb_eeprom["name"]; + new_addr["type"] = "b200"; + new_addr["name"] = mb_eeprom["name"]; new_addr["serial"] = handle->get_serial(); try { // Turn the 16-Bit product ID into a string representation new_addr["product"] = B2XX_STR_NAMES[get_b200_product(handle, mb_eeprom)]; - } catch (const uhd::runtime_error &) { + } catch (const uhd::runtime_error&) { // No problem if this fails -- this is just device discovery, after all. new_addr["product"] = "B2??"; } - //this is a found b200 when the hint serial and name match or blank - if ( - (not hint.has_key("name") or hint["name"] == new_addr["name"]) and - (not hint.has_key("serial") or hint["serial"] == new_addr["serial"]) - ){ + // this is a found b200 when the hint serial and name match or blank + if ((not hint.has_key("name") or hint["name"] == new_addr["name"]) + and (not hint.has_key("serial") + or hint["serial"] == new_addr["serial"])) { b200_addrs.push_back(new_addr); } } @@ -241,7 +262,7 @@ static device_addrs_t b200_find(const device_addr_t &hint) /*********************************************************************** * Make **********************************************************************/ -static device::sptr b200_make(const device_addr_t &device_addr) +static device::sptr b200_make(const device_addr_t& device_addr) { uhd::transport::usb_device_handle::sptr handle; @@ -250,14 +271,14 @@ static device::sptr b200_make(const device_addr_t &device_addr) // a third time is pointless. try { return device::sptr(new b200_impl(device_addr, handle)); - } - catch (const uhd::usb_error &) { - UHD_LOGGER_INFO("B200") << "Detected bad USB state; resetting." ; + } catch (const uhd::usb_error&) { + UHD_LOGGER_INFO("B200") << "Detected bad USB state; resetting."; libusb::device_handle::sptr dev_handle(libusb::device_handle::get_cached_handle( - std::static_pointer_cast<libusb::special_handle>(handle)->get_device() - )); - dev_handle->clear_endpoints(B200_USB_CTRL_RECV_ENDPOINT, B200_USB_CTRL_SEND_ENDPOINT); - dev_handle->clear_endpoints(B200_USB_DATA_RECV_ENDPOINT, B200_USB_DATA_SEND_ENDPOINT); + std::static_pointer_cast<libusb::special_handle>(handle)->get_device())); + dev_handle->clear_endpoints( + B200_USB_CTRL_RECV_ENDPOINT, B200_USB_CTRL_SEND_ENDPOINT); + dev_handle->clear_endpoints( + B200_USB_DATA_RECV_ENDPOINT, B200_USB_DATA_SEND_ENDPOINT); dev_handle->reset_device(); } @@ -272,84 +293,96 @@ UHD_STATIC_BLOCK(register_b200_device) /*********************************************************************** * Structors **********************************************************************/ -b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::sptr &handle) : - _product(B200), // Some safe value - _revision(0), - _enable_user_regs(device_addr.has_key("enable_user_regs")), - _time_source(UNKNOWN), - _tick_rate(0.0) // Forces a clock initialization at startup +b200_impl::b200_impl( + const uhd::device_addr_t& device_addr, usb_device_handle::sptr& handle) + : _product(B200) + , // Some safe value + _revision(0) + , _enable_user_regs(device_addr.has_key("enable_user_regs")) + , _time_source(UNKNOWN) + , _tick_rate(0.0) // Forces a clock initialization at startup { - _tree = property_tree::make(); - _type = device::USRP; + _tree = property_tree::make(); + _type = device::USRP; const fs_path mb_path = "/mboards/0"; - //try to match the given device address with something on the USB bus - uint16_t vid = B200_VENDOR_ID; - uint16_t pid = B200_PRODUCT_ID; + // try to match the given device address with something on the USB bus + uint16_t vid = B200_VENDOR_ID; + uint16_t pid = B200_PRODUCT_ID; bool specified_vid = false; bool specified_pid = false; - if (device_addr.has_key("vid")) - { - vid = uhd::cast::hexstr_cast<uint16_t>(device_addr.get("vid")); + if (device_addr.has_key("vid")) { + vid = uhd::cast::hexstr_cast<uint16_t>(device_addr.get("vid")); specified_vid = true; } - if (device_addr.has_key("pid")) - { - pid = uhd::cast::hexstr_cast<uint16_t>(device_addr.get("pid")); + if (device_addr.has_key("pid")) { + pid = uhd::cast::hexstr_cast<uint16_t>(device_addr.get("pid")); specified_pid = true; } - std::vector<usb_device_handle::vid_pid_pair_t> vid_pid_pair_list;//search list for devices. + std::vector<usb_device_handle::vid_pid_pair_t> + vid_pid_pair_list; // search list for devices. // Search only for specified VID and PID if both specified - if (specified_vid && specified_pid) - { - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid,pid)); + if (specified_vid && specified_pid) { + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid, pid)); } // Search for all supported PIDs limited to specified VID if only VID specified - else if (specified_vid) - { - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid, B200_PRODUCT_ID)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid, B200MINI_PRODUCT_ID)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid, B205MINI_PRODUCT_ID)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid, B200_PRODUCT_NI_ID)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid, B210_PRODUCT_NI_ID)); + else if (specified_vid) { + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(vid, B200_PRODUCT_ID)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(vid, B200MINI_PRODUCT_ID)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(vid, B205MINI_PRODUCT_ID)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(vid, B200_PRODUCT_NI_ID)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(vid, B210_PRODUCT_NI_ID)); } // Search for all supported VIDs limited to specified PID if only PID specified - else if (specified_pid) - { - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID,pid)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID,pid)); + else if (specified_pid) { + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, pid)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, pid)); } // Search for all supported devices if neither VID nor PID specified - else - { - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200_PRODUCT_ID)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200MINI_PRODUCT_ID)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B205MINI_PRODUCT_ID)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B200_PRODUCT_NI_ID)); - vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID)); + else { + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200_PRODUCT_ID)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200MINI_PRODUCT_ID)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B205MINI_PRODUCT_ID)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B200_PRODUCT_NI_ID)); + vid_pid_pair_list.push_back( + usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID)); } - std::vector<usb_device_handle::sptr> device_list = usb_device_handle::get_device_list(vid_pid_pair_list); + std::vector<usb_device_handle::sptr> device_list = + usb_device_handle::get_device_list(vid_pid_pair_list); - //locate the matching handle in the device list - for(usb_device_handle::sptr dev_handle: device_list) { + // locate the matching handle in the device list + for (usb_device_handle::sptr dev_handle : device_list) { try { - if (dev_handle->get_serial() == device_addr["serial"]){ + if (dev_handle->get_serial() == device_addr["serial"]) { handle = dev_handle; break; } - } catch (const uhd::exception&) { continue; } + } catch (const uhd::exception&) { + continue; + } } - UHD_ASSERT_THROW(handle.get() != NULL); //better be found + UHD_ASSERT_THROW(handle.get() != NULL); // better be found - //create control objects + // create control objects usb_control::sptr control = usb_control::make(handle, 0); - _iface = b200_iface::make(control); - this->check_fw_compat(); //check after making + _iface = b200_iface::make(control); + this->check_fw_compat(); // check after making //////////////////////////////////////////////////////////////////// // setup the mboard eeprom @@ -357,7 +390,8 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s const mboard_eeprom_t mb_eeprom = get_mb_eeprom(_iface); _tree->create<mboard_eeprom_t>(mb_path / "eeprom") .set(mb_eeprom) - .add_coerced_subscriber(std::bind(&b200_impl::set_mb_eeprom, this, std::placeholders::_1)); + .add_coerced_subscriber( + std::bind(&b200_impl::set_mb_eeprom, this, std::placeholders::_1)); //////////////////////////////////////////////////////////////////// // Identify the device type @@ -366,10 +400,10 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s std::string product_name; try { // This will throw if the product ID is invalid: - _product = get_b200_product(handle, mb_eeprom); + _product = get_b200_product(handle, mb_eeprom); default_file_name = B2XX_FPGA_FILE_NAME.get(_product); product_name = B2XX_STR_NAMES.get(_product); - } catch (const uhd::runtime_error &e) { + } catch (const uhd::runtime_error& e) { // The only reason we may let this pass is if the user specified // the FPGA file name: if (not device_addr.has_key("fpga")) { @@ -382,9 +416,9 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s _revision = boost::lexical_cast<size_t>(mb_eeprom["revision"]); } - UHD_LOGGER_INFO("B200") << "Detected Device: " << B2XX_STR_NAMES[_product] ; + UHD_LOGGER_INFO("B200") << "Detected Device: " << B2XX_STR_NAMES[_product]; - _gpsdo_capable = (not (_product == B200MINI or _product == B205MINI)); + _gpsdo_capable = (not(_product == B200MINI or _product == B205MINI)); //////////////////////////////////////////////////////////////////// // Set up frontend mapping @@ -399,27 +433,27 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s // does not have an FE2, so we don't swap FEs. // Swapped setup: - _fe1 = 1; - _fe2 = 0; + _fe1 = 1; + _fe2 = 0; _gpio_state.swap_atr = 1; // Unswapped setup: - if (_product == B200MINI or _product == B205MINI or (_product == B200 and _revision >= 5)) { - _fe1 = 0; //map radio0 to FE1 - _fe2 = 1; //map radio1 to FE2 + if (_product == B200MINI or _product == B205MINI + or (_product == B200 and _revision >= 5)) { + _fe1 = 0; // map radio0 to FE1 + _fe2 = 1; // map radio1 to FE2 _gpio_state.swap_atr = 0; // ATRs for radio0 are mapped to FE1 } //////////////////////////////////////////////////////////////////// // Load the FPGA image, then reset GPIF //////////////////////////////////////////////////////////////////// - //extract the FPGA path for the B200 + // extract the FPGA path for the B200 std::string b200_fpga_image = find_image_path( - device_addr.has_key("fpga")? device_addr["fpga"] : default_file_name - ); + device_addr.has_key("fpga") ? device_addr["fpga"] : default_file_name); uint32_t status = _iface->load_fpga(b200_fpga_image); - if(status != 0) { + if (status != 0) { throw uhd::runtime_error(str(boost::format("fx3 is in state %1%") % status)); } @@ -429,7 +463,7 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s // Create control transport //////////////////////////////////////////////////////////////////// uint8_t usb_speed = _iface->get_usb_speed(); - UHD_LOGGER_INFO("B200") << "Operating over USB " << (int) usb_speed << "." ; + UHD_LOGGER_INFO("B200") << "Operating over USB " << (int)usb_speed << "."; const std::string min_frame_size = (usb_speed == 3) ? "1024" : "512"; device_addr_t ctrl_xport_args; @@ -439,32 +473,38 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s ctrl_xport_args["num_send_frames"] = "16"; // This may throw a uhd::usb_error, which will be caught by b200_make(). - _ctrl_transport = usb_zero_copy::make( - handle, - B200_USB_CTRL_RECV_INTERFACE, B200_USB_CTRL_RECV_ENDPOINT, //interface, endpoint - B200_USB_CTRL_SEND_INTERFACE, B200_USB_CTRL_SEND_ENDPOINT, //interface, endpoint - ctrl_xport_args - ); - while (_ctrl_transport->get_recv_buff(0.0)){} //flush ctrl xport - _tree->create<double>(mb_path / "link_max_rate").set((usb_speed == 3) ? B200_MAX_RATE_USB3 : B200_MAX_RATE_USB2); + _ctrl_transport = usb_zero_copy::make(handle, + B200_USB_CTRL_RECV_INTERFACE, + B200_USB_CTRL_RECV_ENDPOINT, // interface, endpoint + B200_USB_CTRL_SEND_INTERFACE, + B200_USB_CTRL_SEND_ENDPOINT, // interface, endpoint + ctrl_xport_args); + while (_ctrl_transport->get_recv_buff(0.0)) { + } // flush ctrl xport + _tree->create<double>(mb_path / "link_max_rate") + .set((usb_speed == 3) ? B200_MAX_RATE_USB3 : B200_MAX_RATE_USB2); //////////////////////////////////////////////////////////////////// // Async task structure //////////////////////////////////////////////////////////////////// _async_task_data.reset(new AsyncTaskData()); - _async_task_data->async_md.reset(new async_md_type(1000/*messages deep*/)); - if (_gpsdo_capable) - { - _async_task_data->gpsdo_uart = b200_uart::make(_ctrl_transport, B200_TX_GPS_UART_SID); + _async_task_data->async_md.reset(new async_md_type(1000 /*messages deep*/)); + if (_gpsdo_capable) { + _async_task_data->gpsdo_uart = + b200_uart::make(_ctrl_transport, B200_TX_GPS_UART_SID); } - _async_task = uhd::msg_task::make(std::bind(&b200_impl::handle_async_task, this, _ctrl_transport, _async_task_data)); + _async_task = uhd::msg_task::make(std::bind( + &b200_impl::handle_async_task, this, _ctrl_transport, _async_task_data)); //////////////////////////////////////////////////////////////////// // Local control endpoint //////////////////////////////////////////////////////////////////// - _local_ctrl = radio_ctrl_core_3000::make(false/*lilE*/, _ctrl_transport, zero_copy_if::sptr()/*null*/, B200_LOCAL_CTRL_SID); + _local_ctrl = radio_ctrl_core_3000::make(false /*lilE*/, + _ctrl_transport, + zero_copy_if::sptr() /*null*/, + B200_LOCAL_CTRL_SID); _local_ctrl->hold_task(_async_task); - _async_task_data->local_ctrl = _local_ctrl; //weak + _async_task_data->local_ctrl = _local_ctrl; // weak this->check_fpga_compat(); /* Initialize the GPIOs, set the default bandsels to the lower range. Note @@ -475,30 +515,21 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s //////////////////////////////////////////////////////////////////// // Create the GPSDO control //////////////////////////////////////////////////////////////////// - if (_gpsdo_capable) - { - - if ((_local_ctrl->peek32(RB32_CORE_STATUS) & 0xff) != B200_GPSDO_ST_NONE) - { + if (_gpsdo_capable) { + if ((_local_ctrl->peek32(RB32_CORE_STATUS) & 0xff) != B200_GPSDO_ST_NONE) { UHD_LOGGER_INFO("B200") << "Detecting internal GPSDO.... " << std::flush; - try - { + try { _gps = gps_ctrl::make(_async_task_data->gpsdo_uart); + } catch (std::exception& e) { + UHD_LOGGER_ERROR("B200") + << "An error occurred making GPSDO control: " << e.what(); } - catch(std::exception &e) - { - UHD_LOGGER_ERROR("B200") << "An error occurred making GPSDO control: " << e.what(); - } - if (_gps and _gps->gps_detected()) - { - for(const std::string &name: _gps->get_sensors()) - { + if (_gps and _gps->gps_detected()) { + for (const std::string& name : _gps->get_sensors()) { _tree->create<sensor_value_t>(mb_path / "sensors" / name) .set_publisher(std::bind(&gps_ctrl::get_sensor, _gps, name)); } - } - else - { + } else { _local_ctrl->poke32(TOREG(SR_CORE_GPSDO_ST), B200_GPSDO_ST_NONE); } } @@ -509,7 +540,8 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s //////////////////////////////////////////////////////////////////// _tree->create<std::string>("/name").set("B-Series Device"); _tree->create<std::string>(mb_path / "name").set(product_name); - _tree->create<std::string>(mb_path / "codename").set((_product == B200MINI or _product == B205MINI) ? "Pixie" : "Sasquatch"); + _tree->create<std::string>(mb_path / "codename") + .set((_product == B200MINI or _product == B205MINI) ? "Pixie" : "Sasquatch"); //////////////////////////////////////////////////////////////////// // Create data transport @@ -519,22 +551,18 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s //////////////////////////////////////////////////////////////////// device_addr_t data_xport_args; const int max_transfer = usb_speed == 3 ? 1024 : 512; - int recv_frame_size = device_addr.cast<int>( - "recv_frame_size", - B200_USB_DATA_DEFAULT_FRAME_SIZE - ); + int recv_frame_size = + device_addr.cast<int>("recv_frame_size", B200_USB_DATA_DEFAULT_FRAME_SIZE); // Check that recv_frame_size limits. if (recv_frame_size < B200_USB_DATA_MIN_RECV_FRAME_SIZE) { - UHD_LOGGER_WARNING("B200") - << "Requested recv_frame_size of " << recv_frame_size - << " is too small. It will be set to " - << B200_USB_DATA_MIN_RECV_FRAME_SIZE << "."; + UHD_LOGGER_WARNING("B200") << "Requested recv_frame_size of " << recv_frame_size + << " is too small. It will be set to " + << B200_USB_DATA_MIN_RECV_FRAME_SIZE << "."; recv_frame_size = B200_USB_DATA_MIN_RECV_FRAME_SIZE; } else if (recv_frame_size > B200_USB_DATA_MAX_RECV_FRAME_SIZE) { - UHD_LOGGER_WARNING("B200") - << "Requested recv_frame_size of " << recv_frame_size - << " is too large. It will be set to " - << B200_USB_DATA_MAX_RECV_FRAME_SIZE << "."; + UHD_LOGGER_WARNING("B200") << "Requested recv_frame_size of " << recv_frame_size + << " is too large. It will be set to " + << B200_USB_DATA_MAX_RECV_FRAME_SIZE << "."; recv_frame_size = B200_USB_DATA_MAX_RECV_FRAME_SIZE; } else if (recv_frame_size % max_transfer == 0 or recv_frame_size % 8 != 0) { // The Cypress FX3 does not properly handle recv_frame_sizes that are @@ -553,37 +581,39 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s UHD_LOGGER_WARNING("B200") << "The recv_frame_size must be a multiple of 8 bytes and not a multiple of " << max_transfer << " bytes. Requested recv_frame_size of " - << device_addr["recv_frame_size"] - << " coerced to " << recv_frame_size << "."; + << device_addr["recv_frame_size"] << " coerced to " << recv_frame_size << "."; } data_xport_args["recv_frame_size"] = std::to_string(recv_frame_size); data_xport_args["num_recv_frames"] = device_addr.get("num_recv_frames", "16"); - data_xport_args["send_frame_size"] = device_addr.get("send_frame_size", std::to_string(B200_USB_DATA_DEFAULT_FRAME_SIZE)); + data_xport_args["send_frame_size"] = device_addr.get( + "send_frame_size", std::to_string(B200_USB_DATA_DEFAULT_FRAME_SIZE)); data_xport_args["num_send_frames"] = device_addr.get("num_send_frames", "16"); // This may throw a uhd::usb_error, which will be caught by b200_make(). - _data_transport = usb_zero_copy::make( - handle, // identifier - B200_USB_DATA_RECV_INTERFACE, B200_USB_DATA_RECV_ENDPOINT, //interface, endpoint - B200_USB_DATA_SEND_INTERFACE, B200_USB_DATA_SEND_ENDPOINT, //interface, endpoint - data_xport_args // param hints + _data_transport = usb_zero_copy::make(handle, // identifier + B200_USB_DATA_RECV_INTERFACE, + B200_USB_DATA_RECV_ENDPOINT, // interface, endpoint + B200_USB_DATA_SEND_INTERFACE, + B200_USB_DATA_SEND_ENDPOINT, // interface, endpoint + data_xport_args // param hints ); - while (_data_transport->get_recv_buff(0.0)){} //flush ctrl xport + while (_data_transport->get_recv_buff(0.0)) { + } // flush ctrl xport _demux = recv_packet_demuxer_3000::make(_data_transport); //////////////////////////////////////////////////////////////////// // create time and clock control objects //////////////////////////////////////////////////////////////////// _spi_iface = b200_local_spi_core::make(_local_ctrl); - if (not (_product == B200MINI or _product == B205MINI)) { + if (not(_product == B200MINI or _product == B205MINI)) { _adf4001_iface = std::make_shared<b200_ref_pll_ctrl>(_spi_iface); } //////////////////////////////////////////////////////////////////// // Init codec - turns on clocks //////////////////////////////////////////////////////////////////// - UHD_LOGGER_INFO("B200") << "Initialize CODEC control..." ; + UHD_LOGGER_INFO("B200") << "Initialize CODEC control..."; reset_codec(); ad9361_params::sptr client_settings; if (_product == B200MINI or _product == B205MINI) { @@ -598,13 +628,15 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s //////////////////////////////////////////////////////////////////// { const fs_path codec_path = mb_path / ("rx_codecs") / "A"; - _tree->create<std::string>(codec_path / "name").set(product_name+" RX dual ADC"); - _tree->create<int>(codec_path / "gains"); //empty cuz gains are in frontend + _tree->create<std::string>(codec_path / "name") + .set(product_name + " RX dual ADC"); + _tree->create<int>(codec_path / "gains"); // empty cuz gains are in frontend } { const fs_path codec_path = mb_path / ("tx_codecs") / "A"; - _tree->create<std::string>(codec_path / "name").set(product_name+" TX dual DAC"); - _tree->create<int>(codec_path / "gains"); //empty cuz gains are in frontend + _tree->create<std::string>(codec_path / "name") + .set(product_name + " TX dual DAC"); + _tree->create<int>(codec_path / "gains"); // empty cuz gains are in frontend } //////////////////////////////////////////////////////////////////// @@ -613,12 +645,11 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s _tree->create<double>(mb_path / "tick_rate") .set_coercer(std::bind(&b200_impl::set_tick_rate, this, std::placeholders::_1)) .set_publisher(std::bind(&b200_impl::get_tick_rate, this)) - .add_coerced_subscriber(std::bind(&b200_impl::update_tick_rate, this, std::placeholders::_1)); - _tree->create<meta_range_t>(mb_path / "tick_rate/range") - .set_publisher([this](){ - return this->_codec_ctrl->get_clock_rate_range(); - }) - ; + .add_coerced_subscriber( + std::bind(&b200_impl::update_tick_rate, this, std::placeholders::_1)); + _tree->create<meta_range_t>(mb_path / "tick_rate/range").set_publisher([this]() { + return this->_codec_ctrl->get_clock_rate_range(); + }); _tree->create<time_spec_t>(mb_path / "time" / "cmd"); _tree->create<bool>(mb_path / "auto_tick_rate").set(false); @@ -631,22 +662,27 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s //////////////////////////////////////////////////////////////////// // create frontend mapping //////////////////////////////////////////////////////////////////// - std::vector<size_t> default_map(2, 0); default_map[1] = 1; // Set this to A->0 B->1 even if there's only A - _tree->create<std::vector<size_t> >(mb_path / "rx_chan_dsp_mapping").set(default_map); - _tree->create<std::vector<size_t> >(mb_path / "tx_chan_dsp_mapping").set(default_map); + std::vector<size_t> default_map(2, 0); + default_map[1] = 1; // Set this to A->0 B->1 even if there's only A + _tree->create<std::vector<size_t>>(mb_path / "rx_chan_dsp_mapping").set(default_map); + _tree->create<std::vector<size_t>>(mb_path / "tx_chan_dsp_mapping").set(default_map); _tree->create<subdev_spec_t>(mb_path / "rx_subdev_spec") - .set_coercer(std::bind(&b200_impl::coerce_subdev_spec, this, std::placeholders::_1)) + .set_coercer( + std::bind(&b200_impl::coerce_subdev_spec, this, std::placeholders::_1)) .set(subdev_spec_t()) - .add_coerced_subscriber(std::bind(&b200_impl::update_subdev_spec, this, "rx", std::placeholders::_1)); + .add_coerced_subscriber( + std::bind(&b200_impl::update_subdev_spec, this, "rx", std::placeholders::_1)); _tree->create<subdev_spec_t>(mb_path / "tx_subdev_spec") - .set_coercer(std::bind(&b200_impl::coerce_subdev_spec, this, std::placeholders::_1)) + .set_coercer( + std::bind(&b200_impl::coerce_subdev_spec, this, std::placeholders::_1)) .set(subdev_spec_t()) - .add_coerced_subscriber(std::bind(&b200_impl::update_subdev_spec, this, "tx", std::placeholders::_1)); + .add_coerced_subscriber( + std::bind(&b200_impl::update_subdev_spec, this, "tx", std::placeholders::_1)); //////////////////////////////////////////////////////////////////// // setup radio control //////////////////////////////////////////////////////////////////// - UHD_LOGGER_INFO("B200") << "Initialize Radio control..." ; + UHD_LOGGER_INFO("B200") << "Initialize Radio control..."; const size_t num_radio_chains = ((_local_ctrl->peek32(RB32_CORE_STATUS) >> 8) & 0xff); UHD_ASSERT_THROW(num_radio_chains > 0); UHD_ASSERT_THROW(num_radio_chains <= 2); @@ -656,141 +692,162 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s for (size_t i = 0; i < _radio_perifs.size(); i++) this->setup_radio(i); - //now test each radio module's connection to the codec interface - for (radio_perifs_t &perif : _radio_perifs) { + // now test each radio module's connection to the codec interface + for (radio_perifs_t& perif : _radio_perifs) { _codec_mgr->loopback_self_test( - [&perif](const uint32_t value){ + [&perif](const uint32_t value) { perif.ctrl->poke32(TOREG(SR_CODEC_IDLE), value); }, - [&perif](){ - return perif.ctrl->peek64(RB64_CODEC_READBACK); - } - ); + [&perif]() { return perif.ctrl->peek64(RB64_CODEC_READBACK); }); } - //register time now and pps onto available radio cores + // register time now and pps onto available radio cores _tree->create<time_spec_t>(mb_path / "time" / "now") .set_publisher(std::bind(&time_core_3000::get_time_now, _radio_perifs[0].time64)) - .add_coerced_subscriber(std::bind(&b200_impl::set_time, this, std::placeholders::_1)) + .add_coerced_subscriber( + std::bind(&b200_impl::set_time, this, std::placeholders::_1)) .set(0.0); - //re-sync the times when the tick rate changes + // re-sync the times when the tick rate changes _tree->access<double>(mb_path / "tick_rate") .add_coerced_subscriber(std::bind(&b200_impl::sync_times, this)); _tree->create<time_spec_t>(mb_path / "time" / "pps") - .set_publisher(std::bind(&time_core_3000::get_time_last_pps, _radio_perifs[0].time64)); - for(radio_perifs_t &perif: _radio_perifs) - { + .set_publisher( + std::bind(&time_core_3000::get_time_last_pps, _radio_perifs[0].time64)); + for (radio_perifs_t& perif : _radio_perifs) { _tree->access<time_spec_t>(mb_path / "time" / "pps") - .add_coerced_subscriber(std::bind(&time_core_3000::set_time_next_pps, perif.time64, std::placeholders::_1)); + .add_coerced_subscriber(std::bind( + &time_core_3000::set_time_next_pps, perif.time64, std::placeholders::_1)); } - //setup time source props + // setup time source props const std::vector<std::string> time_sources = - (_gpsdo_capable) ? - std::vector<std::string>{"none", "internal", "external", "gpsdo"} : - std::vector<std::string>{"none", "internal", "external"}; - _tree->create<std::vector<std::string> >(mb_path / "time_source" / "options") + (_gpsdo_capable) + ? std::vector<std::string>{"none", "internal", "external", "gpsdo"} + : std::vector<std::string>{"none", "internal", "external"}; + _tree->create<std::vector<std::string>>(mb_path / "time_source" / "options") .set(time_sources); _tree->create<std::string>(mb_path / "time_source" / "value") - .set_coercer(std::bind(&check_option_valid, "time source", time_sources, std::placeholders::_1)) - .add_coerced_subscriber(std::bind(&b200_impl::update_time_source, this, std::placeholders::_1)); - //setup reference source props + .set_coercer(std::bind( + &check_option_valid, "time source", time_sources, std::placeholders::_1)) + .add_coerced_subscriber( + std::bind(&b200_impl::update_time_source, this, std::placeholders::_1)); + // setup reference source props const std::vector<std::string> clock_sources = - (_gpsdo_capable) ? - std::vector<std::string>{"internal", "external", "gpsdo"} : - std::vector<std::string>{"internal", "external"}; - _tree->create<std::vector<std::string> >(mb_path / "clock_source" / "options") + (_gpsdo_capable) ? std::vector<std::string>{"internal", "external", "gpsdo"} + : std::vector<std::string>{"internal", "external"}; + _tree->create<std::vector<std::string>>(mb_path / "clock_source" / "options") .set(clock_sources); _tree->create<std::string>(mb_path / "clock_source" / "value") - .set_coercer(std::bind(&check_option_valid, "clock source", clock_sources, std::placeholders::_1)) - .add_coerced_subscriber(std::bind(&b200_impl::update_clock_source, this, std::placeholders::_1)); + .set_coercer(std::bind( + &check_option_valid, "clock source", clock_sources, std::placeholders::_1)) + .add_coerced_subscriber( + std::bind(&b200_impl::update_clock_source, this, std::placeholders::_1)); //////////////////////////////////////////////////////////////////// // front panel gpio //////////////////////////////////////////////////////////////////// - _radio_perifs[0].fp_gpio = gpio_atr_3000::make(_radio_perifs[0].ctrl, TOREG(SR_FP_GPIO), RB32_FP_GPIO); - for(const gpio_attr_map_t::value_type attr: gpio_attr_map) - { switch (attr.first){ - case usrp::gpio_atr::GPIO_SRC: - _tree->create<std::vector<std::string>>(mb_path / "gpio" / "FP0" / attr.second) - .set(std::vector<std::string>(32, usrp::gpio_atr::default_attr_value_map.at(attr.first))) - .add_coerced_subscriber([this](const std::vector<std::string>&){ - throw uhd::runtime_error("This device does not support setting the GPIO_SRC attribute."); - }); - break; - case usrp::gpio_atr::GPIO_CTRL: - case usrp::gpio_atr::GPIO_DDR: - _tree->create<std::vector<std::string>>(mb_path / "gpio" / "FP0" / attr.second) - .set(std::vector<std::string>(32, usrp::gpio_atr::default_attr_value_map.at(attr.first))) - .add_coerced_subscriber([this, attr](const std::vector<std::string> str_val){ - uint32_t val = 0; - for(size_t i = 0 ; i < str_val.size() ; i++){ - val += usrp::gpio_atr::gpio_attr_value_pair.at(attr.second).at(str_val[i])<<i; - } - _radio_perifs[0].fp_gpio->set_gpio_attr(attr.first, val); - }); - break; - case usrp::gpio_atr::GPIO_READBACK: - _tree->create<uint32_t>(mb_path / "gpio" / "FP0" / "READBACK") - .set_publisher(std::bind(&gpio_atr_3000::read_gpio, _radio_perifs[0].fp_gpio)); - break; - default: - _tree->create<uint32_t>(mb_path / "gpio" / "FP0" / attr.second) + _radio_perifs[0].fp_gpio = + gpio_atr_3000::make(_radio_perifs[0].ctrl, TOREG(SR_FP_GPIO), RB32_FP_GPIO); + for (const gpio_attr_map_t::value_type attr : gpio_attr_map) { + switch (attr.first) { + case usrp::gpio_atr::GPIO_SRC: + _tree + ->create<std::vector<std::string>>( + mb_path / "gpio" / "FP0" / attr.second) + .set(std::vector<std::string>( + 32, usrp::gpio_atr::default_attr_value_map.at(attr.first))) + .add_coerced_subscriber([this](const std::vector<std::string>&) { + throw uhd::runtime_error("This device does not support setting " + "the GPIO_SRC attribute."); + }); + break; + case usrp::gpio_atr::GPIO_CTRL: + case usrp::gpio_atr::GPIO_DDR: + _tree + ->create<std::vector<std::string>>( + mb_path / "gpio" / "FP0" / attr.second) + .set(std::vector<std::string>( + 32, usrp::gpio_atr::default_attr_value_map.at(attr.first))) + .add_coerced_subscriber([this, attr]( + const std::vector<std::string> str_val) { + uint32_t val = 0; + for (size_t i = 0; i < str_val.size(); i++) { + val += usrp::gpio_atr::gpio_attr_value_pair.at(attr.second) + .at(str_val[i]) + << i; + } + _radio_perifs[0].fp_gpio->set_gpio_attr(attr.first, val); + }); + break; + case usrp::gpio_atr::GPIO_READBACK: + _tree->create<uint32_t>(mb_path / "gpio" / "FP0" / "READBACK") + .set_publisher( + std::bind(&gpio_atr_3000::read_gpio, _radio_perifs[0].fp_gpio)); + break; + default: + _tree->create<uint32_t>(mb_path / "gpio" / "FP0" / attr.second) .set(0) - .add_coerced_subscriber(std::bind(&gpio_atr_3000::set_gpio_attr, _radio_perifs[0].fp_gpio, attr.first, std::placeholders::_1)); - } + .add_coerced_subscriber(std::bind(&gpio_atr_3000::set_gpio_attr, + _radio_perifs[0].fp_gpio, + attr.first, + std::placeholders::_1)); + } } //////////////////////////////////////////////////////////////////// // dboard eeproms but not really //////////////////////////////////////////////////////////////////// dboard_eeprom_t db_eeprom; - _tree->create<dboard_eeprom_t>(mb_path / "dboards" / "A" / "rx_eeprom").set(db_eeprom); - _tree->create<dboard_eeprom_t>(mb_path / "dboards" / "A" / "tx_eeprom").set(db_eeprom); - _tree->create<dboard_eeprom_t>(mb_path / "dboards" / "A" / "gdb_eeprom").set(db_eeprom); + _tree->create<dboard_eeprom_t>(mb_path / "dboards" / "A" / "rx_eeprom") + .set(db_eeprom); + _tree->create<dboard_eeprom_t>(mb_path / "dboards" / "A" / "tx_eeprom") + .set(db_eeprom); + _tree->create<dboard_eeprom_t>(mb_path / "dboards" / "A" / "gdb_eeprom") + .set(db_eeprom); //////////////////////////////////////////////////////////////////// // do some post-init tasks //////////////////////////////////////////////////////////////////// // Init the clock rate and the auto mcr appropriately if (not device_addr.has_key("master_clock_rate")) { - UHD_LOGGER_INFO("B200") << "Setting master clock rate selection to 'automatic'." ; + UHD_LOGGER_INFO("B200") << "Setting master clock rate selection to 'automatic'."; } // We can automatically choose a master clock rate, but not if the user specifies one - const double default_tick_rate = device_addr.cast<double>("master_clock_rate", ad936x_manager::DEFAULT_TICK_RATE); + const double default_tick_rate = + device_addr.cast<double>("master_clock_rate", ad936x_manager::DEFAULT_TICK_RATE); _tree->access<double>(mb_path / "tick_rate").set(default_tick_rate); - _tree->access<bool>(mb_path / "auto_tick_rate").set(not device_addr.has_key("master_clock_rate")); + _tree->access<bool>(mb_path / "auto_tick_rate") + .set(not device_addr.has_key("master_clock_rate")); - //subdev spec contains full width of selections + // subdev spec contains full width of selections subdev_spec_t rx_spec, tx_spec; - for(const std::string &fe: _tree->list(mb_path / "dboards" / "A" / "rx_frontends")) - { + for (const std::string& fe : + _tree->list(mb_path / "dboards" / "A" / "rx_frontends")) { rx_spec.push_back(subdev_spec_pair_t("A", fe)); } - for(const std::string &fe: _tree->list(mb_path / "dboards" / "A" / "tx_frontends")) - { + for (const std::string& fe : + _tree->list(mb_path / "dboards" / "A" / "tx_frontends")) { tx_spec.push_back(subdev_spec_pair_t("A", fe)); } _tree->access<subdev_spec_t>(mb_path / "rx_subdev_spec").set(rx_spec); _tree->access<subdev_spec_t>(mb_path / "tx_subdev_spec").set(tx_spec); - //init to internal clock and time source + // init to internal clock and time source _tree->access<std::string>(mb_path / "clock_source/value").set("internal"); _tree->access<std::string>(mb_path / "time_source/value").set("internal"); // Set the DSP chains to some safe value for (size_t i = 0; i < _radio_perifs.size(); i++) { - _radio_perifs[i].ddc->set_host_rate(default_tick_rate / ad936x_manager::DEFAULT_DECIM); - _radio_perifs[i].duc->set_host_rate(default_tick_rate / ad936x_manager::DEFAULT_INTERP); + _radio_perifs[i].ddc->set_host_rate( + default_tick_rate / ad936x_manager::DEFAULT_DECIM); + _radio_perifs[i].duc->set_host_rate( + default_tick_rate / ad936x_manager::DEFAULT_INTERP); } } b200_impl::~b200_impl(void) { - UHD_SAFE_CALL - ( - _async_task.reset(); - ) + UHD_SAFE_CALL(_async_task.reset();) } /*********************************************************************** @@ -798,7 +855,7 @@ b200_impl::~b200_impl(void) **********************************************************************/ void b200_impl::setup_radio(const size_t dspno) { - radio_perifs_t &perif = _radio_perifs[dspno]; + radio_perifs_t& perif = _radio_perifs[dspno]; const fs_path mb_path = "/mboards/0"; //////////////////////////////////////////////////////////////////// @@ -810,16 +867,15 @@ void b200_impl::setup_radio(const size_t dspno) // radio control //////////////////////////////////////////////////////////////////// perif.ctrl = radio_ctrl_core_3000::make( - false/*lilE*/, - _ctrl_transport, - zero_copy_if::sptr()/*null*/, - sid); + false /*lilE*/, _ctrl_transport, zero_copy_if::sptr() /*null*/, sid); perif.ctrl->hold_task(_async_task); - _async_task_data->radio_ctrl[dspno] = perif.ctrl; //weak + _async_task_data->radio_ctrl[dspno] = perif.ctrl; // weak _tree->access<time_spec_t>(mb_path / "time" / "cmd") - .add_coerced_subscriber(std::bind(&radio_ctrl_core_3000::set_time, perif.ctrl, std::placeholders::_1)); + .add_coerced_subscriber(std::bind( + &radio_ctrl_core_3000::set_time, perif.ctrl, std::placeholders::_1)); _tree->access<double>(mb_path / "tick_rate") - .add_coerced_subscriber(std::bind(&radio_ctrl_core_3000::set_tick_rate, perif.ctrl, std::placeholders::_1)); + .add_coerced_subscriber(std::bind( + &radio_ctrl_core_3000::set_tick_rate, perif.ctrl, std::placeholders::_1)); this->register_loopback_self_test(perif.ctrl); //////////////////////////////////////////////////////////////////// @@ -830,19 +886,17 @@ void b200_impl::setup_radio(const size_t dspno) // create rx dsp control objects perif.framer = rx_vita_core_3000::make(perif.ctrl, TOREG(SR_RX_CTRL)); perif.ddc = rx_dsp_core_3000::make(perif.ctrl, TOREG(SR_RX_DSP), true /*is_b200?*/); - perif.ddc->set_link_rate(10e9/8); //whatever + perif.ddc->set_link_rate(10e9 / 8); // whatever perif.ddc->set_mux(usrp::fe_connection_t(dspno == 1 ? "IbQb" : "IQ")); perif.ddc->set_freq(rx_dsp_core_3000::DEFAULT_CORDIC_FREQ); perif.deframer = tx_vita_core_3000::make_no_radio_buff(perif.ctrl, TOREG(SR_TX_CTRL)); - perif.duc = tx_dsp_core_3000::make(perif.ctrl, TOREG(SR_TX_DSP)); - perif.duc->set_link_rate(10e9/8); //whatever + perif.duc = tx_dsp_core_3000::make(perif.ctrl, TOREG(SR_TX_DSP)); + perif.duc->set_link_rate(10e9 / 8); // whatever perif.duc->set_freq(tx_dsp_core_3000::DEFAULT_CORDIC_FREQ); if (_enable_user_regs) { UHD_LOG_DEBUG("B200", "Enabling user settings registers"); - perif.user_settings = user_settings_core_3000::make(perif.ctrl, - TOREG(SR_USER_SR_BASE), - TOREG(SR_USER_RB_ADDR) - ); + perif.user_settings = user_settings_core_3000::make( + perif.ctrl, TOREG(SR_USER_SR_BASE), TOREG(SR_USER_RB_ADDR)); if (!perif.user_settings) { const std::string error_msg = "Failed to create user settings bus!"; UHD_LOG_ERROR("B200", error_msg); @@ -865,21 +919,30 @@ void b200_impl::setup_radio(const size_t dspno) perif.ddc->populate_subtree(_tree->subtree(rx_dsp_path)); _tree->create<bool>(rx_dsp_path / "rate" / "set").set(false); _tree->access<double>(rx_dsp_path / "rate" / "value") - .set_coercer(std::bind(&b200_impl::coerce_rx_samp_rate, this, perif.ddc, dspno, std::placeholders::_1)) - .add_coerced_subscriber([this, rx_dsp_path](const double){ + .set_coercer(std::bind(&b200_impl::coerce_rx_samp_rate, + this, + perif.ddc, + dspno, + std::placeholders::_1)) + .add_coerced_subscriber([this, rx_dsp_path](const double) { if (this->_tree) { - this->_tree->access<bool>(rx_dsp_path / "rate" / "set") - .set(true); + this->_tree->access<bool>(rx_dsp_path / "rate" / "set").set(true); } }) - .add_coerced_subscriber(std::bind(&b200_impl::update_rx_samp_rate, this, dspno, std::placeholders::_1)) - ; + .add_coerced_subscriber(std::bind( + &b200_impl::update_rx_samp_rate, this, dspno, std::placeholders::_1)); _tree->create<stream_cmd_t>(rx_dsp_path / "stream_cmd") - .add_coerced_subscriber(std::bind(&rx_vita_core_3000::issue_stream_command, perif.framer, std::placeholders::_1)); + .add_coerced_subscriber(std::bind(&rx_vita_core_3000::issue_stream_command, + perif.framer, + std::placeholders::_1)); _tree->access<double>(mb_path / "tick_rate") - .add_coerced_subscriber(std::bind(&rx_vita_core_3000::set_tick_rate, perif.framer, std::placeholders::_1)) - .add_coerced_subscriber(std::bind(&b200_impl::update_rx_dsp_tick_rate, this, std::placeholders::_1, perif.ddc, rx_dsp_path)) - ; + .add_coerced_subscriber(std::bind( + &rx_vita_core_3000::set_tick_rate, perif.framer, std::placeholders::_1)) + .add_coerced_subscriber(std::bind(&b200_impl::update_rx_dsp_tick_rate, + this, + std::placeholders::_1, + perif.ddc, + rx_dsp_path)); //////////////////////////////////////////////////////////////////// // create tx dsp control objects @@ -888,54 +951,58 @@ void b200_impl::setup_radio(const size_t dspno) perif.duc->populate_subtree(_tree->subtree(tx_dsp_path)); _tree->create<bool>(tx_dsp_path / "rate" / "set").set(false); _tree->access<double>(tx_dsp_path / "rate" / "value") - .set_coercer(std::bind(&b200_impl::coerce_tx_samp_rate, this, perif.duc, dspno, std::placeholders::_1)) - .add_coerced_subscriber([this, tx_dsp_path](const double){ + .set_coercer(std::bind(&b200_impl::coerce_tx_samp_rate, + this, + perif.duc, + dspno, + std::placeholders::_1)) + .add_coerced_subscriber([this, tx_dsp_path](const double) { if (this->_tree) { - this->_tree->access<bool>(tx_dsp_path / "rate" / "set") - .set(true); + this->_tree->access<bool>(tx_dsp_path / "rate" / "set").set(true); } }) - .add_coerced_subscriber(std::bind(&b200_impl::update_tx_samp_rate, this, dspno, std::placeholders::_1)) - ; + .add_coerced_subscriber(std::bind( + &b200_impl::update_tx_samp_rate, this, dspno, std::placeholders::_1)); _tree->access<double>(mb_path / "tick_rate") - .add_coerced_subscriber(std::bind(&b200_impl::update_tx_dsp_tick_rate, this, std::placeholders::_1, perif.duc, tx_dsp_path)) - ; + .add_coerced_subscriber(std::bind(&b200_impl::update_tx_dsp_tick_rate, + this, + std::placeholders::_1, + perif.duc, + tx_dsp_path)); //////////////////////////////////////////////////////////////////// // create RF frontend interfacing //////////////////////////////////////////////////////////////////// for (direction_t dir : std::vector<direction_t>{RX_DIRECTION, TX_DIRECTION}) { - const std::string x = (dir == RX_DIRECTION) ? "rx" : "tx"; - const std::string key = std::string(((dir == RX_DIRECTION) ? "RX" : "TX")) + std::string(((dspno == _fe1) ? "1" : "2")); - const fs_path rf_fe_path - = mb_path / "dboards" / "A" / (x + "_frontends") / (dspno ? "B" : "A"); + const std::string x = (dir == RX_DIRECTION) ? "rx" : "tx"; + const std::string key = std::string(((dir == RX_DIRECTION) ? "RX" : "TX")) + + std::string(((dspno == _fe1) ? "1" : "2")); + const fs_path rf_fe_path = + mb_path / "dboards" / "A" / (x + "_frontends") / (dspno ? "B" : "A"); // This will connect all the AD936x-specific items - _codec_mgr->populate_frontend_subtree( - _tree->subtree(rf_fe_path), key, dir - ); + _codec_mgr->populate_frontend_subtree(_tree->subtree(rf_fe_path), key, dir); // Now connect all the b200_impl-specific items _tree->create<sensor_value_t>(rf_fe_path / "sensors" / "lo_locked") - .set_publisher(std::bind(&b200_impl::get_fe_pll_locked, this, dir == TX_DIRECTION)) - ; + .set_publisher( + std::bind(&b200_impl::get_fe_pll_locked, this, dir == TX_DIRECTION)); _tree->access<double>(rf_fe_path / "freq" / "value") - .add_coerced_subscriber(std::bind(&b200_impl::update_bandsel, this, key, std::placeholders::_1)) - ; - if (dir == RX_DIRECTION) - { + .add_coerced_subscriber( + std::bind(&b200_impl::update_bandsel, this, key, std::placeholders::_1)); + if (dir == RX_DIRECTION) { static const std::vector<std::string> ants{"TX/RX", "RX2"}; - _tree->create<std::vector<std::string> >(rf_fe_path / "antenna" / "options").set(ants); + _tree->create<std::vector<std::string>>(rf_fe_path / "antenna" / "options") + .set(ants); _tree->create<std::string>(rf_fe_path / "antenna" / "value") - .add_coerced_subscriber(std::bind(&b200_impl::update_antenna_sel, this, dspno, std::placeholders::_1)) - .set("RX2") - ; + .add_coerced_subscriber(std::bind( + &b200_impl::update_antenna_sel, this, dspno, std::placeholders::_1)) + .set("RX2"); - } - else if (dir == TX_DIRECTION) - { + } else if (dir == TX_DIRECTION) { static const std::vector<std::string> ants(1, "TX/RX"); - _tree->create<std::vector<std::string> >(rf_fe_path / "antenna" / "options").set(ants); + _tree->create<std::vector<std::string>>(rf_fe_path / "antenna" / "options") + .set(ants); _tree->create<std::string>(rf_fe_path / "antenna" / "value").set("TX/RX"); } @@ -955,75 +1022,71 @@ void b200_impl::register_loopback_self_test(wb_iface::sptr iface) bool test_fail = false; UHD_LOGGER_INFO("B200") << "Performing register loopback test... "; size_t hash = size_t(time(NULL)); - for (size_t i = 0; i < 100; i++) - { + for (size_t i = 0; i < 100; i++) { boost::hash_combine(hash, i); iface->poke32(TOREG(SR_TEST), uint32_t(hash)); test_fail = iface->peek32(RB32_TEST) != uint32_t(hash); - if (test_fail) break; //exit loop on any failure + if (test_fail) + break; // exit loop on any failure } - UHD_LOGGER_INFO("B200") << "Register loopback test " << ((test_fail)? "failed" : "passed") ; + UHD_LOGGER_INFO("B200") << "Register loopback test " + << ((test_fail) ? "failed" : "passed"); } /*********************************************************************** * Sample and tick rate comprehension below **********************************************************************/ -void b200_impl::enforce_tick_rate_limits(size_t chan_count, double tick_rate, const std::string &direction /*= ""*/) +void b200_impl::enforce_tick_rate_limits( + size_t chan_count, double tick_rate, const std::string& direction /*= ""*/) { const size_t max_chans = 2; - if (chan_count > max_chans) - { + if (chan_count > max_chans) { throw uhd::value_error(boost::str( - boost::format("cannot not setup %d %s channels (maximum is %d)") - % chan_count - % (direction.empty() ? "data" : direction) - % max_chans - )); - } - else - { - const double max_tick_rate = ad9361_device_t::AD9361_MAX_CLOCK_RATE / ((chan_count <= 1) ? 1 : 2); - if (tick_rate - max_tick_rate >= 1.0) - { + boost::format("cannot not setup %d %s channels (maximum is %d)") % chan_count + % (direction.empty() ? "data" : direction) % max_chans)); + } else { + const double max_tick_rate = + ad9361_device_t::AD9361_MAX_CLOCK_RATE / ((chan_count <= 1) ? 1 : 2); + if (tick_rate - max_tick_rate >= 1.0) { throw uhd::value_error(boost::str( - boost::format("current master clock rate (%.6f MHz) exceeds maximum possible master clock rate (%.6f MHz) when using %d %s channels") - % (tick_rate/1e6) - % (max_tick_rate/1e6) - % chan_count - % (direction.empty() ? "data" : direction) - )); + boost::format( + "current master clock rate (%.6f MHz) exceeds maximum possible " + "master clock rate (%.6f MHz) when using %d %s channels") + % (tick_rate / 1e6) % (max_tick_rate / 1e6) % chan_count + % (direction.empty() ? "data" : direction))); } - const double min_tick_rate = ad9361_device_t::AD9361_MIN_CLOCK_RATE / ((chan_count <= 1) ? 1 : 2); - if (min_tick_rate - tick_rate >= 1.0) - { + const double min_tick_rate = + ad9361_device_t::AD9361_MIN_CLOCK_RATE / ((chan_count <= 1) ? 1 : 2); + if (min_tick_rate - tick_rate >= 1.0) { throw uhd::value_error(boost::str( - boost::format("current master clock rate (%.6f MHz) is less than minimum possible master clock rate (%.6f MHz) when using %d %s channels") - % (tick_rate/1e6) - % (min_tick_rate/1e6) - % chan_count - % (direction.empty() ? "data" : direction) - )); + boost::format( + "current master clock rate (%.6f MHz) is less than minimum possible " + "master clock rate (%.6f MHz) when using %d %s channels") + % (tick_rate / 1e6) % (min_tick_rate / 1e6) % chan_count + % (direction.empty() ? "data" : direction))); } } } double b200_impl::set_tick_rate(const double new_tick_rate) { - UHD_LOGGER_INFO("B200") << (boost::format("Asking for clock rate %.6f MHz... ") % (new_tick_rate/1e6)) << std::flush; - check_tick_rate_with_current_streamers(new_tick_rate); // Defined in b200_io_impl.cpp + UHD_LOGGER_INFO("B200") << (boost::format("Asking for clock rate %.6f MHz... ") + % (new_tick_rate / 1e6)) + << std::flush; + check_tick_rate_with_current_streamers(new_tick_rate); // Defined in b200_io_impl.cpp // Make sure the clock rate is actually changed before doing // the full Monty of setting regs and loopback tests etc. if (std::abs(new_tick_rate - _tick_rate) < 1.0) { - UHD_LOGGER_INFO("B200") << "OK" ; + UHD_LOGGER_INFO("B200") << "OK"; return _tick_rate; } _tick_rate = _codec_ctrl->set_clock_rate(new_tick_rate); - UHD_LOGGER_INFO("B200") << (boost::format("Actually got clock rate %.6f MHz.") % (_tick_rate/1e6)) ; + UHD_LOGGER_INFO("B200") << (boost::format("Actually got clock rate %.6f MHz.") + % (_tick_rate / 1e6)); - for(radio_perifs_t &perif: _radio_perifs) - { + for (radio_perifs_t& perif : _radio_perifs) { perif.time64->set_tick_rate(_tick_rate); perif.time64->self_test(); } @@ -1036,76 +1099,72 @@ double b200_impl::set_tick_rate(const double new_tick_rate) void b200_impl::check_fw_compat(void) { - uint16_t compat_num = _iface->get_compat_num(); - uint32_t compat_major = (uint32_t) (compat_num >> 8); - uint32_t compat_minor = (uint32_t) (compat_num & 0xFF); - - if (compat_major != B200_FW_COMPAT_NUM_MAJOR){ - throw uhd::runtime_error(str(boost::format( - "Expected firmware compatibility number %d.%d, but got %d.%d:\n" - "The firmware build is not compatible with the host code build.\n" - "%s" - ) % int(B200_FW_COMPAT_NUM_MAJOR) % int(B200_FW_COMPAT_NUM_MINOR) - % compat_major % compat_minor % print_utility_error("uhd_images_downloader.py"))); + uint16_t compat_num = _iface->get_compat_num(); + uint32_t compat_major = (uint32_t)(compat_num >> 8); + uint32_t compat_minor = (uint32_t)(compat_num & 0xFF); + + if (compat_major != B200_FW_COMPAT_NUM_MAJOR) { + throw uhd::runtime_error(str( + boost::format( + "Expected firmware compatibility number %d.%d, but got %d.%d:\n" + "The firmware build is not compatible with the host code build.\n" + "%s") + % int(B200_FW_COMPAT_NUM_MAJOR) % int(B200_FW_COMPAT_NUM_MINOR) % compat_major + % compat_minor % print_utility_error("uhd_images_downloader.py"))); } - _tree->create<std::string>("/mboards/0/fw_version").set(str(boost::format("%u.%u") - % compat_major % compat_minor)); + _tree->create<std::string>("/mboards/0/fw_version") + .set(str(boost::format("%u.%u") % compat_major % compat_minor)); } void b200_impl::check_fpga_compat(void) { - const uint64_t compat = _local_ctrl->peek64(0); - const uint32_t signature = uint32_t(compat >> 32); + const uint64_t compat = _local_ctrl->peek64(0); + const uint32_t signature = uint32_t(compat >> 32); const uint16_t compat_major = uint16_t(compat >> 16); const uint16_t compat_minor = uint16_t(compat & 0xffff); - if (signature != 0xACE0BA5E) throw uhd::runtime_error( - "b200::check_fpga_compat signature register readback failed"); - - const uint16_t expected = ((_product == B200MINI or _product == B205MINI) ? B205_FPGA_COMPAT_NUM : B200_FPGA_COMPAT_NUM); - if (compat_major != expected) - { - throw uhd::runtime_error(str(boost::format( - "Expected FPGA compatibility number %d, but got %d:\n" - "The FPGA build is not compatible with the host code build.\n" - "%s" - ) % int(expected) % compat_major % print_utility_error("uhd_images_downloader.py"))); + if (signature != 0xACE0BA5E) + throw uhd::runtime_error( + "b200::check_fpga_compat signature register readback failed"); + + const uint16_t expected = ((_product == B200MINI or _product == B205MINI) + ? B205_FPGA_COMPAT_NUM + : B200_FPGA_COMPAT_NUM); + if (compat_major != expected) { + throw uhd::runtime_error(str( + boost::format("Expected FPGA compatibility number %d, but got %d:\n" + "The FPGA build is not compatible with the host code build.\n" + "%s") + % int(expected) % compat_major + % print_utility_error("uhd_images_downloader.py"))); } - _tree->create<std::string>("/mboards/0/fpga_version").set(str(boost::format("%u.%u") - % compat_major % compat_minor)); + _tree->create<std::string>("/mboards/0/fpga_version") + .set(str(boost::format("%u.%u") % compat_major % compat_minor)); } /*********************************************************************** * Reference time and clock **********************************************************************/ -void b200_impl::update_clock_source(const std::string &source) +void b200_impl::update_clock_source(const std::string& source) { // For B205, ref_sel selects whether or not to lock to the external clock source - if (_product == B200MINI or _product == B205MINI) - { - if (source == "external" and _time_source == EXTERNAL) - { - throw uhd::value_error("external reference cannot be both a clock source and a time source"); + if (_product == B200MINI or _product == B205MINI) { + if (source == "external" and _time_source == EXTERNAL) { + throw uhd::value_error( + "external reference cannot be both a clock source and a time source"); } - if (source == "internal") - { - if (_gpio_state.ref_sel != 0) - { + if (source == "internal") { + if (_gpio_state.ref_sel != 0) { _gpio_state.ref_sel = 0; this->update_gpio_state(); } - } - else if (source == "external") - { - if (_gpio_state.ref_sel != 1) - { + } else if (source == "external") { + if (_gpio_state.ref_sel != 1) { _gpio_state.ref_sel = 1; this->update_gpio_state(); } - } - else - { + } else { throw uhd::key_error("update_clock_source: unknown source: " + source); } return; @@ -1113,42 +1172,35 @@ void b200_impl::update_clock_source(const std::string &source) // For all other devices, ref_sel selects the external or gpsdo clock source // and the ADF4001 selects whether to lock to it or not - if (source == "internal") - { + if (source == "internal") { _adf4001_iface->set_lock_to_ext_ref(false); - } - else if (source == "external") - { - if (_gpio_state.ref_sel != 0) - { + } else if (source == "external") { + if (_gpio_state.ref_sel != 0) { _gpio_state.ref_sel = 0; this->update_gpio_state(); } _adf4001_iface->set_lock_to_ext_ref(true); - } - else if (source == "gpsdo") - { + } else if (source == "gpsdo") { if (not _gps or not _gps->gps_detected()) { - throw uhd::key_error("update_clock_source: gpsdo selected, but no gpsdo detected!"); + throw uhd::key_error( + "update_clock_source: gpsdo selected, but no gpsdo detected!"); } - if (_gpio_state.ref_sel != 1) - { + if (_gpio_state.ref_sel != 1) { _gpio_state.ref_sel = 1; this->update_gpio_state(); } _adf4001_iface->set_lock_to_ext_ref(true); - } - else - { + } else { throw uhd::key_error("update_clock_source: unknown source: " + source); } } -void b200_impl::update_time_source(const std::string &source) +void b200_impl::update_time_source(const std::string& source) { - if ((_product == B200MINI or _product == B205MINI) and source == "external" and _gpio_state.ref_sel == 1) - { - throw uhd::value_error("external reference cannot be both a time source and a clock source"); + if ((_product == B200MINI or _product == B205MINI) and source == "external" + and _gpio_state.ref_sel == 1) { + throw uhd::value_error( + "external reference cannot be both a time source and a clock source"); } // We assume source is valid for this device (if it's gone through @@ -1164,8 +1216,7 @@ void b200_impl::update_time_source(const std::string &source) value = GPSDO; else throw uhd::key_error("update_time_source: unknown source: " + source); - if (_time_source != value) - { + if (_time_source != value) { _local_ctrl->poke32(TOREG(SR_CORE_SYNC), value); _time_source = value; } @@ -1173,7 +1224,7 @@ void b200_impl::update_time_source(const std::string &source) void b200_impl::set_time(const uhd::time_spec_t& t) { - for(radio_perifs_t &perif: _radio_perifs) + for (radio_perifs_t& perif : _radio_perifs) perif.time64->set_time_sync(t); _local_ctrl->poke32(TOREG(SR_CORE_SYNC), 1 << 2 | uint32_t(_time_source)); _local_ctrl->poke32(TOREG(SR_CORE_SYNC), _time_source); @@ -1195,27 +1246,27 @@ void b200_impl::update_bandsel(const std::string& which, double freq) return; } - if(which[0] == 'R') { - if(freq < 2.2e9) { + if (which[0] == 'R') { + if (freq < 2.2e9) { _gpio_state.rx_bandsel_a = 0; _gpio_state.rx_bandsel_b = 0; _gpio_state.rx_bandsel_c = 1; - } else if((freq >= 2.2e9) && (freq < 4e9)) { + } else if ((freq >= 2.2e9) && (freq < 4e9)) { _gpio_state.rx_bandsel_a = 0; _gpio_state.rx_bandsel_b = 1; _gpio_state.rx_bandsel_c = 0; - } else if((freq >= 4e9) && (freq <= 6e9)) { + } else if ((freq >= 4e9) && (freq <= 6e9)) { _gpio_state.rx_bandsel_a = 1; _gpio_state.rx_bandsel_b = 0; _gpio_state.rx_bandsel_c = 0; } else { UHD_THROW_INVALID_CODE_PATH(); } - } else if(which[0] == 'T') { - if(freq < 2.5e9) { + } else if (which[0] == 'T') { + if (freq < 2.5e9) { _gpio_state.tx_bandsel_a = 0; _gpio_state.tx_bandsel_b = 1; - } else if((freq >= 2.5e9) && (freq <= 6e9)) { + } else if ((freq >= 2.5e9) && (freq <= 6e9)) { _gpio_state.tx_bandsel_a = 1; _gpio_state.tx_bandsel_b = 0; } else { @@ -1238,53 +1289,54 @@ void b200_impl::reset_codec() void b200_impl::update_gpio_state(void) { - const uint32_t misc_word = 0 - | (_gpio_state.swap_atr << 8) - | (_gpio_state.tx_bandsel_a << 7) - | (_gpio_state.tx_bandsel_b << 6) - | (_gpio_state.rx_bandsel_a << 5) - | (_gpio_state.rx_bandsel_b << 4) - | (_gpio_state.rx_bandsel_c << 3) - | (_gpio_state.codec_arst << 2) - | (_gpio_state.mimo << 1) - | (_gpio_state.ref_sel << 0) - ; + const uint32_t misc_word = + 0 | (_gpio_state.swap_atr << 8) | (_gpio_state.tx_bandsel_a << 7) + | (_gpio_state.tx_bandsel_b << 6) | (_gpio_state.rx_bandsel_a << 5) + | (_gpio_state.rx_bandsel_b << 4) | (_gpio_state.rx_bandsel_c << 3) + | (_gpio_state.codec_arst << 2) | (_gpio_state.mimo << 1) + | (_gpio_state.ref_sel << 0); _local_ctrl->poke32(TOREG(SR_CORE_MISC), misc_word); } void b200_impl::update_atrs(void) { - if (_radio_perifs.size() > _fe1 and _radio_perifs[_fe1].atr) - { - radio_perifs_t &perif = _radio_perifs[_fe1]; - const bool enb_rx = bool(perif.rx_streamer.lock()); - const bool enb_tx = bool(perif.tx_streamer.lock()); - const bool is_rx2 = perif.ant_rx2; - const uint32_t rxonly = (enb_rx)? ((is_rx2)? STATE_RX1_RX2 : STATE_RX1_TXRX) : STATE_OFF; - const uint32_t txonly = (enb_tx)? (STATE_TX1_TXRX) : STATE_OFF; - uint32_t fd = STATE_OFF; - if (enb_rx and enb_tx) fd = STATE_FDX1_TXRX; - if (enb_rx and not enb_tx) fd = rxonly; - if (not enb_rx and enb_tx) fd = txonly; + if (_radio_perifs.size() > _fe1 and _radio_perifs[_fe1].atr) { + radio_perifs_t& perif = _radio_perifs[_fe1]; + const bool enb_rx = bool(perif.rx_streamer.lock()); + const bool enb_tx = bool(perif.tx_streamer.lock()); + const bool is_rx2 = perif.ant_rx2; + const uint32_t rxonly = (enb_rx) ? ((is_rx2) ? STATE_RX1_RX2 : STATE_RX1_TXRX) + : STATE_OFF; + const uint32_t txonly = (enb_tx) ? (STATE_TX1_TXRX) : STATE_OFF; + uint32_t fd = STATE_OFF; + if (enb_rx and enb_tx) + fd = STATE_FDX1_TXRX; + if (enb_rx and not enb_tx) + fd = rxonly; + if (not enb_rx and enb_tx) + fd = txonly; gpio_atr_3000::sptr atr = perif.atr; atr->set_atr_reg(ATR_REG_IDLE, STATE_OFF); atr->set_atr_reg(ATR_REG_RX_ONLY, rxonly); atr->set_atr_reg(ATR_REG_TX_ONLY, txonly); atr->set_atr_reg(ATR_REG_FULL_DUPLEX, fd); } - if (_radio_perifs.size() > _fe2 and _radio_perifs[_fe2].atr) - { - radio_perifs_t &perif = _radio_perifs[_fe2]; - const bool enb_rx = bool(perif.rx_streamer.lock()); - const bool enb_tx = bool(perif.tx_streamer.lock()); - const bool is_rx2 = perif.ant_rx2; - const uint32_t rxonly = (enb_rx)? ((is_rx2)? STATE_RX2_RX2 : STATE_RX2_TXRX) : STATE_OFF; - const uint32_t txonly = (enb_tx)? (STATE_TX2_TXRX) : STATE_OFF; - uint32_t fd = STATE_OFF; - if (enb_rx and enb_tx) fd = STATE_FDX2_TXRX; - if (enb_rx and not enb_tx) fd = rxonly; - if (not enb_rx and enb_tx) fd = txonly; + if (_radio_perifs.size() > _fe2 and _radio_perifs[_fe2].atr) { + radio_perifs_t& perif = _radio_perifs[_fe2]; + const bool enb_rx = bool(perif.rx_streamer.lock()); + const bool enb_tx = bool(perif.tx_streamer.lock()); + const bool is_rx2 = perif.ant_rx2; + const uint32_t rxonly = (enb_rx) ? ((is_rx2) ? STATE_RX2_RX2 : STATE_RX2_TXRX) + : STATE_OFF; + const uint32_t txonly = (enb_tx) ? (STATE_TX2_TXRX) : STATE_OFF; + uint32_t fd = STATE_OFF; + if (enb_rx and enb_tx) + fd = STATE_FDX2_TXRX; + if (enb_rx and not enb_tx) + fd = rxonly; + if (not enb_rx and enb_tx) + fd = txonly; gpio_atr_3000::sptr atr = perif.atr; atr->set_atr_reg(ATR_REG_IDLE, STATE_OFF); atr->set_atr_reg(ATR_REG_RX_ONLY, rxonly); @@ -1293,38 +1345,44 @@ void b200_impl::update_atrs(void) } } -void b200_impl::update_antenna_sel(const size_t which, const std::string &ant) +void b200_impl::update_antenna_sel(const size_t which, const std::string& ant) { - if (ant != "TX/RX" and ant != "RX2") throw uhd::value_error("b200: unknown RX antenna option: " + ant); + if (ant != "TX/RX" and ant != "RX2") + throw uhd::value_error("b200: unknown RX antenna option: " + ant); _radio_perifs[which].ant_rx2 = (ant == "RX2"); this->update_atrs(); } void b200_impl::update_enables(void) { - //extract settings from state variables - const bool enb_tx1 = (_radio_perifs.size() > _fe1) and bool(_radio_perifs[_fe1].tx_streamer.lock()); - const bool enb_rx1 = (_radio_perifs.size() > _fe1) and bool(_radio_perifs[_fe1].rx_streamer.lock()); - const bool enb_tx2 = (_radio_perifs.size() > _fe2) and bool(_radio_perifs[_fe2].tx_streamer.lock()); - const bool enb_rx2 = (_radio_perifs.size() > _fe2) and bool(_radio_perifs[_fe2].rx_streamer.lock()); - const size_t num_rx = (enb_rx1?1:0) + (enb_rx2?1:0); - const size_t num_tx = (enb_tx1?1:0) + (enb_tx2?1:0); - const bool mimo = num_rx == 2 or num_tx == 2; - - if ((num_rx + num_tx) == 3) - { - throw uhd::runtime_error("b200: 2 RX 1 TX and 1 RX 2 TX configurations not possible"); + // extract settings from state variables + const bool enb_tx1 = (_radio_perifs.size() > _fe1) + and bool(_radio_perifs[_fe1].tx_streamer.lock()); + const bool enb_rx1 = (_radio_perifs.size() > _fe1) + and bool(_radio_perifs[_fe1].rx_streamer.lock()); + const bool enb_tx2 = (_radio_perifs.size() > _fe2) + and bool(_radio_perifs[_fe2].tx_streamer.lock()); + const bool enb_rx2 = (_radio_perifs.size() > _fe2) + and bool(_radio_perifs[_fe2].rx_streamer.lock()); + const size_t num_rx = (enb_rx1 ? 1 : 0) + (enb_rx2 ? 1 : 0); + const size_t num_tx = (enb_tx1 ? 1 : 0) + (enb_tx2 ? 1 : 0); + const bool mimo = num_rx == 2 or num_tx == 2; + + if ((num_rx + num_tx) == 3) { + throw uhd::runtime_error( + "b200: 2 RX 1 TX and 1 RX 2 TX configurations not possible"); } - //setup the active chains in the codec + // setup the active chains in the codec _codec_ctrl->set_active_chains(enb_tx1, enb_tx2, enb_rx1, enb_rx2); - if ((num_rx + num_tx) == 0) _codec_ctrl->set_active_chains(true, false, true, false); //enable something + if ((num_rx + num_tx) == 0) + _codec_ctrl->set_active_chains(true, false, true, false); // enable something - //figure out if mimo is enabled based on new state - _gpio_state.mimo = (mimo)? 1 : 0; + // figure out if mimo is enabled based on new state + _gpio_state.mimo = (mimo) ? 1 : 0; update_gpio_state(); - //atrs change based on enables + // atrs change based on enables this->update_atrs(); } diff --git a/host/lib/usrp/b200/b200_impl.hpp b/host/lib/usrp/b200/b200_impl.hpp index bd44aa14f..d151bc59d 100644 --- a/host/lib/usrp/b200/b200_impl.hpp +++ b/host/lib/usrp/b200/b200_impl.hpp @@ -8,47 +8,47 @@ #ifndef INCLUDED_B200_IMPL_HPP #define INCLUDED_B200_IMPL_HPP +#include "b200_cores.hpp" #include "b200_iface.hpp" #include "b200_uart.hpp" -#include "b200_cores.hpp" #include <uhd/device.hpp> #include <uhd/property_tree.hpp> -#include <uhd/utils/pimpl.hpp> -#include <uhd/utils/tasks.hpp> +#include <uhd/transport/bounded_buffer.hpp> +#include <uhd/transport/usb_zero_copy.hpp> #include <uhd/types/dict.hpp> #include <uhd/types/sensors.hpp> #include <uhd/types/stream_cmd.hpp> +#include <uhd/usrp/gps_ctrl.hpp> #include <uhd/usrp/mboard_eeprom.hpp> #include <uhd/usrp/subdev_spec.hpp> -#include <uhd/usrp/gps_ctrl.hpp> -#include <uhd/transport/usb_zero_copy.hpp> -#include <uhd/transport/bounded_buffer.hpp> +#include <uhd/utils/pimpl.hpp> +#include <uhd/utils/tasks.hpp> #include <uhdlib/usrp/common/ad9361_ctrl.hpp> -#include <uhdlib/usrp/cores/rx_vita_core_3000.hpp> -#include <uhdlib/usrp/cores/tx_vita_core_3000.hpp> -#include <uhdlib/usrp/cores/time_core_3000.hpp> +#include <uhdlib/usrp/common/ad936x_manager.hpp> +#include <uhdlib/usrp/common/adf4001_ctrl.hpp> +#include <uhdlib/usrp/common/recv_packet_demuxer_3000.hpp> #include <uhdlib/usrp/cores/gpio_atr_3000.hpp> #include <uhdlib/usrp/cores/radio_ctrl_core_3000.hpp> #include <uhdlib/usrp/cores/rx_dsp_core_3000.hpp> +#include <uhdlib/usrp/cores/rx_vita_core_3000.hpp> +#include <uhdlib/usrp/cores/time_core_3000.hpp> #include <uhdlib/usrp/cores/tx_dsp_core_3000.hpp> +#include <uhdlib/usrp/cores/tx_vita_core_3000.hpp> #include <uhdlib/usrp/cores/user_settings_core_3000.hpp> -#include <uhdlib/usrp/common/recv_packet_demuxer_3000.hpp> -#include <uhdlib/usrp/common/ad936x_manager.hpp> -#include <uhdlib/usrp/common/adf4001_ctrl.hpp> #include <boost/assign.hpp> -#include <mutex> #include <memory> +#include <mutex> -static const uint8_t B200_FW_COMPAT_NUM_MAJOR = 8; -static const uint8_t B200_FW_COMPAT_NUM_MINOR = 0; -static const uint16_t B200_FPGA_COMPAT_NUM = 16; -static const uint16_t B205_FPGA_COMPAT_NUM = 7; -static const double B200_BUS_CLOCK_RATE = 100e6; -static const uint32_t B200_GPSDO_ST_NONE = 0x83; -static constexpr double B200_MAX_RATE_USB2 = 53248000; // bytes/s -static constexpr double B200_MAX_RATE_USB3 = 500000000; // bytes/s +static const uint8_t B200_FW_COMPAT_NUM_MAJOR = 8; +static const uint8_t B200_FW_COMPAT_NUM_MINOR = 0; +static const uint16_t B200_FPGA_COMPAT_NUM = 16; +static const uint16_t B205_FPGA_COMPAT_NUM = 7; +static const double B200_BUS_CLOCK_RATE = 100e6; +static const uint32_t B200_GPSDO_ST_NONE = 0x83; +static constexpr double B200_MAX_RATE_USB2 = 53248000; // bytes/s +static constexpr double B200_MAX_RATE_USB3 = 500000000; // bytes/s -#define FLIP_SID(sid) (((sid)<<16)|((sid)>>16)) +#define FLIP_SID(sid) (((sid) << 16) | ((sid) >> 16)) static const uint32_t B200_CTRL0_MSG_SID = 0x00000010; static const uint32_t B200_RESP0_MSG_SID = FLIP_SID(B200_CTRL0_MSG_SID); @@ -57,10 +57,10 @@ static const uint32_t B200_CTRL1_MSG_SID = 0x00000020; static const uint32_t B200_RESP1_MSG_SID = FLIP_SID(B200_CTRL1_MSG_SID); static const uint32_t B200_TX_DATA0_SID = 0x00000050; -static const uint32_t B200_TX_MSG0_SID = FLIP_SID(B200_TX_DATA0_SID); +static const uint32_t B200_TX_MSG0_SID = FLIP_SID(B200_TX_DATA0_SID); static const uint32_t B200_TX_DATA1_SID = 0x00000060; -static const uint32_t B200_TX_MSG1_SID = FLIP_SID(B200_TX_DATA1_SID); +static const uint32_t B200_TX_MSG1_SID = FLIP_SID(B200_TX_DATA1_SID); static const uint32_t B200_RX_DATA0_SID = 0x000000A0; static const uint32_t B200_RX_DATA1_SID = 0x000000B0; @@ -91,48 +91,55 @@ static const int B200_USB_DATA_MAX_RECV_FRAME_SIZE = 16360; * VID/PID pairs for all B2xx products */ static std::vector<uhd::transport::usb_device_handle::vid_pid_pair_t> b200_vid_pid_pairs = - boost::assign::list_of - (uhd::transport::usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200_PRODUCT_ID)) - (uhd::transport::usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200MINI_PRODUCT_ID)) - (uhd::transport::usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B205MINI_PRODUCT_ID)) - (uhd::transport::usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B200_PRODUCT_NI_ID)) - (uhd::transport::usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID)) - ; - -b200_product_t get_b200_product(const uhd::transport::usb_device_handle::sptr& handle, const uhd::usrp::mboard_eeprom_t &mb_eeprom); -std::vector<uhd::transport::usb_device_handle::sptr> get_b200_device_handles(const uhd::device_addr_t &hint); + boost::assign::list_of(uhd::transport::usb_device_handle::vid_pid_pair_t( + B200_VENDOR_ID, B200_PRODUCT_ID))( + uhd::transport::usb_device_handle::vid_pid_pair_t( + B200_VENDOR_ID, B200MINI_PRODUCT_ID))( + uhd::transport::usb_device_handle::vid_pid_pair_t( + B200_VENDOR_ID, B205MINI_PRODUCT_ID))( + uhd::transport::usb_device_handle::vid_pid_pair_t( + B200_VENDOR_NI_ID, B200_PRODUCT_NI_ID))( + uhd::transport::usb_device_handle::vid_pid_pair_t( + B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID)); + +b200_product_t get_b200_product(const uhd::transport::usb_device_handle::sptr& handle, + const uhd::usrp::mboard_eeprom_t& mb_eeprom); +std::vector<uhd::transport::usb_device_handle::sptr> get_b200_device_handles( + const uhd::device_addr_t& hint); //! Implementation guts class b200_impl : public uhd::device { public: - //structors - b200_impl(const uhd::device_addr_t &, uhd::transport::usb_device_handle::sptr &handle); + // structors + b200_impl(const uhd::device_addr_t&, uhd::transport::usb_device_handle::sptr& handle); ~b200_impl(void); - //the io interface - uhd::rx_streamer::sptr get_rx_stream(const uhd::stream_args_t &args); - uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t &args); - bool recv_async_msg(uhd::async_metadata_t &, double); + // the io interface + uhd::rx_streamer::sptr get_rx_stream(const uhd::stream_args_t& args); + uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t& args); + bool recv_async_msg(uhd::async_metadata_t&, double); //! Check that the combination of stream args and tick rate are valid. // // Basically figures out the arguments for enforce_tick_rate_limits() // and calls said method. If arguments are invalid, throws a // uhd::value_error. - void check_streamer_args(const uhd::stream_args_t &args, double tick_rate, const std::string &direction = ""); + void check_streamer_args(const uhd::stream_args_t& args, + double tick_rate, + const std::string& direction = ""); static uhd::usrp::mboard_eeprom_t get_mb_eeprom(uhd::i2c_iface::sptr); private: - b200_product_t _product; - size_t _revision; - bool _gpsdo_capable; + b200_product_t _product; + size_t _revision; + bool _gpsdo_capable; //! This flag is true if the FPGA has custom (user) registers and access to // those needs to be enabled from software. - const bool _enable_user_regs; + const bool _enable_user_regs; - //controllers + // controllers b200_iface::sptr _iface; radio_ctrl_core_3000::sptr _local_ctrl; uhd::usrp::ad9361_ctrl::sptr _codec_ctrl; @@ -141,7 +148,7 @@ private: std::shared_ptr<uhd::usrp::adf4001_ctrl> _adf4001_iface; uhd::gps_ctrl::sptr _gps; - //transports + // transports uhd::transport::zero_copy_if::sptr _data_transport; uhd::transport::zero_copy_if::sptr _ctrl_transport; uhd::usrp::recv_packet_demuxer_3000::sptr _demux; @@ -151,7 +158,7 @@ private: std::mutex _transport_setup_mutex; - //async ctrl + msgs + // async ctrl + msgs uhd::msg_task::sptr _async_task; typedef uhd::transport::bounded_buffer<uhd::async_metadata_t> async_md_type; struct AsyncTaskData @@ -162,25 +169,26 @@ private: b200_uart::sptr gpsdo_uart; }; std::shared_ptr<AsyncTaskData> _async_task_data; - boost::optional<uhd::msg_task::msg_type_t> handle_async_task(uhd::transport::zero_copy_if::sptr, std::shared_ptr<AsyncTaskData>); + boost::optional<uhd::msg_task::msg_type_t> handle_async_task( + uhd::transport::zero_copy_if::sptr, std::shared_ptr<AsyncTaskData>); void register_loopback_self_test(uhd::wb_iface::sptr iface); - void set_mb_eeprom(const uhd::usrp::mboard_eeprom_t &); + void set_mb_eeprom(const uhd::usrp::mboard_eeprom_t&); void check_fw_compat(void); void check_fpga_compat(void); - uhd::usrp::subdev_spec_t coerce_subdev_spec(const uhd::usrp::subdev_spec_t &); - void update_subdev_spec(const std::string &tx_rx, const uhd::usrp::subdev_spec_t &); - void update_time_source(const std::string &); + uhd::usrp::subdev_spec_t coerce_subdev_spec(const uhd::usrp::subdev_spec_t&); + void update_subdev_spec(const std::string& tx_rx, const uhd::usrp::subdev_spec_t&); + void update_time_source(const std::string&); void set_time(const uhd::time_spec_t&); void sync_times(void); - void update_clock_source(const std::string &); + void update_clock_source(const std::string&); void update_bandsel(const std::string& which, double freq); void reset_codec(void); - void update_antenna_sel(const size_t which, const std::string &ant); + void update_antenna_sel(const size_t which, const std::string& ant); uhd::sensor_value_t get_ref_locked(void); uhd::sensor_value_t get_fe_pll_locked(const bool is_tx); - //perifs in the radio core + // perifs in the radio core struct radio_perifs_t { radio_ctrl_core_3000::sptr ctrl; @@ -198,10 +206,10 @@ private: }; std::vector<radio_perifs_t> _radio_perifs; - //mapping of AD936x frontends (FE1 and FE2) to radio perif index (0 and 1) - //FE1 corresponds to the ports labeled "RF B" on the B200/B210 - //FE2 corresponds to the ports labeled "RF A" on the B200/B210 - //the mapping is product and revision specific + // mapping of AD936x frontends (FE1 and FE2) to radio perif index (0 and 1) + // FE1 corresponds to the ports labeled "RF B" on the B200/B210 + // FE2 corresponds to the ports labeled "RF A" on the B200/B210 + // the mapping is product and revision specific size_t _fe1; size_t _fe2; @@ -211,23 +219,32 @@ private: void setup_radio(const size_t radio_index); void handle_overflow(const size_t radio_index); - struct gpio_state { - uint32_t tx_bandsel_a, tx_bandsel_b, rx_bandsel_a, rx_bandsel_b, rx_bandsel_c, codec_arst, mimo, ref_sel, swap_atr; + struct gpio_state + { + uint32_t tx_bandsel_a, tx_bandsel_b, rx_bandsel_a, rx_bandsel_b, rx_bandsel_c, + codec_arst, mimo, ref_sel, swap_atr; - gpio_state() { + gpio_state() + { tx_bandsel_a = 0; tx_bandsel_b = 0; rx_bandsel_a = 0; rx_bandsel_b = 0; rx_bandsel_c = 0; - codec_arst = 0; - mimo = 0; - ref_sel = 0; - swap_atr = 0; + codec_arst = 0; + mimo = 0; + ref_sel = 0; + swap_atr = 0; } } _gpio_state; - enum time_source_t {GPSDO=0,EXTERNAL=1,INTERNAL=2,NONE=3,UNKNOWN=4} _time_source; + enum time_source_t { + GPSDO = 0, + EXTERNAL = 1, + INTERNAL = 2, + NONE = 3, + UNKNOWN = 4 + } _time_source; void update_gpio_state(void); @@ -235,10 +252,14 @@ private: void update_atrs(void); double _tick_rate; - double get_tick_rate(void){return _tick_rate;} + double get_tick_rate(void) + { + return _tick_rate; + } double set_tick_rate(const double rate); - /*! \brief Choose a tick rate (master clock rate) that works well for the given sampling rate. + /*! \brief Choose a tick rate (master clock rate) that works well for the given + * sampling rate. * * This function will try and choose a master clock rate automatically. * See the function definition for details on the algorithm. @@ -257,30 +278,32 @@ private: * will be ignored. * \param num_chans If given, specifies the number of channels. */ - void set_auto_tick_rate( - const double rate=0, - const uhd::fs_path &tree_dsp_path="", - size_t num_chans=0 - ); + void set_auto_tick_rate(const double rate = 0, + const uhd::fs_path& tree_dsp_path = "", + size_t num_chans = 0); void update_tick_rate(const double); /*! Subscriber to the tick_rate property, updates DDCs after tick rate change. */ - void update_rx_dsp_tick_rate(const double, rx_dsp_core_3000::sptr, uhd::fs_path rx_dsp_path); + void update_rx_dsp_tick_rate( + const double, rx_dsp_core_3000::sptr, uhd::fs_path rx_dsp_path); /*! Subscriber to the tick_rate property, updates DUCs after tick rate change. */ - void update_tx_dsp_tick_rate(const double, tx_dsp_core_3000::sptr, uhd::fs_path tx_dsp_path); + void update_tx_dsp_tick_rate( + const double, tx_dsp_core_3000::sptr, uhd::fs_path tx_dsp_path); /*! Check if \p tick_rate works with \p chan_count channels. * * Throws a uhd::value_error if not. */ - void enforce_tick_rate_limits(size_t chan_count, double tick_rate, const std::string &direction = ""); + void enforce_tick_rate_limits( + size_t chan_count, double tick_rate, const std::string& direction = ""); void check_tick_rate_with_current_streamers(double rate); - /*! Return the max number of channels on active rx_streamer or tx_streamer objects associated with this device. + /*! Return the max number of channels on active rx_streamer or tx_streamer objects + * associated with this device. * * \param direction Set to "TX" to only check tx_streamers, "RX" to only check * rx_streamers. Any other value will check if \e any active @@ -288,7 +311,7 @@ private: * \return Return the number of tx streamers (direction=="TX"), the number of rx * streamers (direction=="RX") or the total number of streamers. */ - size_t max_chan_count(const std::string &direction=""); + size_t max_chan_count(const std::string& direction = ""); //! Coercer, attached to the "rate/value" property on the rx dsps. double coerce_rx_samp_rate(rx_dsp_core_3000::sptr, size_t, const double); diff --git a/host/lib/usrp/b200/b200_io_impl.cpp b/host/lib/usrp/b200/b200_io_impl.cpp index 6eb3631ab..57a1b18c7 100644 --- a/host/lib/usrp/b200/b200_io_impl.cpp +++ b/host/lib/usrp/b200/b200_io_impl.cpp @@ -458,12 +458,17 @@ rx_streamer::sptr b200_impl::get_rx_stream(const uhd::stream_args_t& args_) perif.ddc->setup(args); _demux->realloc_sid(sid); my_streamer->set_xport_chan_get_buff(stream_i, - std::bind(&recv_packet_demuxer_3000::get_recv_buff, _demux, sid, std::placeholders::_1), + std::bind(&recv_packet_demuxer_3000::get_recv_buff, + _demux, + sid, + std::placeholders::_1), true /*flush*/); my_streamer->set_overflow_handler( stream_i, std::bind(&b200_impl::handle_overflow, this, radio_index)); my_streamer->set_issue_stream_cmd(stream_i, - std::bind(&rx_vita_core_3000::issue_stream_command, perif.framer, std::placeholders::_1)); + std::bind(&rx_vita_core_3000::issue_stream_command, + perif.framer, + std::placeholders::_1)); perif.rx_streamer = my_streamer; // store weak pointer // sets all tick and samp rates on this streamer @@ -574,10 +579,13 @@ tx_streamer::sptr b200_impl::get_tx_stream(const uhd::stream_args_t& args_) perif.deframer->setup(args); perif.duc->setup(args); - my_streamer->set_xport_chan_get_buff( - stream_i, std::bind(&zero_copy_if::get_send_buff, _data_transport, std::placeholders::_1)); - my_streamer->set_async_receiver(std::bind( - &async_md_type::pop_with_timed_wait, _async_task_data->async_md, std::placeholders::_1, std::placeholders::_2)); + my_streamer->set_xport_chan_get_buff(stream_i, + std::bind( + &zero_copy_if::get_send_buff, _data_transport, std::placeholders::_1)); + my_streamer->set_async_receiver(std::bind(&async_md_type::pop_with_timed_wait, + _async_task_data->async_md, + std::placeholders::_1, + std::placeholders::_2)); my_streamer->set_xport_chan_sid( stream_i, true, radio_index ? B200_TX_DATA1_SID : B200_TX_DATA0_SID); my_streamer->set_enable_trailer(false); // TODO not implemented trailer support diff --git a/host/lib/usrp/b200/b200_mb_eeprom.cpp b/host/lib/usrp/b200/b200_mb_eeprom.cpp index 5a37cc9c1..a83dce189 100644 --- a/host/lib/usrp/b200/b200_mb_eeprom.cpp +++ b/host/lib/usrp/b200/b200_mb_eeprom.cpp @@ -7,7 +7,6 @@ #include "b200_impl.hpp" #include <uhd/usrp/mboard_eeprom.hpp> #include <uhdlib/utils/eeprom_utils.hpp> - #include <unordered_map> using namespace uhd; @@ -27,7 +26,7 @@ struct eeprom_field_t // firmware and bootloader code. // EEPROM map information is duplicated in b2xx_fx3_utils.cpp -constexpr uint16_t SIGNATURE_ADDR = 0x0000; +constexpr uint16_t SIGNATURE_ADDR = 0x0000; constexpr size_t SIGNATURE_LENGTH = 4; constexpr auto EXPECTED_MAGIC = "45568"; // 0xB200 @@ -38,15 +37,15 @@ constexpr uint16_t REV1_BASE_ADDR = 0x7F00; constexpr size_t REV1_LENGTH = 46; const std::unordered_map<std::string, eeprom_field_t> B200_REV1_MAP = { - {"magic", {0, 2}}, - {"eeprom_revision", {2, 2}}, - {"eeprom_compat", {4, 2}}, - {"vendor_id", {6, 2}}, - {"product_id", {8, 2}}, - {"revision", {10, 2}}, - {"product", {12, 2}}, - {"name", {14, NAME_MAX_LEN}}, - {"serial", {14 + NAME_MAX_LEN, SERIAL_LEN}}, + {"magic", {0, 2}}, + {"eeprom_revision", {2, 2}}, + {"eeprom_compat", {4, 2}}, + {"vendor_id", {6, 2}}, + {"product_id", {8, 2}}, + {"revision", {10, 2}}, + {"product", {12, 2}}, + {"name", {14, NAME_MAX_LEN}}, + {"serial", {14 + NAME_MAX_LEN, SERIAL_LEN}}, // pad of 210 bytes }; @@ -56,10 +55,10 @@ constexpr size_t REV0_LENGTH = 36; const std::unordered_map<std::string, eeprom_field_t> B200_REV0_MAP = { // front pad of 220 bytes - {"revision", {0, 2}}, - {"product", {2, 2}}, - {"name", {4, NAME_MAX_LEN}}, - {"serial", {4 + NAME_MAX_LEN, SERIAL_LEN}}, + {"revision", {0, 2}}, + {"product", {2, 2}}, + {"name", {4, NAME_MAX_LEN}}, + {"serial", {4 + NAME_MAX_LEN, SERIAL_LEN}}, }; constexpr int UNKNOWN_REV = -1; @@ -82,8 +81,7 @@ int _get_rev(uhd::i2c_iface::sptr iface) byte_vector_t _get_eeprom(uhd::i2c_iface::sptr iface) { const auto rev = _get_rev(iface); - if (rev == UNKNOWN_REV) - { + if (rev == UNKNOWN_REV) { return byte_vector_t(); } @@ -93,7 +91,7 @@ byte_vector_t _get_eeprom(uhd::i2c_iface::sptr iface) return iface->read_eeprom(addr >> 8, addr & 0xFF, length); } -} +} // namespace mboard_eeprom_t b200_impl::get_mb_eeprom(uhd::i2c_iface::sptr iface) { @@ -106,8 +104,7 @@ mboard_eeprom_t b200_impl::get_mb_eeprom(uhd::i2c_iface::sptr iface) auto eeprom_map = (rev == 0) ? B200_REV0_MAP : B200_REV1_MAP; - for (const auto &element : eeprom_map) - { + for (const auto& element : eeprom_map) { // There is an assumption here that fields of length 2 are uint16's and // lengths other than 2 are strings. Update this code if that // assumption changes. @@ -115,23 +112,22 @@ mboard_eeprom_t b200_impl::get_mb_eeprom(uhd::i2c_iface::sptr iface) bytes.begin() + element.second.offset + element.second.length); mb_eeprom[element.first] = (element.second.length == 2) - ? uint16_bytes_to_string(element_bytes) - : bytes_to_string(element_bytes); + ? uint16_bytes_to_string(element_bytes) + : bytes_to_string(element_bytes); } if (rev > 0) { - if (mb_eeprom["magic"] != EXPECTED_MAGIC) - { + if (mb_eeprom["magic"] != EXPECTED_MAGIC) { throw uhd::runtime_error( str(boost::format("EEPROM magic value mismatch. Device returns %s, but " "should have been %s.") - % mb_eeprom["magic"] % EXPECTED_MAGIC)); + % mb_eeprom["magic"] % EXPECTED_MAGIC)); } if (mb_eeprom["eeprom_compat"] != EXPECTED_COMPAT) { throw uhd::runtime_error( str(boost::format("EEPROM compat value mismatch. Device returns %s, but " "should have been %s.") - % mb_eeprom["eeprom_compat"] % EXPECTED_COMPAT)); + % mb_eeprom["eeprom_compat"] % EXPECTED_COMPAT)); } } @@ -140,13 +136,11 @@ mboard_eeprom_t b200_impl::get_mb_eeprom(uhd::i2c_iface::sptr iface) void b200_impl::set_mb_eeprom(const mboard_eeprom_t& mb_eeprom) { - const auto rev = _get_rev(_iface); + const auto rev = _get_rev(_iface); auto eeprom_map = (rev == 0) ? B200_REV0_MAP : B200_REV1_MAP; auto base_addr = (rev == 0) ? REV0_BASE_ADDR : REV1_BASE_ADDR; - for (const auto& key : mb_eeprom.keys()) - { - if (eeprom_map.find(key) == eeprom_map.end()) - { + for (const auto& key : mb_eeprom.keys()) { + if (eeprom_map.find(key) == eeprom_map.end()) { UHD_LOG_WARNING( LOG_ID, "Unknown key in mb_eeprom during set_mb_eeprom: " << key); continue; diff --git a/host/lib/usrp/b200/b200_regs.hpp b/host/lib/usrp/b200/b200_regs.hpp index cedbe0ff5..4554eb52c 100644 --- a/host/lib/usrp/b200/b200_regs.hpp +++ b/host/lib/usrp/b200/b200_regs.hpp @@ -14,60 +14,60 @@ #define localparam static const int -localparam SR_CORE_SPI = 8; -localparam SR_CORE_MISC = 16; -localparam SR_CORE_COMPAT = 24; -localparam SR_CORE_GPSDO_ST = 40; -localparam SR_CORE_SYNC = 48; -localparam RB32_CORE_SPI = 8; -localparam RB32_CORE_MISC = 16; -localparam RB32_CORE_STATUS = 20; -localparam RB32_CORE_PLL = 24; - -localparam SR_SPI = 8; -localparam SR_ATR = 12; -localparam SR_TEST = 21; -localparam SR_CODEC_IDLE = 22; -localparam SR_READBACK = 32; -localparam SR_TX_CTRL = 64; -localparam SR_RX_CTRL = 96; -localparam SR_RX_DSP = 144; -localparam SR_TX_DSP = 184; -localparam SR_TIME = 128; -localparam SR_RX_FMT = 136; -localparam SR_TX_FMT = 138; -localparam SR_FP_GPIO = 200; +localparam SR_CORE_SPI = 8; +localparam SR_CORE_MISC = 16; +localparam SR_CORE_COMPAT = 24; +localparam SR_CORE_GPSDO_ST = 40; +localparam SR_CORE_SYNC = 48; +localparam RB32_CORE_SPI = 8; +localparam RB32_CORE_MISC = 16; +localparam RB32_CORE_STATUS = 20; +localparam RB32_CORE_PLL = 24; + +localparam SR_SPI = 8; +localparam SR_ATR = 12; +localparam SR_TEST = 21; +localparam SR_CODEC_IDLE = 22; +localparam SR_READBACK = 32; +localparam SR_TX_CTRL = 64; +localparam SR_RX_CTRL = 96; +localparam SR_RX_DSP = 144; +localparam SR_TX_DSP = 184; +localparam SR_TIME = 128; +localparam SR_RX_FMT = 136; +localparam SR_TX_FMT = 138; +localparam SR_FP_GPIO = 200; localparam SR_USER_SR_BASE = 253; localparam SR_USER_RB_ADDR = 255; -localparam RB32_TEST = 0; -localparam RB64_TIME_NOW = 8; -localparam RB64_TIME_PPS = 16; -localparam RB64_CODEC_READBACK = 24; -localparam RB32_FP_GPIO = 32; +localparam RB32_TEST = 0; +localparam RB64_TIME_NOW = 8; +localparam RB64_TIME_PPS = 16; +localparam RB64_CODEC_READBACK = 24; +localparam RB32_FP_GPIO = 32; -//pll constants -static const int AD9361_SLAVENO = (1 << 0); -static const int ADF4001_SLAVENO = (1 << 1); -static const double AD9361_SPI_RATE = 1e6; -static const double ADF4001_SPI_RATE = 10e3; //slow for large time constant on spi lines +// pll constants +static const int AD9361_SLAVENO = (1 << 0); +static const int ADF4001_SLAVENO = (1 << 1); +static const double AD9361_SPI_RATE = 1e6; +static const double ADF4001_SPI_RATE = 10e3; // slow for large time constant on spi lines /* ATR Control Bits */ -static const uint32_t TX_ENABLE1 = (1 << 7); -static const uint32_t SFDX1_RX = (1 << 6); -static const uint32_t SFDX1_TX = (1 << 5); -static const uint32_t SRX1_RX = (1 << 4); -static const uint32_t SRX1_TX = (1 << 3); -static const uint32_t LED_RX1 = (1 << 2); +static const uint32_t TX_ENABLE1 = (1 << 7); +static const uint32_t SFDX1_RX = (1 << 6); +static const uint32_t SFDX1_TX = (1 << 5); +static const uint32_t SRX1_RX = (1 << 4); +static const uint32_t SRX1_TX = (1 << 3); +static const uint32_t LED_RX1 = (1 << 2); static const uint32_t LED_TXRX_RX1 = (1 << 1); static const uint32_t LED_TXRX_TX1 = (1 << 0); -static const uint32_t TX_ENABLE2 = (1 << 7); -static const uint32_t SFDX2_RX = (1 << 6); -static const uint32_t SFDX2_TX = (1 << 5); -static const uint32_t SRX2_RX = (1 << 4); -static const uint32_t SRX2_TX = (1 << 3); -static const uint32_t LED_RX2 = (1 << 2); +static const uint32_t TX_ENABLE2 = (1 << 7); +static const uint32_t SFDX2_RX = (1 << 6); +static const uint32_t SFDX2_TX = (1 << 5); +static const uint32_t SRX2_RX = (1 << 4); +static const uint32_t SRX2_TX = (1 << 3); +static const uint32_t LED_RX2 = (1 << 2); static const uint32_t LED_TXRX_RX2 = (1 << 1); static const uint32_t LED_TXRX_TX2 = (1 << 0); @@ -76,44 +76,24 @@ static const uint32_t LED_TXRX_TX2 = (1 << 0); static const uint32_t STATE_OFF = 0x00; ///////////////////////// side 1 /////////////////////////////////// -static const uint32_t STATE_RX1_RX2 = (SFDX1_RX - | SFDX1_TX - | LED_RX1); +static const uint32_t STATE_RX1_RX2 = (SFDX1_RX | SFDX1_TX | LED_RX1); -static const uint32_t STATE_RX1_TXRX = (SRX1_RX - | SRX1_TX - | LED_TXRX_RX1); +static const uint32_t STATE_RX1_TXRX = (SRX1_RX | SRX1_TX | LED_TXRX_RX1); -static const uint32_t STATE_FDX1_TXRX = (TX_ENABLE1 - | SFDX1_RX - | SFDX1_TX - | LED_TXRX_TX1 - | LED_RX1); +static const uint32_t STATE_FDX1_TXRX = + (TX_ENABLE1 | SFDX1_RX | SFDX1_TX | LED_TXRX_TX1 | LED_RX1); -static const uint32_t STATE_TX1_TXRX = (TX_ENABLE1 - | SFDX1_RX - | SFDX1_TX - | LED_TXRX_TX1); +static const uint32_t STATE_TX1_TXRX = (TX_ENABLE1 | SFDX1_RX | SFDX1_TX | LED_TXRX_TX1); ///////////////////////// side 2 /////////////////////////////////// -static const uint32_t STATE_RX2_RX2 = (SFDX2_RX - | SRX2_TX - | LED_RX2); - -static const uint32_t STATE_RX2_TXRX = (SRX2_TX - | SRX2_RX - | LED_TXRX_RX2); - -static const uint32_t STATE_FDX2_TXRX = (TX_ENABLE2 - | SFDX2_RX - | SFDX2_TX - | LED_TXRX_TX2 - | LED_RX2); - -static const uint32_t STATE_TX2_TXRX = (TX_ENABLE2 - | SFDX2_RX - | SFDX2_TX - | LED_TXRX_TX2); +static const uint32_t STATE_RX2_RX2 = (SFDX2_RX | SRX2_TX | LED_RX2); + +static const uint32_t STATE_RX2_TXRX = (SRX2_TX | SRX2_RX | LED_TXRX_RX2); + +static const uint32_t STATE_FDX2_TXRX = + (TX_ENABLE2 | SFDX2_RX | SFDX2_TX | LED_TXRX_TX2 | LED_RX2); + +static const uint32_t STATE_TX2_TXRX = (TX_ENABLE2 | SFDX2_RX | SFDX2_TX | LED_TXRX_TX2); #endif /* INCLUDED_B200_REGS_HPP */ diff --git a/host/lib/usrp/b200/b200_uart.cpp b/host/lib/usrp/b200/b200_uart.cpp index 8c8e2462a..b78690705 100644 --- a/host/lib/usrp/b200/b200_uart.cpp +++ b/host/lib/usrp/b200/b200_uart.cpp @@ -7,24 +7,24 @@ #include "b200_uart.hpp" #include "b200_impl.hpp" +#include <uhd/exception.hpp> #include <uhd/transport/bounded_buffer.hpp> #include <uhd/transport/vrt_if_packet.hpp> +#include <uhd/types/time_spec.hpp> #include <uhd/utils/byteswap.hpp> #include <uhd/utils/log.hpp> -#include <uhd/types/time_spec.hpp> -#include <uhd/exception.hpp> using namespace uhd; using namespace uhd::transport; struct b200_uart_impl : b200_uart { - b200_uart_impl(zero_copy_if::sptr xport, const uint32_t sid): - _xport(xport), - _sid(sid), - _count(0), - _baud_div(std::floor(B200_BUS_CLOCK_RATE/115200 + 0.5)), - _line_queue(4096) + b200_uart_impl(zero_copy_if::sptr xport, const uint32_t sid) + : _xport(xport) + , _sid(sid) + , _count(0) + , _baud_div(std::floor(B200_BUS_CLOCK_RATE / 115200 + 0.5)) + , _line_queue(4096) { /*NOP*/ } @@ -35,31 +35,31 @@ struct b200_uart_impl : b200_uart UHD_ASSERT_THROW(bool(buff)); vrt::if_packet_info_t packet_info; - packet_info.link_type = vrt::if_packet_info_t::LINK_TYPE_CHDR; - packet_info.packet_type = vrt::if_packet_info_t::PACKET_TYPE_CONTEXT; + packet_info.link_type = vrt::if_packet_info_t::LINK_TYPE_CHDR; + packet_info.packet_type = vrt::if_packet_info_t::PACKET_TYPE_CONTEXT; packet_info.num_payload_words32 = 2; - packet_info.num_payload_bytes = packet_info.num_payload_words32*sizeof(uint32_t); + packet_info.num_payload_bytes = + packet_info.num_payload_words32 * sizeof(uint32_t); packet_info.packet_count = _count++; - packet_info.sob = false; - packet_info.eob = false; - packet_info.sid = _sid; - packet_info.has_sid = true; - packet_info.has_cid = false; - packet_info.has_tsi = false; - packet_info.has_tsf = false; - packet_info.has_tlr = false; + packet_info.sob = false; + packet_info.eob = false; + packet_info.sid = _sid; + packet_info.has_sid = true; + packet_info.has_cid = false; + packet_info.has_tsi = false; + packet_info.has_tsf = false; + packet_info.has_tlr = false; - uint32_t *packet_buff = buff->cast<uint32_t *>(); + uint32_t* packet_buff = buff->cast<uint32_t*>(); vrt::if_hdr_pack_le(packet_buff, packet_info); - packet_buff[packet_info.num_header_words32+0] = uhd::htowx(uint32_t(_baud_div)); - packet_buff[packet_info.num_header_words32+1] = uhd::htowx(uint32_t(ch)); - buff->commit(packet_info.num_packet_words32*sizeof(uint32_t)); + packet_buff[packet_info.num_header_words32 + 0] = uhd::htowx(uint32_t(_baud_div)); + packet_buff[packet_info.num_header_words32 + 1] = uhd::htowx(uint32_t(ch)); + buff->commit(packet_info.num_packet_words32 * sizeof(uint32_t)); } - void write_uart(const std::string &buff) + void write_uart(const std::string& buff) { - for(const char ch: buff) - { + for (const char ch : buff) { this->send_char(ch); } } @@ -73,15 +73,14 @@ struct b200_uart_impl : b200_uart void handle_uart_packet(managed_recv_buffer::sptr buff) { - const uint32_t *packet_buff = buff->cast<const uint32_t *>(); + const uint32_t* packet_buff = buff->cast<const uint32_t*>(); vrt::if_packet_info_t packet_info; - packet_info.link_type = vrt::if_packet_info_t::LINK_TYPE_CHDR; - packet_info.num_packet_words32 = buff->size()/sizeof(uint32_t); + packet_info.link_type = vrt::if_packet_info_t::LINK_TYPE_CHDR; + packet_info.num_packet_words32 = buff->size() / sizeof(uint32_t); vrt::if_hdr_unpack_le(packet_buff, packet_info); - const char ch = char(uhd::wtohx(packet_buff[packet_info.num_header_words32+1])); + const char ch = char(uhd::wtohx(packet_buff[packet_info.num_header_words32 + 1])); _line += ch; - if (ch == '\n') - { + if (ch == '\n') { _line_queue.push_with_pop_on_full(_line); _line.clear(); } diff --git a/host/lib/usrp/b200/b200_uart.hpp b/host/lib/usrp/b200/b200_uart.hpp index c6de5f844..b70cdfa89 100644 --- a/host/lib/usrp/b200/b200_uart.hpp +++ b/host/lib/usrp/b200/b200_uart.hpp @@ -14,7 +14,7 @@ #include <uhd/utils/noncopyable.hpp> #include <memory> -class b200_uart: uhd::noncopyable, public uhd::uart_iface +class b200_uart : uhd::noncopyable, public uhd::uart_iface { public: typedef std::shared_ptr<b200_uart> sptr; |