diff options
author | Josh Blum <josh@joshknows.com> | 2010-08-19 17:15:30 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-08-19 17:15:30 -0700 |
commit | a32c3217cb703430f417cf5a3b816f6fd0f70ed3 (patch) | |
tree | b50b370c4ce9a50c1218e1f5b2ff773840fb2d2f /host | |
parent | 0f2bf7bf709f417e0ef5a0860e18b190f740fd1b (diff) | |
parent | d99e22971975e9b5bfb966741684963be8f049f6 (diff) | |
download | uhd-a32c3217cb703430f417cf5a3b816f6fd0f70ed3.tar.gz uhd-a32c3217cb703430f417cf5a3b816f6fd0f70ed3.tar.bz2 uhd-a32c3217cb703430f417cf5a3b816f6fd0f70ed3.zip |
Merge branch 'master' into usrp1
Diffstat (limited to 'host')
-rw-r--r-- | host/config/Version.cmake | 2 | ||||
-rw-r--r-- | host/docs/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/docs/coding.rst | 7 | ||||
-rw-r--r-- | host/docs/images.rst | 103 | ||||
-rw-r--r-- | host/docs/index.rst | 1 | ||||
-rw-r--r-- | host/docs/usrp2.rst | 36 | ||||
-rw-r--r-- | host/examples/CMakeLists.txt | 8 | ||||
-rw-r--r-- | host/examples/tx_continuous_samples.cpp | 110 | ||||
-rw-r--r-- | host/examples/tx_waveforms.cpp | 144 | ||||
-rw-r--r-- | host/include/uhd/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/utils/images.hpp | 38 | ||||
-rw-r--r-- | host/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | host/lib/usrp/misc_utils.cpp | 65 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dsp_impl.cpp | 5 | ||||
-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 | 14 |
17 files changed, 381 insertions, 197 deletions
diff --git a/host/config/Version.cmake b/host/config/Version.cmake index a592a4565..9e4b6b306 100644 --- a/host/config/Version.cmake +++ b/host/config/Version.cmake @@ -42,7 +42,7 @@ ELSE(${GIT} STREQUAL "GIT-NOTFOUND") #extract the timestamp from the git log entry EXECUTE_PROCESS( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMAND ${PYTHON_EXECUTABLE} -c "import re; print re.match('^.*Date:\\s*(\\d*).*$', '''${_git_log}''', re.MULTILINE | re.DOTALL).groups()[0]" + COMMAND ${PYTHON_EXECUTABLE} -c "import re; print re.match('^.*Date:\\s*(\\d*).*$', ''' ${_git_log} ''', re.MULTILINE | re.DOTALL).groups()[0]" OUTPUT_VARIABLE _git_timestamp OUTPUT_STRIP_TRAILING_WHITESPACE ) diff --git a/host/docs/CMakeLists.txt b/host/docs/CMakeLists.txt index d0041f71c..b4383f88d 100644 --- a/host/docs/CMakeLists.txt +++ b/host/docs/CMakeLists.txt @@ -24,6 +24,7 @@ SET(manual_sources coding.rst dboards.rst general.rst + images.rst usrp2.rst ) diff --git a/host/docs/coding.rst b/host/docs/coding.rst index 84f9abf3e..23f350b0f 100644 --- a/host/docs/coding.rst +++ b/host/docs/coding.rst @@ -64,7 +64,12 @@ Integrating custom hardware ------------------------------------------------------------------------ Creators of custom hardware can create drivers that use the UHD API. These drivers can be built as dynamically loadable modules that the UHD will load at runtime. -For a module to be loaded at runtime, it must be found in the UHD_MODULE_PATH environment variable. + +For a module to be loaded at runtime, it must be: + +* found in the UHD_MODULE_PATH environment variable, +* installed into the <prefix>/share/uhd/modules directory, +* or installed into /usr/share/uhd/modules directory (unix only). ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Custom motherboard diff --git a/host/docs/images.rst b/host/docs/images.rst new file mode 100644 index 000000000..612a00aa5 --- /dev/null +++ b/host/docs/images.rst @@ -0,0 +1,103 @@ +======================================================================== +UHD - Firmware and FPGA Image Application Notes +======================================================================== + +.. contents:: Table of Contents + +------------------------------------------------------------------------ +Images Overview +------------------------------------------------------------------------ +Every USRP device must be loaded with special firmware and FPGA images. +The methods of loading images into the device varies among devices: + +* **USRP1:** The host code will automatically load the firmware and FPGA at runtime. +* **USRP2:** The user must manually write the images onto the USRP2 SD card. + +------------------------------------------------------------------------ +Pre-built images +------------------------------------------------------------------------ + +Pre-built images are available for download. +See the UHD wiki for the download link. + +The pre-built images come in platform-specific installer packages +and platform-independent archive files: + +* **Linux:** DEB or RPM installer +* **Windows:** not available yet... +* **Macintosh:** not available yet... +* **Platform-independent:** ZIP or TAR.GZ archive + +^^^^^^^^^^^^^^^^^^ +Linux installers +^^^^^^^^^^^^^^^^^^ +The Linux-based installers will install the images into /usr/share/uhd/images. +On a Linux system, the UHD will always search this path for image files. + +Commands to install a linux rpm or deb package: + +:: + + sudo rpm -i <linux-images-installer>.rpm + + -- OR -- + + sudo dpkg -i <linux-images-installer>.deb + +^^^^^^^^^^^^^^^^^^^^^^ +Archive install +^^^^^^^^^^^^^^^^^^^^^^ +When installing images from an archive, there are two options: + +**Option 1:** + +Unpack the archive into the UHD installation prefix. +The UHD will always search <prefix>/share/uhd/images for image files. +Where <prefix> was set by the CMAKE_INSTALL_PREFIX at configure-time. + +**Option 2:** + +Unpack the archive anywhere and set the UHD_IMAGE_PATH environment variable. +The UHD_IMAGE_PATH may contain a list of directories to search for image files. + +------------------------------------------------------------------------ +Building images +------------------------------------------------------------------------ + +The UHD source repository comes with the source code necessary to build +both firmware and FPGA images for all supported devices. +The build commands for a particular image can be found in <uhd-repo-path>/images/Makefile. + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Xilinx FPGA builds +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Xilinx ISE 12.x and up is required to build the Xilinx FPGA images. +The build requires that you have a unix-like environment with make. +Make sure that xtclsh from the Xilinx ISE bin directory is in your $PATH. + +See <uhd-repo-path>/fpga/usrp2/top/* + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Microblaze firmware builds +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Microblaze GCC compiler from the Xilinx EDK is required to build the Microblaze firmware images. +The build requires that you have a unix-like environment with autotools and make. +Make sure that mb-gcc from the Xilinx EDK/microblaze directory is in your $PATH. + +See <uhd-repo-path>/firmware/microblaze + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Altera FPGA builds +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Quartus is required to build the Altera FPGA images. +Pre-built images can also be found in <uhd-repo-path>/fpga/usrp1/rbf + +See <uhd-repo-path>/fpga/usrp1/toplevel/* + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +FX2 firmware builds +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The sdcc compiler is required to build the FX2 firmware images. +The build requires that you have a unix-like environment with autotools and make. + +See <uhd-repo-path>/firmware/fx2 diff --git a/host/docs/index.rst b/host/docs/index.rst index b31a3d0ac..6973ede19 100644 --- a/host/docs/index.rst +++ b/host/docs/index.rst @@ -21,6 +21,7 @@ Building the UHD Application Notes ^^^^^^^^^^^^^^^^^^^^^ * `General App Notes <./general.html>`_ +* `Firmware and FPGA Image Notes <./images.html>`_ * `USRP2 App Notes <./usrp2.html>`_ * `Daughterboard App Notes <./dboards.html>`_ diff --git a/host/docs/usrp2.rst b/host/docs/usrp2.rst index bc4ea0e44..3ac326f58 100644 --- a/host/docs/usrp2.rst +++ b/host/docs/usrp2.rst @@ -5,42 +5,6 @@ UHD - USRP2 Application Notes .. contents:: Table of Contents ------------------------------------------------------------------------ -Building firmware and FPGA images ------------------------------------------------------------------------- - -^^^^^^^^^^^^^^^^^^ -FPGA Image -^^^^^^^^^^^^^^^^^^ -Xilinx ISE 10.1 and up is required to build the FPGA image for the USRP2. -The build requires that you have a unix-like environment with make. -Make sure that xtclsh from the Xilinx ISE bin directory is in your $PATH. - -Run the following commands: -:: - - cd <uhd-repo-path>/fpga/usrp2/top/u2_rev3 - make -f Makefile.udp bin - -*The image file will be ./build/u2_rev3.bin* - -^^^^^^^^^^^^^^^^^^ -Firmware Image -^^^^^^^^^^^^^^^^^^ -The Microblaze GCC compiler from the Xilinx EDK is required to build the firmware. -The build requires that you have a unix-like environment with autotools and make. -Make sure that mb-gcc from the Xilinx EDK/microblaze directory is in your $PATH. - -Run the following commands: -:: - - cd <uhd-repo-path>/firmware/microblaze - ./boostrap - ./configure --host=mb - make - -*The image file will be ./usrp2/usrp2_txrx_uhd.bin* - ------------------------------------------------------------------------- Load the images onto the SD card ------------------------------------------------------------------------ **Warning!** diff --git a/host/examples/CMakeLists.txt b/host/examples/CMakeLists.txt index 10a9a833a..c3bbbcd04 100644 --- a/host/examples/CMakeLists.txt +++ b/host/examples/CMakeLists.txt @@ -16,9 +16,6 @@ # -ADD_EXECUTABLE(tx_continuous_samples tx_continuous_samples.cpp) -TARGET_LINK_LIBRARIES(tx_continuous_samples uhd) - ADD_EXECUTABLE(benchmark_rx_rate benchmark_rx_rate.cpp) TARGET_LINK_LIBRARIES(benchmark_rx_rate uhd) @@ -28,10 +25,13 @@ TARGET_LINK_LIBRARIES(rx_timed_samples uhd) ADD_EXECUTABLE(tx_timed_samples tx_timed_samples.cpp) TARGET_LINK_LIBRARIES(tx_timed_samples uhd) +ADD_EXECUTABLE(tx_waveforms tx_waveforms.cpp) +TARGET_LINK_LIBRARIES(tx_waveforms uhd) + INSTALL(TARGETS - tx_continuous_samples benchmark_rx_rate rx_timed_samples tx_timed_samples + tx_waveforms RUNTIME DESTINATION ${PKG_DATA_DIR}/examples ) diff --git a/host/examples/tx_continuous_samples.cpp b/host/examples/tx_continuous_samples.cpp deleted file mode 100644 index cf70b07fb..000000000 --- a/host/examples/tx_continuous_samples.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// -// 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/thread_priority.hpp> -#include <uhd/utils/safe_main.hpp> -#include <uhd/usrp/simple_usrp.hpp> -#include <boost/program_options.hpp> -#include <boost/thread/thread_time.hpp> //system time -#include <boost/format.hpp> -#include <iostream> -#include <complex> - -namespace po = boost::program_options; - -int UHD_SAFE_MAIN(int argc, char *argv[]){ - uhd::set_thread_priority_safe(); - - //variables to be set by po - std::string args; - size_t total_duration; - size_t samps_per_packet; - double tx_rate, freq; - float ampl; - - //setup the program options - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args") - ("duration", po::value<size_t>(&total_duration)->default_value(3), "number of seconds to transmit") - ("spp", po::value<size_t>(&samps_per_packet)->default_value(1000), "number of samples per packet") - ("txrate", po::value<double>(&tx_rate)->default_value(100e6/16), "rate of outgoing samples") - ("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz") - ("ampl", po::value<float>(&l)->default_value(float(0.3)), "amplitude of each sample") - ("dilv", "specify to disable inner-loop verbose") - ; - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("UHD TX Continuous Samples %s") % desc << std::endl; - return ~0; - } - - bool verbose = vm.count("dilv") == 0; - - //create a usrp device - std::cout << std::endl; - std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; - uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(args); - uhd::device::sptr dev = sdev->get_device(); - std::cout << boost::format("Using Device: %s") % sdev->get_pp_string() << std::endl; - - //set properties on the device - std::cout << boost::format("Setting TX Rate: %f Msps...") % (tx_rate/1e6) << std::endl; - sdev->set_tx_rate(tx_rate); - std::cout << boost::format("Actual TX Rate: %f Msps...") % (sdev->get_tx_rate()/1e6) << std::endl; - sdev->set_tx_freq(freq); - - //allocate data to send - std::vector<std::complex<float> > buff(samps_per_packet, std::complex<float>(ampl, ampl)); - - //setup the metadata flags - uhd::tx_metadata_t md; - md.start_of_burst = true; //always SOB (good for continuous streaming) - md.end_of_burst = false; - - //send the data in multiple packets - boost::system_time end_time(boost::get_system_time() + boost::posix_time::seconds(total_duration)); - while(end_time > boost::get_system_time()){ - //send samples per packet (driver fragments internally) - size_t num_tx_samps = dev->send( - &buff.front(), samps_per_packet, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF - ); - if(verbose) std::cout << std::endl << boost::format("Sent %d samples") % num_tx_samps << std::endl; - } - - //send a mini EOB packet - if(verbose) std::cout << std::endl << boost::format("Sending packet with end-of-burst") << std::endl; - md.start_of_burst = false; - md.end_of_burst = true; - dev->send( - NULL, 0, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF - ); - - //finished - std::cout << std::endl << "Done!" << std::endl << std::endl; - - return 0; -} diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp new file mode 100644 index 000000000..e9cf210bb --- /dev/null +++ b/host/examples/tx_waveforms.cpp @@ -0,0 +1,144 @@ +// +// 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/thread_priority.hpp> +#include <uhd/utils/safe_main.hpp> +#include <uhd/usrp/simple_usrp.hpp> +#include <boost/program_options.hpp> +#include <boost/thread/thread_time.hpp> //system time +#include <boost/format.hpp> +#include <iostream> +#include <complex> +#include <cmath> + +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + uhd::set_thread_priority_safe(); + + //variables to be set by po + std::string args, wave_type; + size_t total_duration, amspb; + double rate, freq, wave_freq; + float ampl, gain; + + //setup the program options + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args") + ("duration", po::value<size_t>(&total_duration)->default_value(3), "number of seconds to transmit") + ("amspb", po::value<size_t>(&amspb)->default_value(10000), "approximate mimimum samples per buffer") + ("rate", po::value<double>(&rate)->default_value(100e6/16), "rate of outgoing samples") + ("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz") + ("ampl", po::value<float>(&l)->default_value(float(0.3)), "amplitude of the waveform") + ("gain", po::value<float>(&gain)->default_value(float(0)), "gain for the RF chain") + ("wave-type", po::value<std::string>(&wave_type)->default_value("SINE"), "waveform type (CONST, SQUARE, RAMP, SINE)") + ("wave-freq", po::value<double>(&wave_freq)->default_value(0), "waveform frequency in Hz") + ; + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("UHD TX Waveforms %s") % desc << std::endl; + return ~0; + } + + //create a usrp device + std::cout << std::endl; + std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; + uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(args); + uhd::device::sptr dev = sdev->get_device(); + std::cout << boost::format("Using Device: %s") % sdev->get_pp_string() << std::endl; + + //set the tx sample rate + std::cout << boost::format("Setting TX Rate: %f Msps...") % (rate/1e6) << std::endl; + sdev->set_tx_rate(rate); + std::cout << boost::format("Actual TX Rate: %f Msps...") % (sdev->get_tx_rate()/1e6) << std::endl << std::endl; + + //set the tx center frequency + std::cout << boost::format("Setting TX Freq: %f Mhz...") % (freq/1e6) << std::endl; + sdev->set_tx_freq(freq); + std::cout << boost::format("Actual TX Freq: %f Mhz...") % (sdev->get_tx_freq()/1e6) << std::endl << std::endl; + + //set the tx rf gain + std::cout << boost::format("Setting TX Gain: %f dB...") % gain << std::endl; + sdev->set_tx_gain(gain); + std::cout << boost::format("Actual TX Gain: %f dB...") % sdev->get_tx_gain() << std::endl << std::endl; + + //for the const wave, set the wave freq for small samples per period + if (wave_freq == 0 and wave_type == "CONST"){ + wave_freq = sdev->get_tx_rate()/2; + } + + //error when the waveform is not possible to generate + if (std::abs(wave_freq)/sdev->get_tx_rate() < 0.5/amspb){ + throw std::runtime_error("wave freq/tx rate too small"); + } + if (std::abs(wave_freq) > sdev->get_tx_rate()/2){ + throw std::runtime_error("wave freq out of Nyquist zone"); + } + + //fill a buffer with one period worth of samples + std::vector<float> period(size_t(sdev->get_tx_rate()/std::abs(wave_freq))); + std::cout << boost::format("Samples per waveform period: %d") % period.size() << std::endl; + for (size_t n = 0; n < period.size(); n++){ + if (wave_type == "CONST") period[n] = ampl; + else if (wave_type == "SQUARE") period[n] = (n > period.size()/2)? ampl : 0; + else if (wave_type == "RAMP") period[n] = float((n/double(period.size()-1)) * 2*ampl - ampl); + else if (wave_type == "SINE") period[n] = ampl*float(std::sin(2*M_PI*n/double(period.size()))); + else throw std::runtime_error("unknown waveform type: " + wave_type); + } + + //allocate data to send (fill with several periods worth of IQ samples) + const size_t periods_per_buff = std::max<size_t>(1, amspb/period.size()); + std::vector<std::complex<float> > buff(period.size()*periods_per_buff); + std::cout << boost::format("Samples per send buffer: %d") % buff.size() << std::endl; + const size_t i_ahead = (wave_freq > 0)? period.size()/4 : 0; + const size_t q_ahead = (wave_freq < 0)? period.size()/4 : 0; + for (size_t n = 0; n < buff.size(); n++) buff[n] = std::complex<float>( + period[(n+i_ahead)%period.size()], period[(n+q_ahead)%period.size()] //I,Q + ); + + //setup the metadata flags + uhd::tx_metadata_t md; + md.start_of_burst = true; //always SOB (good for continuous streaming) + md.end_of_burst = false; + + //send the data in multiple packets + boost::system_time end_time(boost::get_system_time() + boost::posix_time::seconds(total_duration)); + while(end_time > boost::get_system_time()) dev->send( + &buff.front(), buff.size(), md, + uhd::io_type_t::COMPLEX_FLOAT32, + uhd::device::SEND_MODE_FULL_BUFF + ); + + //send a mini EOB packet + md.start_of_burst = false; + md.end_of_burst = true; + dev->send(NULL, 0, md, + uhd::io_type_t::COMPLEX_FLOAT32, + uhd::device::SEND_MODE_FULL_BUFF + ); + + //finished + std::cout << std::endl << "Done!" << std::endl << std::endl; + + return 0; +} diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index ef8e64ce0..b39b6083c 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -23,6 +23,7 @@ INSTALL(FILES byteswap.ipp exception.hpp gain_group.hpp + images.hpp pimpl.hpp props.hpp safe_main.hpp diff --git a/host/include/uhd/utils/images.hpp b/host/include/uhd/utils/images.hpp new file mode 100644 index 000000000..8b5a1eedd --- /dev/null +++ b/host/include/uhd/utils/images.hpp @@ -0,0 +1,38 @@ +// +// 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/>. +// + +#ifndef INCLUDED_UHD_UTILS_IMAGES_HPP +#define INCLUDED_UHD_UTILS_IMAGES_HPP + +#include <uhd/config.hpp> +#include <string> + +namespace uhd{ + + /*! + * Search for an image in the system image paths: + * Search compiled-in paths and environment variable paths + * for a specific image file with the provided file name. + * \param image_name the name of the file + * \return the full system path to the file + * \throw exception if the image was not found + */ + UHD_API std::string find_image_path(const std::string &image_name); + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_IMAGES_HPP */ diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index cbb68c725..81845de21 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -54,11 +54,13 @@ 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} 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) 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/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/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 6ad12d3cc..9e9525caf 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -85,17 +85,3 @@ std::vector<fs::path> get_module_paths(void){ 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); -} |