diff options
Diffstat (limited to 'host/utils')
-rw-r--r-- | host/utils/CMakeLists.txt | 4 | ||||
-rw-r--r-- | host/utils/b2xx_fx3_utils.cpp | 472 | ||||
-rw-r--r-- | host/utils/fx2_init_eeprom.cpp | 8 | ||||
-rw-r--r-- | host/utils/query_gpsdo_sensors.cpp | 3 | ||||
-rw-r--r-- | host/utils/uhd-usrp.rules | 6 | ||||
-rw-r--r-- | host/utils/uhd_cal_rx_iq_balance.cpp | 5 | ||||
-rw-r--r-- | host/utils/uhd_cal_tx_dc_offset.cpp | 4 | ||||
-rw-r--r-- | host/utils/uhd_cal_tx_iq_balance.cpp | 5 | ||||
-rw-r--r-- | host/utils/uhd_find_devices.cpp | 7 | ||||
-rw-r--r-- | host/utils/uhd_usrp_probe.cpp | 26 | ||||
-rw-r--r-- | host/utils/usrp_burn_db_eeprom.cpp | 4 | ||||
-rw-r--r-- | host/utils/usrp_burn_mb_eeprom.cpp | 49 | ||||
-rw-r--r-- | host/utils/usrp_cal_utils.hpp | 6 | ||||
-rwxr-xr-x | host/utils/usrp_n2xx_net_burner_gui.py | 38 |
14 files changed, 581 insertions, 56 deletions
diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index b04d0e1b9..f73690475 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -47,7 +47,11 @@ SET(util_share_sources IF(ENABLE_USB) LIST(APPEND util_share_sources fx2_init_eeprom.cpp + b2xx_fx3_utils ) + INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS}) + # Additional include directories for b2xx_fx3_utils + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../lib/usrp/b200 ${CMAKE_CURRENT_SOURCE_DIR}/../lib/usrp/common) ENDIF(ENABLE_USB) IF(LINUX AND ENABLE_USB) diff --git a/host/utils/b2xx_fx3_utils.cpp b/host/utils/b2xx_fx3_utils.cpp new file mode 100644 index 000000000..c182548b7 --- /dev/null +++ b/host/utils/b2xx_fx3_utils.cpp @@ -0,0 +1,472 @@ +// +// Copyright 2010-2013 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <cstdlib> +#include <cstring> +#include <iostream> +#include <iomanip> +#include <fstream> +#include <libusb.h> +#include <sstream> +#include <string> +#include <cmath> +#include <cstring> + +#include <boost/cstdint.hpp> +#include <boost/filesystem.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/format.hpp> +#include <boost/program_options.hpp> +#include <boost/thread/thread.hpp> +#include <boost/functional/hash.hpp> + +#include <b200_iface.hpp> +#include <uhd/config.hpp> +#include <uhd/transport/usb_control.hpp> +#include <uhd/transport/usb_device_handle.hpp> +#include <uhd/exception.hpp> +#include <uhd/utils/images.hpp> + +namespace po = boost::program_options; +namespace fs = boost::filesystem; + + +//!used with lexical cast to parse a hex string +template <class T> struct to_hex{ + T value; + operator T() const {return value;} + friend std::istream& operator>>(std::istream& in, to_hex& out){ + in >> std::hex >> out.value; + return in; + } +}; + +//!parse hex-formatted ASCII text into an int +boost::uint16_t atoh(const std::string &string){ + if (string.substr(0, 2) == "0x"){ + return boost::lexical_cast<to_hex<boost::uint16_t> >(string); + } + return boost::lexical_cast<boost::uint16_t>(string); +} + +int reset_usb() +{ + /* Okay, first, we need to discover what the path is to the ehci and + * xhci device files. */ + std::set<fs::path> path_list; + path_list.insert("/sys/bus/pci/drivers/xhci-pci/"); + path_list.insert("/sys/bus/pci/drivers/ehci-pci/"); + path_list.insert("/sys/bus/pci/drivers/xhci_hcd/"); + path_list.insert("/sys/bus/pci/drivers/ehci_hcd/"); + + /* Check each of the possible paths above to find which ones this system + * uses. */ + for(std::set<fs::path>::iterator found = path_list.begin(); + found != path_list.end(); ++found) { + + if(fs::exists(*found)) { + + fs::path devpath = *found; + + std::set<fs::path> globbed; + + /* Now, glob all of the files in the directory. */ + fs::directory_iterator end_itr; + for(fs::directory_iterator itr(devpath); itr != end_itr; ++itr) { + globbed.insert((*itr).path()); + } + + /* Check each file path string to see if it is a device file. */ + for(std::set<fs::path>::iterator it = globbed.begin(); + it != globbed.end(); ++it) { + + std::string file = fs::path((*it).filename()).string(); + + if(file.compare(0, 5, "0000:") == 0) { + /* Un-bind the device. */ + std::fstream unbind((devpath.string() + "unbind").c_str(), + std::fstream::out); + unbind << file; + unbind.close(); + + /* Re-bind the device. */ + std::cout << "Re-binding: " << file << " in " + << devpath.string() << std::endl; + std::fstream bind((devpath.string() + "bind").c_str(), + std::fstream::out); + bind << file; + bind.close(); + } + } + } + } + + return 0; +} + +uhd::transport::usb_device_handle::sptr open_device(const boost::uint16_t vid, const boost::uint16_t pid) +{ + std::vector<uhd::transport::usb_device_handle::sptr> handles; + uhd::transport::usb_device_handle::sptr handle; + + try { + handles = uhd::transport::usb_device_handle::get_device_list(vid, pid); // try caller's VID/PID first + if (handles.size() == 0) + handles = uhd::transport::usb_device_handle::get_device_list(FX3_VID, FX3_DEFAULT_PID); // try default Cypress FX3 VID/PID next + if (handles.size() == 0) + handles = uhd::transport::usb_device_handle::get_device_list(FX3_VID, FX3_REENUM_PID); // try reenumerated Cypress FX3 VID/PID next + if (handles.size() == 0) + handles = uhd::transport::usb_device_handle::get_device_list(B200_VENDOR_ID, B200_PRODUCT_ID); // try default B200 VID/PID last + + if (handles.size() > 0) + handle = handles[0]; + + if (!handle) + std::cerr << "Cannot open device" << std::endl; + } + catch(const std::exception &e) { + std::cerr << "Failed to communicate with the device!" << std::endl; + #ifdef UHD_PLATFORM_WIN32 + std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details." << std::endl; + #endif /* UHD_PLATFORM_WIN32 */ + handle.reset(); + } + + return handle; +} + +b200_iface::sptr make_b200_iface(const uhd::transport::usb_device_handle::sptr &handle) +{ + b200_iface::sptr b200; + + try { + uhd::transport::usb_control::sptr usb_ctrl = uhd::transport::usb_control::make(handle, 0); + b200 = b200_iface::make(usb_ctrl); + + if (!b200) + std::cerr << "Cannot create device interface" << std::endl; + } + catch(const std::exception &e) { + std::cerr << "Failed to communicate with the device!" << std::endl; + #ifdef UHD_PLATFORM_WIN32 + std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details." << std::endl; + #endif /* UHD_PLATFORM_WIN32 */ + b200.reset(); + } + + return b200; +} + +boost::int32_t main(boost::int32_t argc, char *argv[]) { + boost::uint16_t vid, pid; + std::string pid_str, vid_str, fw_file, fpga_file; + + po::options_description visible("Allowed options"); + visible.add_options() + ("help,h", "help message") + ("vid,v", po::value<std::string>(&vid_str), + "Specify VID of device to use.") + ("pid,p", po::value<std::string>(&pid_str), + "Specify PID of device to use.") + ("speed,S", "Read back the USB mode currently in use.") + ("reset-device,D", "Reset the B2xx Device.") + ("reset-fpga,F", "Reset the FPGA (does not require re-programming.") + ("reset-usb,U", "Reset the USB subsystem on your host computer.") + ("init-device,I", "Initialize a B2xx device.") + ("load-fw,W", po::value<std::string>(&fw_file), + "Load a firmware (hex) file into the FX3.") + ("load-fpga,L", po::value<std::string>(&fpga_file), + "Load a FPGA (bin) file into the FPGA.") + ; + + // Hidden options provided for testing - use at your own risk! + po::options_description hidden("Hidden options"); + hidden.add_options() + ("uninit-device,U", "Uninitialize a B2xx device.") + ("read-eeprom,R", "Read first 8 bytes of EEPROM") + ("erase-eeprom,E", "Erase first 8 bytes of EEPROM"); + + po::options_description desc; + desc.add(visible); + desc.add(hidden); + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + if (vm.count("help")){ + std::cout << boost::format("B2xx Utility Program %s") % visible << std::endl; + return ~0; + } else if (vm.count("reset-usb")) { + return reset_usb(); + } + + uhd::transport::usb_device_handle::sptr handle; + b200_iface::sptr b200; + + vid = B200_VENDOR_ID; // Default + pid = B200_PRODUCT_ID; // Default + if (vm.count("vid")) + vid = atoh(vid_str); + if (vm.count("pid")) + pid = atoh(pid_str); + + // open the device + handle = open_device(vid, pid); + if (!handle) + return -1; + std::cout << "B2xx detected..." << std::flush; + + // make the interface + b200 = make_b200_iface(handle); + if (!b200) + return -1; + std::cout << " Control of B2xx granted..." << std::endl << std::endl; + + // if we are supposed to load a new firmware image and one already exists, reset the FX3 so we can load the new one + if (vm.count("load-fw") && handle->firmware_loaded()) + { + std::cout << "Overwriting existing firmware" << std::endl; + + // reset the device + b200->reset_fx3(); + + // re-open device + b200.reset(); + handle.reset(); + boost::this_thread::sleep(boost::posix_time::seconds(2)); // wait 2 seconds for FX3 to reset + handle = open_device(vid, pid); + if (!handle) + return -1; + b200 = make_b200_iface(handle); + if (!b200) + return -1; + } + + // Check to make sure firmware is loaded + if (!(handle->firmware_loaded())) + { + std::cout << "Loading firmware" << std::endl; + + if (fw_file.empty()) + fw_file = uhd::find_image_path(B200_FW_FILE_NAME); + + if(fw_file.empty()) { + std::cerr << "Firmware image not found!" << std::endl; + return -1; + } + + if(!(fs::exists(fw_file))) { + std::cerr << "Invalid filepath: " << fw_file << std::endl; + return -1; + } + + // load firmware + b200->load_firmware(fw_file); + + // re-open device + b200.reset(); + handle.reset(); + handle = open_device(vid, pid); + if (!handle) + return -1; + b200 = make_b200_iface(handle); + if (!b200) + return -1; + } + + // Added for testing purposes - not exposed + if (vm.count("read-eeprom")) + { + uhd::byte_vector_t data; + + try { + data = b200->read_eeprom(0x0, 0x0, 8); + } catch (std::exception &e) { + std::cerr << "Exception while reading EEPROM: " << e.what() << std::endl; + return -1; + } + for (int i = 0; i < 8; i++) + std::cout << i << ": " << boost::format("0x%X") % (int)data[i] << std::endl; + + return 0; + } + + // Added for testing purposes - not exposed + if (vm.count("erase-eeprom")) + { + uhd::byte_vector_t bytes(8); + memset(&bytes[0], 0xFF, 8); + try { + b200->write_eeprom(0x0, 0x0, bytes); + } catch (uhd::exception &e) { + std::cerr << "Exception while writing to EEPROM: " << e.what() << std::endl; + return -1; + } + + // verify + uhd::byte_vector_t read_bytes(8); + try { + read_bytes = b200->read_eeprom(0x0, 0x0, 8); + } catch (uhd::exception &e) { + std::cerr << "Exception while reading from EEPROM: " << e.what() << std::endl; + return -1; + } + bool verified = true; + for (int i = 0; i < 8; i++) { + if (bytes[i] != read_bytes[i]) { + verified = false; + std::cerr << "Expected: " << bytes[i] << ", Got: " << read_bytes[i] << std::endl; + } + } + if (!verified) { + std::cerr << "Verification failed" << std::endl; + return -1; + } + + std::cout << "Erase Successful!" << std::endl; + + return 0; + } + + // Added for testing purposes - not exposed + if (vm.count("uninit-device")) + { + // uninitialize the device + uhd::byte_vector_t bytes(8); + memset(&bytes[0], 0xFF, 8); + + try { + b200->write_eeprom(0x0, 0x0, bytes); + } catch (uhd::exception &e) { + std::cerr << "Exception while writing to EEPROM: " << e.what() << std::endl; + return -1; + } + + std::cout << "EEPROM uninitialized, resetting device..." + << std::endl << std::endl; + + // reset the device + try { + b200->reset_fx3(); + } catch (uhd::exception &e) { + std::cerr << "Exception while resetting FX3: " << e.what() << std::endl; + return -1; + } + + std::cout << "Uninitialization Process Complete." + << std::endl << std::endl; + + return 0; + } + + /* If we are initializing the device, the VID/PID should default to the + * Cypress VID/PID for the initial FW load, but we can initialize from any state. */ + if (vm.count("init-device")) + { + /* Now, initialize the device. */ + uhd::byte_vector_t bytes(8); + bytes[0] = 0x43; + bytes[1] = 0x59; + bytes[2] = 0x14; + bytes[3] = 0xB2; + bytes[4] = (B200_PRODUCT_ID & 0xff); + bytes[5] = (B200_PRODUCT_ID >> 8); + bytes[6] = (B200_VENDOR_ID & 0xff); + bytes[7] = (B200_VENDOR_ID >> 8); + + try { + b200->write_eeprom(0x0, 0x0, bytes); + } catch (uhd::exception &e) { + std::cerr << "Exception while writing to EEPROM: " << e.what() << std::endl; + return -1; + } + + std::cout << "EEPROM initialized, resetting device..." + << std::endl << std::endl; + + /* Reset the device! */ + try { + b200->reset_fx3(); + } catch (const std::exception &e) { + std::cerr << "Exceptions while resetting device: " << e.what() << std::endl; + return -1; + } + + std::cout << "Initialization Process Complete." + << std::endl << std::endl; + return 0; + } + + boost::uint8_t data_buffer[16]; + memset(data_buffer, 0x0, sizeof(data_buffer)); + + if (vm.count("speed")){ + boost::uint8_t speed; + try {speed = b200->get_usb_speed();} + catch (uhd::exception &e) { + std::cerr << "Exception while getting USB speed: " << e.what() << std::endl; + return -1; + } + std::cout << "Currently operating at USB " << (int) speed << std::endl; + + } else if (vm.count("reset-device")) { + try {b200->reset_fx3();} + catch (uhd::exception &e) { + std::cerr << "Exception while resetting FX3: " << e.what() << std::endl; + return -1; + } + + } else if (vm.count("reset-fpga")) { + try {b200->set_fpga_reset_pin(true);} + catch (uhd::exception &e) { + std::cerr << "Exception while resetting FPGA: " << e.what() << std::endl; + return -1; + } + + } else if (vm.count("load-fw")) { + std::cout << "Firmware load complete, releasing USB interface..." + << std::endl; + + } else if (vm.count("load-fpga")) { + std::cout << "Loading FPGA image (" << fpga_file << ")" << std::endl; + uint32_t fx3_state; + try {fx3_state = b200->load_fpga(fpga_file);} // returns 0 on success, or FX3 state on error + catch (uhd::exception &e) { + std::cerr << "Exception while loading FPGA: " << e.what() << std::endl; + return ~0; + } + + if (fx3_state != 0) { + std::cerr << std::flush << "Error loading FPGA. FX3 state: " + << fx3_state << std::endl; + return ~0; + } + + std::cout << "FPGA load complete, releasing USB interface..." + << std::endl; + + } else { + std::cout << boost::format("B2xx Utility Program %s") % visible << std::endl; + return ~0; + } + + std::cout << "Operation complete! I did it! I did it!" << std::endl; + + return 0; +} + diff --git a/host/utils/fx2_init_eeprom.cpp b/host/utils/fx2_init_eeprom.cpp index c210ae575..701092a5d 100644 --- a/host/utils/fx2_init_eeprom.cpp +++ b/host/utils/fx2_init_eeprom.cpp @@ -41,12 +41,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); + po::notify(vm); //print the help message if (vm.count("help")){ std::cout << boost::format("USRP EEPROM initialization %s") % desc << std::endl; - return ~0; + return EXIT_FAILURE; } //cant find a uninitialized usrp with this mystery module in the way... @@ -76,7 +76,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ if (found_addrs.size() == 0){ std::cerr << "No USRP devices found" << std::endl; - return ~0; + return EXIT_FAILURE; } for (size_t i = 0; i < found_addrs.size(); i++){ @@ -89,5 +89,5 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl; - return 0; + return EXIT_SUCCESS; } diff --git a/host/utils/query_gpsdo_sensors.cpp b/host/utils/query_gpsdo_sensors.cpp index 8e34bb3d5..91088112c 100644 --- a/host/utils/query_gpsdo_sensors.cpp +++ b/host/utils/query_gpsdo_sensors.cpp @@ -27,6 +27,7 @@ #include <boost/thread.hpp> #include <string> #include <cmath> +#include <ctime> #include <cstdlib> namespace po = boost::program_options; @@ -102,6 +103,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //Check PPS and compare UHD device time to GPS time boost::this_thread::sleep(boost::posix_time::seconds(1)); uhd::sensor_value_t gps_time = usrp->get_mboard_sensor("gps_time"); + const time_t pc_clock_time = time(NULL); const uhd::time_spec_t last_pps_time = usrp->get_time_last_pps(); if (last_pps_time.to_ticks(1.0) == gps_time.to_int()) { std::cout << boost::format("GPS and UHD Device time are aligned.\n"); @@ -114,6 +116,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::sensor_value_t rmc_string = usrp->get_mboard_sensor("gps_gprmc"); std::cout << boost::format("%s\n%s\n%s\n") % gga_string.to_pp_string() % rmc_string.to_pp_string() % gps_time.to_pp_string(); std::cout << boost::format("UHD Device time: %.0f seconds\n") % (last_pps_time.get_real_secs()); + std::cout << boost::format("PC Clock time: %.0f seconds\n") % pc_clock_time; //finished std::cout << boost::format("\nDone!\n\n"); diff --git a/host/utils/uhd-usrp.rules b/host/utils/uhd-usrp.rules index 56d9a8c43..2f5198d64 100644 --- a/host/utils/uhd-usrp.rules +++ b/host/utils/uhd-usrp.rules @@ -15,5 +15,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +#USRP1 SUBSYSTEMS=="usb", ATTRS{idVendor}=="fffe", ATTRS{idProduct}=="0002", MODE:="0666" + +#B100 SUBSYSTEMS=="usb", ATTRS{idVendor}=="2500", ATTRS{idProduct}=="0002", MODE:="0666" + +#B200 +SUBSYSTEMS=="usb", ATTRS{idVendor}=="2500", ATTRS{idProduct}=="0020", MODE:="0666" diff --git a/host/utils/uhd_cal_rx_iq_balance.cpp b/host/utils/uhd_cal_rx_iq_balance.cpp index 68d0443da..5fb494114 100644 --- a/host/utils/uhd_cal_rx_iq_balance.cpp +++ b/host/utils/uhd_cal_rx_iq_balance.cpp @@ -29,6 +29,7 @@ #include <complex> #include <cmath> #include <ctime> +#include <cstdlib> namespace po = boost::program_options; @@ -120,7 +121,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "This application measures leakage between RX and TX on an XCVR daughterboard to self-calibrate.\n" << std::endl; - return ~0; + return EXIT_FAILURE; } //create a usrp device @@ -239,5 +240,5 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ store_results(usrp, results, "RX", "rx", "iq"); - return 0; + return EXIT_SUCCESS; } diff --git a/host/utils/uhd_cal_tx_dc_offset.cpp b/host/utils/uhd_cal_tx_dc_offset.cpp index 8f69b3ce1..c9cf757f4 100644 --- a/host/utils/uhd_cal_tx_dc_offset.cpp +++ b/host/utils/uhd_cal_tx_dc_offset.cpp @@ -123,7 +123,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "This application measures leakage between RX and TX on an XCVR daughterboard to self-calibrate.\n" << std::endl; - return ~0; + return EXIT_FAILURE; } //create a usrp device @@ -237,5 +237,5 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ store_results(usrp, results, "TX", "tx", "dc"); - return 0; + return EXIT_SUCCESS; } diff --git a/host/utils/uhd_cal_tx_iq_balance.cpp b/host/utils/uhd_cal_tx_iq_balance.cpp index 5478b07e3..20d018edf 100644 --- a/host/utils/uhd_cal_tx_iq_balance.cpp +++ b/host/utils/uhd_cal_tx_iq_balance.cpp @@ -28,6 +28,7 @@ #include <iostream> #include <complex> #include <ctime> +#include <cstdlib> namespace po = boost::program_options; @@ -123,7 +124,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "This application measures leakage between RX and TX on an XCVR daughterboard to self-calibrate.\n" << std::endl; - return ~0; + return EXIT_FAILURE; } //create a usrp device @@ -242,5 +243,5 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ store_results(usrp, results, "TX", "tx", "iq"); - return 0; + return EXIT_SUCCESS; } diff --git a/host/utils/uhd_find_devices.cpp b/host/utils/uhd_find_devices.cpp index b778eeb68..c258c580e 100644 --- a/host/utils/uhd_find_devices.cpp +++ b/host/utils/uhd_find_devices.cpp @@ -20,6 +20,7 @@ #include <boost/program_options.hpp> #include <boost/format.hpp> #include <iostream> +#include <cstdlib> namespace po = boost::program_options; @@ -37,7 +38,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //print the help message if (vm.count("help")){ std::cout << boost::format("UHD Find Devices %s") % desc << std::endl; - return ~0; + return EXIT_FAILURE; } //discover the usrps and print the results @@ -45,7 +46,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ if (device_addrs.size() == 0){ std::cerr << "No UHD Devices Found" << std::endl; - return ~0; + return EXIT_FAILURE; } for (size_t i = 0; i < device_addrs.size(); i++){ @@ -56,5 +57,5 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //uhd::device::make(device_addrs[i]); //test make } - return 0; + return EXIT_SUCCESS; } diff --git a/host/utils/uhd_usrp_probe.cpp b/host/utils/uhd_usrp_probe.cpp index 5b3702fb4..98ed84850 100644 --- a/host/utils/uhd_usrp_probe.cpp +++ b/host/utils/uhd_usrp_probe.cpp @@ -30,6 +30,7 @@ #include <iostream> #include <sstream> #include <vector> +#include <cstdlib> namespace po = boost::program_options; using namespace uhd; @@ -114,13 +115,16 @@ static std::string get_dboard_pp_string(const std::string &type, property_tree:: ss << boost::format("%s Dboard: %s") % type % path.leaf() << std::endl; //ss << std::endl; const std::string prefix = (type == "RX")? "rx" : "tx"; - usrp::dboard_eeprom_t db_eeprom = tree->access<usrp::dboard_eeprom_t>(path / (prefix + "_eeprom")).get(); - if (db_eeprom.id != usrp::dboard_id_t::none()) ss << boost::format("ID: %s") % db_eeprom.id.to_pp_string() << std::endl; - if (not db_eeprom.serial.empty()) ss << boost::format("Serial: %s") % db_eeprom.serial << std::endl; - if (type == "TX"){ - usrp::dboard_eeprom_t gdb_eeprom = tree->access<usrp::dboard_eeprom_t>(path / "gdb_eeprom").get(); - if (gdb_eeprom.id != usrp::dboard_id_t::none()) ss << boost::format("ID: %s") % gdb_eeprom.id.to_pp_string() << std::endl; - if (not gdb_eeprom.serial.empty()) ss << boost::format("Serial: %s") % gdb_eeprom.serial << std::endl; + if (tree->exists(path / (prefix + "_eeprom"))) + { + usrp::dboard_eeprom_t db_eeprom = tree->access<usrp::dboard_eeprom_t>(path / (prefix + "_eeprom")).get(); + if (db_eeprom.id != usrp::dboard_id_t::none()) ss << boost::format("ID: %s") % db_eeprom.id.to_pp_string() << std::endl; + if (not db_eeprom.serial.empty()) ss << boost::format("Serial: %s") % db_eeprom.serial << std::endl; + if (type == "TX"){ + usrp::dboard_eeprom_t gdb_eeprom = tree->access<usrp::dboard_eeprom_t>(path / "gdb_eeprom").get(); + if (gdb_eeprom.id != usrp::dboard_id_t::none()) ss << boost::format("ID: %s") % gdb_eeprom.id.to_pp_string() << std::endl; + if (not gdb_eeprom.serial.empty()) ss << boost::format("Serial: %s") % gdb_eeprom.serial << std::endl; + } } BOOST_FOREACH(const std::string &name, tree->list(path / (prefix + "_frontends"))){ ss << make_border(get_frontend_pp_string(type, tree, path / (prefix + "_frontends") / name)); @@ -197,12 +201,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //print the help message if (vm.count("help")){ std::cout << boost::format("UHD USRP Probe %s") % desc << std::endl; - return ~0; + return EXIT_FAILURE; } if (vm.count("version")){ std::cout << uhd::get_version_string() << std::endl; - return 0; + return EXIT_SUCCESS; } device::sptr dev = device::make(vm["args"].as<std::string>()); @@ -210,11 +214,11 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ if (vm.count("string")){ std::cout << tree->access<std::string>(vm["string"].as<std::string>()).get() << std::endl; - return 0; + return EXIT_SUCCESS; } if (vm.count("tree") != 0) print_tree("/", tree); else std::cout << make_border(get_device_pp_string(tree)) << std::endl; - return 0; + return EXIT_SUCCESS; } diff --git a/host/utils/usrp_burn_db_eeprom.cpp b/host/utils/usrp_burn_db_eeprom.cpp index b6b2dc4d6..3ca953115 100644 --- a/host/utils/usrp_burn_db_eeprom.cpp +++ b/host/utils/usrp_burn_db_eeprom.cpp @@ -58,7 +58,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ "Omit the ID argument to perform readback,\n" "Or specify a new ID to burn into the EEPROM.\n" ) << std::endl; - return ~0; + return EXIT_FAILURE; } //make the device and extract the dboard w/ property @@ -96,5 +96,5 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format(" Current revision: \"%s\"") % db_eeprom.revision << std::endl; std::cout << " Done" << std::endl << std::endl; - return 0; + return EXIT_SUCCESS; } diff --git a/host/utils/usrp_burn_mb_eeprom.cpp b/host/utils/usrp_burn_mb_eeprom.cpp index ca9a6c8ba..ce0879c8e 100644 --- a/host/utils/usrp_burn_mb_eeprom.cpp +++ b/host/utils/usrp_burn_mb_eeprom.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010,2013 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,9 +19,11 @@ #include <uhd/device.hpp> #include <uhd/property_tree.hpp> #include <uhd/usrp/mboard_eeprom.hpp> +#include <boost/algorithm/string.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> #include <iostream> +#include <vector> namespace po = boost::program_options; @@ -32,8 +34,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ desc.add_options() ("help", "help message") ("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]") - ("key", po::value<std::string>(&key), "the indentifier for a value in EEPROM") - ("val", po::value<std::string>(&val), "the new value to set, omit for readback") + ("key", po::value<std::string>(&key), "identifiers for new values in EEPROM, separate multiple by \",\"") + ("val", po::value<std::string>(&val), "the new values to set, omit for readback, separate multiple by \",\"") ; po::variables_map vm; @@ -47,7 +49,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ "Omit the value argument to perform a readback,\n" "Or specify a new value to burn into the EEPROM.\n" ) << std::endl; - return ~0; + return EXIT_FAILURE; } std::cout << "Creating USRP device from address: " + args << std::endl; @@ -55,24 +57,39 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::property_tree::sptr tree = dev->get_tree(); std::cout << std::endl; - if (true /*always readback*/){ - std::cout << "Fetching current settings from EEPROM..." << std::endl; - uhd::usrp::mboard_eeprom_t mb_eeprom = tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/0/eeprom").get(); - if (not mb_eeprom.has_key(key)){ - std::cerr << boost::format("Cannot find value for EEPROM[%s]") % key << std::endl; - return ~0; + //remove whitespace, split arguments and values + boost::algorithm::erase_all(key, " "); + boost::algorithm::erase_all(val, " "); + + std::vector<std::string> keys_vec, vals_vec; + boost::split(keys_vec, key, boost::is_any_of("\"',")); + boost::split(vals_vec, val, boost::is_any_of("\"',")); + + if((keys_vec.size() != vals_vec.size()) and val != "") { + //If zero values are given, then user just wants values read to them + throw std::runtime_error("Number of keys must match number of values!"); + } + + std::cout << "Fetching current settings from EEPROM..." << std::endl; + uhd::usrp::mboard_eeprom_t mb_eeprom = tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/0/eeprom").get(); + for(size_t i = 0; i < keys_vec.size(); i++){ + if (not mb_eeprom.has_key(keys_vec[i])){ + std::cerr << boost::format("Cannot find value for EEPROM[%s]") % keys_vec[i] << std::endl; + return EXIT_FAILURE; } - std::cout << boost::format(" EEPROM [\"%s\"] is \"%s\"") % key % mb_eeprom[key] << std::endl; - std::cout << std::endl; + std::cout << boost::format(" EEPROM [\"%s\"] is \"%s\"") % keys_vec[i] % mb_eeprom[keys_vec[i]] << std::endl; } + std::cout << std::endl; if (vm.count("val")){ - uhd::usrp::mboard_eeprom_t mb_eeprom; mb_eeprom[key] = val; - std::cout << boost::format("Setting EEPROM [\"%s\"] to \"%s\"...") % key % val << std::endl; - tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/0/eeprom").set(mb_eeprom); + for(size_t i = 0; i < vals_vec.size(); i++){ + uhd::usrp::mboard_eeprom_t mb_eeprom; mb_eeprom[keys_vec[i]] = vals_vec[i]; + std::cout << boost::format("Setting EEPROM [\"%s\"] to \"%s\"...") % keys_vec[i] % vals_vec[i] << std::endl; + tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/0/eeprom").set(mb_eeprom); + } std::cout << "Power-cycle the USRP device for the changes to take effect." << std::endl; std::cout << std::endl; } std::cout << "Done" << std::endl; - return 0; + return EXIT_SUCCESS; } diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp index bda6fc31b..bab6ddd91 100644 --- a/host/utils/usrp_cal_utils.hpp +++ b/host/utils/usrp_cal_utils.hpp @@ -77,6 +77,9 @@ static inline void set_optimum_defaults(uhd::usrp::multi_usrp::sptr usrp){ else if (tx_name.find("SBX") != std::string::npos){ usrp->set_tx_gain(0); } + else if (tx_name.find("CBX") != std::string::npos){ + usrp->set_tx_gain(0); + } else if (tx_name.find("RFX") != std::string::npos){ usrp->set_tx_gain(0); } @@ -92,6 +95,9 @@ static inline void set_optimum_defaults(uhd::usrp::multi_usrp::sptr usrp){ else if (rx_name.find("SBX") != std::string::npos){ usrp->set_rx_gain(25); } + else if (rx_name.find("CBX") != std::string::npos){ + usrp->set_rx_gain(25); + } else if (rx_name.find("RFX") != std::string::npos){ usrp->set_rx_gain(25); } diff --git a/host/utils/usrp_n2xx_net_burner_gui.py b/host/utils/usrp_n2xx_net_burner_gui.py index 75d246c25..bad065f08 100755 --- a/host/utils/usrp_n2xx_net_burner_gui.py +++ b/host/utils/usrp_n2xx_net_burner_gui.py @@ -203,20 +203,30 @@ class USRPN2XXNetBurnerApp(tkinter.Frame): #make a new burner object and attempt the burner operation burner = usrp_n2xx_net_burner.burner_socket(addr=addr,quiet=False) - for (image_type, fw_img, fpga_img) in (('FPGA', '', fpga), ('Firmware', fw, '')): - #setup callbacks that update the gui - def status_cb(status): - self._pbar.set(0.0) #status change, reset the progress - self._status.set("%s %s "%(status.title(), image_type)) - self.update() - def progress_cb(progress): - self._pbar.set(progress) - self.update() - burner.set_callbacks(progress_cb=progress_cb, status_cb=status_cb) - burner.burn_fw(fw=fw_img, fpga=fpga_img, reset=False, safe=False, check_rev=not options.dont_check_rev) - - if tkinter.messagebox.askyesno("Burn was successful!", "Reset the device?"): - burner.reset_usrp() + #setup callbacks that update the gui + def status_cb(status): + self._pbar.set(0.0) #status change, reset the progress + self._status.set("%s %s "%(status.title(), image_type)) + self.update() + def progress_cb(progress): + self._pbar.set(progress) + self.update() + + if options.overwrite_safe: + if tkinter.messagebox.askyesno("Overwrite safe images?", "Overwrite safe images! This is ALMOST ALWAYS a terrible idea."): + for (image_type, fw_img, fpga_img) in (('FPGA', '', fpga), ('Firmware', fw, '')): + burner.set_callbacks(progress_cb=progress_cb, status_cb=status_cb) + burner.burn_fw(fw=fw_img, fpga=fpga_img, reset=False, safe=True, check_rev=not options.dont_check_rev) + + if tkinter.messagebox.askyesno("Burn was successful!", "Reset the device?"): + burner.reset_usrp() + else: + for (image_type, fw_img, fpga_img) in (('FPGA', '', fpga), ('Firmware', fw, '')): + burner.set_callbacks(progress_cb=progress_cb, status_cb=status_cb) + burner.burn_fw(fw=fw_img, fpga=fpga_img, reset=False, safe=False, check_rev=not options.dont_check_rev) + + if tkinter.messagebox.askyesno("Burn was successful!", "Reset the device?"): + burner.reset_usrp() except Exception as e: tkinter.messagebox.showerror('Verbose:', 'Error: %s'%str(e)) |