diff options
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/CMakeLists.txt | 12 | ||||
-rw-r--r-- | host/lib/constants.hpp.in | 6 | ||||
-rw-r--r-- | host/lib/usrp/misc_utils.cpp | 65 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/usrp1_impl.cpp | 34 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/usrp1_impl.hpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dsp_impl.cpp | 5 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/fw_common.h | 8 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 2 | ||||
-rw-r--r-- | host/lib/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/utils/images.cpp | 40 | ||||
-rw-r--r-- | host/lib/utils/paths.cpp | 22 |
11 files changed, 126 insertions, 75 deletions
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index b117b99ce..81845de21 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -53,8 +53,16 @@ INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/utils/CMakeLists.txt) ######################################################################## # Append to the list of sources for lib uhd ######################################################################## -FILE(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${PKG_DATA_DIR} FULL_PKG_DATA_DIR) -MESSAGE(STATUS "Full package data directory: ${FULL_PKG_DATA_DIR}") +FILE(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${PKG_DATA_DIR} LOCAL_PKG_DATA_DIR) +STRING(REPLACE "\\" "\\\\" LOCAL_PKG_DATA_DIR ${LOCAL_PKG_DATA_DIR}) +MESSAGE(STATUS "Local package data directory: ${LOCAL_PKG_DATA_DIR}") + +IF(UNIX) + #on unix systems, installers will use this directory for the package data + FILE(TO_NATIVE_PATH /usr/${PKG_DATA_DIR} INSTALLER_PKG_DATA_DIR) + STRING(REPLACE "\\" "\\\\" INSTALLER_PKG_DATA_DIR ${INSTALLER_PKG_DATA_DIR}) + MESSAGE(STATUS "Installer package data directory: ${INSTALLER_PKG_DATA_DIR}") +ENDIF(UNIX) CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/constants.hpp.in diff --git a/host/lib/constants.hpp.in b/host/lib/constants.hpp.in index 2ed4e302f..4aedb6d4a 100644 --- a/host/lib/constants.hpp.in +++ b/host/lib/constants.hpp.in @@ -18,11 +18,9 @@ #ifndef INCLUDED_LIBUHD_CONSTANTS_HPP #define INCLUDED_LIBUHD_CONSTANTS_HPP -#include <uhd/config.hpp> -#include <string> - //these should be pre-processor macros to avoid static initialization issues #define UHD_VERSION_STRING "@CPACK_PACKAGE_VERSION@" -#define FULL_PKG_DATA_DIR "@FULL_PKG_DATA_DIR@" +#define LOCAL_PKG_DATA_DIR "@LOCAL_PKG_DATA_DIR@" +#define INSTALLER_PKG_DATA_DIR "@INSTALLER_PKG_DATA_DIR@" #endif /* INCLUDED_LIBUHD_CONSTANTS_HPP */ diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp index 46094ba32..a1664d810 100644 --- a/host/lib/usrp/misc_utils.cpp +++ b/host/lib/usrp/misc_utils.cpp @@ -25,6 +25,7 @@ #include <uhd/usrp/codec_props.hpp> #include <boost/bind.hpp> #include <boost/foreach.hpp> +#include <boost/format.hpp> using namespace uhd; using namespace uhd::usrp; @@ -132,43 +133,49 @@ static void verify_xx_subdev_spec( wax::obj mboard, std::string xx_type ){ - prop_names_t dboard_names = mboard[dboard_names_prop].as<prop_names_t>(); - UHD_ASSERT_THROW(dboard_names.size() > 0); //well i hope there is a dboard + try{ + prop_names_t dboard_names = mboard[dboard_names_prop].as<prop_names_t>(); + UHD_ASSERT_THROW(dboard_names.size() > 0); //well i hope there is a dboard - //the subdevice specification is empty: handle automatic - if (subdev_spec.empty()){ - BOOST_FOREACH(const std::string &db_name, dboard_names){ - wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; + //the subdevice specification is empty: handle automatic + if (subdev_spec.empty()){ + BOOST_FOREACH(const std::string &db_name, dboard_names){ + wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; + + //if the dboard slot is populated, take the first subdevice + if (dboard[DBOARD_PROP_DBOARD_ID].as<dboard_id_t>() != dboard_id_t::none()){ + std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>().front(); + subdev_spec.push_back(subdev_spec_pair_t(db_name, sd_name)); + break; + } + } - //if the dboard slot is populated, take the first subdevice - if (dboard[DBOARD_PROP_DBOARD_ID].as<dboard_id_t>() != dboard_id_t::none()){ + //didnt find any populated dboards: add the first subdevice + if (subdev_spec.empty()){ + std::string db_name = dboard_names.front(); + wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>().front(); subdev_spec.push_back(subdev_spec_pair_t(db_name, sd_name)); - break; } } - //didnt find any populated dboards: add the first subdevice - if (subdev_spec.empty()){ - std::string db_name = dboard_names.front(); - wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; - std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>().front(); - subdev_spec.push_back(subdev_spec_pair_t(db_name, sd_name)); - } - } - - //sanity check that the dboard/subdevice names exist for this mboard - BOOST_FOREACH(const subdev_spec_pair_t &pair, subdev_spec){ - //empty db name means select dboard automatically - if (pair.db_name.empty()){ - if (dboard_names.size() != 1) throw std::runtime_error( - "A daughterboard name must be provided for multi-slot boards: " + subdev_spec.to_string() - ); - pair.db_name == dboard_names.front(); + //sanity check that the dboard/subdevice names exist for this mboard + BOOST_FOREACH(const subdev_spec_pair_t &pair, subdev_spec){ + //empty db name means select dboard automatically + if (pair.db_name.empty()){ + if (dboard_names.size() != 1) throw std::runtime_error( + "A daughterboard name must be provided for multi-slot boards: " + subdev_spec.to_string() + ); + pair.db_name == dboard_names.front(); + } + uhd::assert_has(dboard_names, pair.db_name, xx_type + " dboard name"); + wax::obj dboard = mboard[named_prop_t(dboard_prop, pair.db_name)]; + uhd::assert_has(dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>(), pair.sd_name, xx_type + " subdev name"); } - uhd::assert_has(dboard_names, pair.db_name, xx_type + " dboard name"); - wax::obj dboard = mboard[named_prop_t(dboard_prop, pair.db_name)]; - uhd::assert_has(dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>(), pair.sd_name, xx_type + " subdev name"); + }catch(const std::exception &e){ + throw std::runtime_error(str(boost::format( + "Validate %s subdev spec failed: %s\n %s" + ) % xx_type % subdev_spec.to_string() % e.what())); } } diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index a4effb907..a15d0a244 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -23,9 +23,11 @@ #include <uhd/usrp/device_props.hpp> #include <uhd/utils/assert.hpp> #include <uhd/utils/static.hpp> +#include <uhd/utils/images.hpp> #include <boost/format.hpp> #include <boost/assign/list_of.hpp> #include <boost/filesystem.hpp> +#include <boost/thread/thread.hpp> #include <iostream> using namespace uhd; @@ -42,11 +44,16 @@ const std::vector<usrp1_impl::dboard_slot_t> usrp1_impl::_dboard_slots = boost:: static device_addrs_t usrp1_find(const device_addr_t &hint) { device_addrs_t usrp1_addrs; - std::string filename = "/usr/local/share/usrp/rev4/std.ihx"; //return an empty list of addresses when type is set to non-usrp1 if (hint.has_key("type") and hint["type"] != "usrp1") return usrp1_addrs; + //extract the firmware path for the USRP1 + std::string usrp1_fw_image = find_image_path( + hint.has_key("fw")? hint["fw"] : "usrp1_fw.ihx" + ); + std::cout << "USRP1 firmware image: " << usrp1_fw_image << std::endl; + //see what we got on the USB bus std::vector<usb_device_handle::sptr> device_list = usb_device_handle::get_device_list(); @@ -58,12 +65,12 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) usb_control::sptr ctrl_transport = usb_control::make(handle); usrp_ctrl::sptr usrp_ctrl = usrp_ctrl::make(ctrl_transport); - usrp_ctrl->usrp_load_firmware(filename); + usrp_ctrl->usrp_load_firmware(usrp1_fw_image); } } //wait for things to settle - sleep(1); + boost::this_thread::sleep(boost::posix_time::milliseconds(500)); //get descriptors again with serial number device_list = usb_device_handle::get_device_list(); @@ -87,14 +94,11 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) **********************************************************************/ static device::sptr usrp1_make(const device_addr_t &device_addr) { - std::string filename; - - if (device_addr.has_key("fpga")) - filename = device_addr["fpga"]; - else - filename = "/usr/local/share/usrp/rev4/std_2rxhb_2tx.rbf"; - - std::cout << "Make usrp1 with " << filename << std::endl; + //extract the FPGA path for the USRP1 + std::string usrp1_fpga_image = find_image_path( + device_addr.has_key("fpga")? device_addr["fpga"] : "usrp1_fpga.rbf" + ); + std::cout << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl; //try to match the given device address with something on the USB bus std::vector<usb_device_handle::sptr> device_list = @@ -111,7 +115,7 @@ static device::sptr usrp1_make(const device_addr_t &device_addr) usb_control::sptr ctrl_transport = usb_control::make(handle); usrp_ctrl = usrp_ctrl::make(ctrl_transport); - usrp_ctrl->usrp_load_fpga(filename); + usrp_ctrl->usrp_load_fpga(usrp1_fpga_image); data_transport = usb_zero_copy::make(handle, // identifier 6, // IN endpoint @@ -176,6 +180,12 @@ usrp1_impl::~usrp1_impl(void){ /* NOP */ } +bool usrp1_impl::recv_async_msg(uhd::async_metadata_t &, size_t timeout_ms){ + //dummy fill-in for the recv_async_msg + boost::this_thread::sleep(boost::posix_time::milliseconds(timeout_ms)); + return false; +} + /*********************************************************************** * Device Get **********************************************************************/ diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp index 5934d1779..4b4ac51dd 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.hpp +++ b/host/lib/usrp/usrp1/usrp1_impl.hpp @@ -93,11 +93,7 @@ public: size_t get_max_send_samps_per_packet(void) const { return 0; } size_t get_max_recv_samps_per_packet(void) const { return 0; } - - bool recv_async_msg(uhd::async_metadata_t &, size_t) { - //TODO sleep the number of ms supplied (dont want to hog CPU) - return false; - } + bool recv_async_msg(uhd::async_metadata_t &, size_t); private: /*! diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 347ec38af..6422142ce 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -31,9 +31,10 @@ static const size_t default_interp = 16; /*********************************************************************** * DDC Helper Methods **********************************************************************/ -static unsigned pick_closest_rate(double exact_rate, const std::vector<unsigned> &rates){ +template <typename rate_type> +static rate_type pick_closest_rate(double exact_rate, const std::vector<rate_type> &rates){ unsigned closest_match = rates.front(); - BOOST_FOREACH(unsigned possible_rate, rates){ + BOOST_FOREACH(rate_type possible_rate, rates){ if(std::abs(exact_rate - possible_rate) < std::abs(exact_rate - closest_match)) closest_match = possible_rate; } diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index a781c1a21..cc6c41ba7 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -34,7 +34,7 @@ extern "C" { //fpga and firmware compatibility numbers #define USRP2_FPGA_COMPAT_NUM 1 -#define USRP2_FW_COMPAT_NUM 5 +#define USRP2_FW_COMPAT_NUM 6 //used to differentiate control packets over data port #define USRP2_INVALID_VRT_HEADER 0 @@ -104,12 +104,12 @@ typedef struct{ union{ __stdint(uint32_t) ip_addr; struct { - __stdint(uint8_t) dev; + __stdint(uint32_t) dev; + __stdint(uint32_t) data; __stdint(uint8_t) miso_edge; __stdint(uint8_t) mosi_edge; - __stdint(uint8_t) readback; - __stdint(uint32_t) data; __stdint(uint8_t) num_bits; + __stdint(uint8_t) readback; } spi_args; struct { __stdint(uint8_t) addr; diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 4124221ef..2d450bfc6 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -115,7 +115,7 @@ public: //setup the out data usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO); - out_data.data.spi_args.dev = which_slave; + out_data.data.spi_args.dev = htonl(which_slave); out_data.data.spi_args.miso_edge = spi_edge_to_otw[config.miso_edge]; out_data.data.spi_args.mosi_edge = spi_edge_to_otw[config.mosi_edge]; out_data.data.spi_args.readback = (readback)? 1 : 0; diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 68945545a..32b679d49 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -79,6 +79,7 @@ ENDIF(HAVE_DLFCN_H) LIBUHD_APPEND_SOURCES( ${CMAKE_SOURCE_DIR}/lib/utils/assert.cpp ${CMAKE_SOURCE_DIR}/lib/utils/gain_group.cpp + ${CMAKE_SOURCE_DIR}/lib/utils/images.cpp ${CMAKE_SOURCE_DIR}/lib/utils/load_modules.cpp ${CMAKE_SOURCE_DIR}/lib/utils/paths.cpp ${CMAKE_SOURCE_DIR}/lib/utils/props.cpp diff --git a/host/lib/utils/images.cpp b/host/lib/utils/images.cpp new file mode 100644 index 000000000..395e542c1 --- /dev/null +++ b/host/lib/utils/images.cpp @@ -0,0 +1,40 @@ +// +// Copyright 2010 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 <uhd/utils/images.hpp> +#include <boost/foreach.hpp> +#include <boost/filesystem.hpp> +#include <stdexcept> +#include <vector> + +namespace fs = boost::filesystem; + +std::vector<fs::path> get_image_paths(void); //defined in paths.cpp + +/*********************************************************************** + * Find a image in the image paths + **********************************************************************/ +std::string uhd::find_image_path(const std::string &image_name){ + if (fs::exists(image_name)){ + return fs::system_complete(image_name).file_string(); + } + BOOST_FOREACH(const fs::path &path, get_image_paths()){ + fs::path image_path = path / image_name; + if (fs::exists(image_path)) return image_path.file_string(); + } + throw std::runtime_error("Could not find path for image: " + image_name); +} diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 3f29945dd..9e9525caf 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -72,26 +72,16 @@ static std::vector<fs::path> get_env_paths(const std::string &var_name){ **********************************************************************/ std::vector<fs::path> get_image_paths(void){ std::vector<fs::path> paths = get_env_paths("UHD_IMAGE_PATH"); - paths.push_back(fs::path(FULL_PKG_DATA_DIR) / "images"); + paths.push_back(fs::path(LOCAL_PKG_DATA_DIR) / "images"); + if (not std::string(INSTALLER_PKG_DATA_DIR).empty()) + paths.push_back(fs::path(INSTALLER_PKG_DATA_DIR) / "images"); return paths; } std::vector<fs::path> get_module_paths(void){ std::vector<fs::path> paths = get_env_paths("UHD_MODULE_PATH"); - paths.push_back(fs::path(FULL_PKG_DATA_DIR) / "modules"); + paths.push_back(fs::path(LOCAL_PKG_DATA_DIR) / "modules"); + if (not std::string(INSTALLER_PKG_DATA_DIR).empty()) + paths.push_back(fs::path(INSTALLER_PKG_DATA_DIR) / "modules"); return paths; } - -/*********************************************************************** - * Find a image in the image paths - **********************************************************************/ -std::string find_image_path(const std::string &image_name){ - if (fs::exists(image_name)){ - return fs::system_complete(image_name).file_string(); - } - BOOST_FOREACH(const fs::path &path, get_image_paths()){ - fs::path image_path = path / image_name; - if (fs::exists(image_path)) return image_path.file_string(); - } - throw std::runtime_error("Could not find path for image: " + image_name); -} |