From 24bd27b90d06820d858c008cff915319873321c5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 23 Mar 2010 20:44:50 -0700 Subject: Reorganized apps dir into utils and examples dir. The files get installed into the pkg data directory. --- host/utils/CMakeLists.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 host/utils/CMakeLists.txt (limited to 'host/utils/CMakeLists.txt') diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt new file mode 100644 index 000000000..9ac3f3a52 --- /dev/null +++ b/host/utils/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# 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 . +# + +ADD_EXECUTABLE(discover_usrps discover_usrps.cpp) +TARGET_LINK_LIBRARIES(discover_usrps uhd) +INSTALL(TARGETS discover_usrps RUNTIME DESTINATION ${RUNTIME_DIR}) + +ADD_EXECUTABLE(usrp2_burner usrp2_burner.cpp) +TARGET_LINK_LIBRARIES(usrp2_burner uhd) +INSTALL(TARGETS usrp2_burner RUNTIME DESTINATION ${PKG_DATA_DIR}/utils) + +INSTALL(FILES usrp2_recovery.py DESTINATION ${PKG_DATA_DIR}/utils) -- cgit v1.2.3 From 71d4a26ea047c38c2aecfa982882dd45902b2393 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 24 Mar 2010 18:30:49 -0700 Subject: mess with that usrp2 io loop unroll, also py app gets installed executable --- host/lib/usrp/usrp2/io_impl.cpp | 45 +++++++++++++++++++++-------------------- host/utils/CMakeLists.txt | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) (limited to 'host/utils/CMakeLists.txt') diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index dc8eea243..df0736863 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -16,7 +16,6 @@ // #include -#include #include #include "usrp2_impl.hpp" @@ -46,16 +45,14 @@ void usrp2_impl::io_init(void){ _data_transport->send(asio::buffer(&zero_data, sizeof(zero_data))); } -#define unrolled_loop(__i, __len, __inst) {\ +#define unrolled_loop(__inst, __len){ \ size_t __i = 0; \ - while(__i < (__len & ~0x7)){ \ - __inst; __i++; __inst; __i++; \ - __inst; __i++; __inst; __i++; \ - __inst; __i++; __inst; __i++; \ - __inst; __i++; __inst; __i++; \ + for(; __i < (__len & ~0x3); __i+= 4){ \ + __inst(__i+0); __inst(__i+1); \ + __inst(__i+2); __inst(__i+3); \ } \ - while(__i < __len){ \ - __inst; __i++;\ + for(; __i < __len; __i++){ \ + __inst(__i); \ } \ } @@ -71,11 +68,12 @@ static inline void host_floats_to_usrp2_items( const fc32_t *host_floats, size_t num_samps ){ - unrolled_loop(i, num_samps,{ - boost::uint16_t real = boost::int16_t(host_floats[i].real()*shorts_per_float); - boost::uint16_t imag = boost::int16_t(host_floats[i].imag()*shorts_per_float); - usrp2_items[i] = htonl((real << 16) | (imag << 0)); - }); + #define host_floats_to_usrp2_items_i(i){ \ + boost::uint16_t real = boost::int16_t(host_floats[i].real()*shorts_per_float); \ + boost::uint16_t imag = boost::int16_t(host_floats[i].imag()*shorts_per_float); \ + usrp2_items[i] = htonl((real << 16) | (imag << 0)); \ + } + unrolled_loop(host_floats_to_usrp2_items_i, num_samps); } static inline void usrp2_items_to_host_floats( @@ -83,12 +81,13 @@ static inline void usrp2_items_to_host_floats( const boost::uint32_t *usrp2_items, size_t num_samps ){ - unrolled_loop(i, num_samps,{ - boost::uint32_t item = ntohl(usrp2_items[i]); - boost::int16_t real = boost::uint16_t(item >> 16); - boost::int16_t imag = boost::uint16_t(item >> 0); - host_floats[i] = fc32_t(float(real*floats_per_short), float(imag*floats_per_short)); - }); + #define usrp2_items_to_host_floats_i(i){ \ + boost::uint32_t item = ntohl(usrp2_items[i]); \ + boost::int16_t real = boost::uint16_t(item >> 16); \ + boost::int16_t imag = boost::uint16_t(item >> 0); \ + host_floats[i] = fc32_t(float(real*floats_per_short), float(imag*floats_per_short)); \ + } + unrolled_loop(usrp2_items_to_host_floats_i, num_samps); } static inline void host_items_to_usrp2_items( @@ -96,11 +95,12 @@ static inline void host_items_to_usrp2_items( const boost::uint32_t *host_items, size_t num_samps ){ + #define host_items_to_usrp2_items_i(i) usrp2_items[i] = htonl(host_items[i]) if (is_big_endian){ std::memcpy(usrp2_items, host_items, num_samps*sizeof(boost::uint32_t)); } else{ - unrolled_loop(i, num_samps, usrp2_items[i] = htonl(host_items[i])); + unrolled_loop(host_items_to_usrp2_items_i, num_samps); } } @@ -109,11 +109,12 @@ static inline void usrp2_items_to_host_items( const boost::uint32_t *usrp2_items, size_t num_samps ){ + #define usrp2_items_to_host_items_i(i) host_items[i] = ntohl(usrp2_items[i]) if (is_big_endian){ std::memcpy(host_items, usrp2_items, num_samps*sizeof(boost::uint32_t)); } else{ - unrolled_loop(i, num_samps, host_items[i] = ntohl(usrp2_items[i])); + unrolled_loop(usrp2_items_to_host_items_i, num_samps); } } diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index 9ac3f3a52..1fb132937 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -23,4 +23,4 @@ ADD_EXECUTABLE(usrp2_burner usrp2_burner.cpp) TARGET_LINK_LIBRARIES(usrp2_burner uhd) INSTALL(TARGETS usrp2_burner RUNTIME DESTINATION ${PKG_DATA_DIR}/utils) -INSTALL(FILES usrp2_recovery.py DESTINATION ${PKG_DATA_DIR}/utils) +INSTALL(PROGRAMS usrp2_recovery.py DESTINATION ${PKG_DATA_DIR}/utils) -- cgit v1.2.3 From 281307833c8275031bd2469e6aef3f472490749a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 30 Mar 2010 15:11:23 -0700 Subject: use find to discover devices --- host/include/uhd/device.hpp | 14 +++---- host/include/uhd/usrp/usrp1e.hpp | 5 +-- host/include/uhd/usrp/usrp2.hpp | 5 +-- host/lib/device.cpp | 8 ++-- host/lib/usrp/usrp1e/usrp1e_none.cpp | 2 +- host/lib/usrp/usrp2/usrp2_impl.cpp | 7 ++-- host/utils/CMakeLists.txt | 6 +-- host/utils/discover_usrps.cpp | 71 ------------------------------------ host/utils/uhd_find_devices.cpp | 71 ++++++++++++++++++++++++++++++++++++ 9 files changed, 93 insertions(+), 96 deletions(-) delete mode 100644 host/utils/discover_usrps.cpp create mode 100644 host/utils/uhd_find_devices.cpp (limited to 'host/utils/CMakeLists.txt') diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 1d0360799..4d4196d98 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -38,22 +38,22 @@ class UHD_API device : boost::noncopyable, public wax::obj{ public: typedef boost::shared_ptr sptr; - typedef boost::function discover_t; + typedef boost::function find_t; typedef boost::function make_t; /*! * Register a device into the discovery and factory system. * - * \param discover a function that discovers devices + * \param find a function that discovers devices * \param make a factory function that makes a device */ static void register_device( - const discover_t &discover, + const find_t &find, const make_t &make ); /*! - * \brief Discover usrp devices attached to the host. + * \brief Find usrp devices attached to the host. * * The hint device address should be used to narrow down the search * to particular transport types and/or transport arguments. @@ -61,17 +61,17 @@ public: * \param hint a partially (or fully) filled in device address * \return a vector of device addresses for all usrps on the system */ - static device_addrs_t discover(const device_addr_t &hint); + static device_addrs_t find(const device_addr_t &hint); /*! * \brief Create a new usrp device from the device address hint. * - * The make routine will call discover and pick one of the results. + * The make routine will call find and pick one of the results. * By default, the first result will be used to create a new device. * Use the which parameter as an index into the list of results. * * \param hint a partially (or fully) filled in device address - * \param which which address to use when multiple are discovered + * \param which which address to use when multiple are found * \return a shared pointer to a new device instance */ static sptr make(const device_addr_t &hint, size_t which = 0); diff --git a/host/include/uhd/usrp/usrp1e.hpp b/host/include/uhd/usrp/usrp1e.hpp index 5cba4ef52..cee9dc3d5 100644 --- a/host/include/uhd/usrp/usrp1e.hpp +++ b/host/include/uhd/usrp/usrp1e.hpp @@ -29,12 +29,11 @@ namespace uhd{ namespace usrp{ class UHD_API usrp1e : public device{ public: /*! - * Discover usrp1e devices on the system via the device node. - * This static method will be called by the device::discover. + * Find usrp1e devices on the system via the device node. * \param hint a device addr with the usrp1e address filled in * \return a vector of device addresses for all usrp1es found */ - static device_addrs_t discover(const device_addr_t &hint); + static device_addrs_t find(const device_addr_t &hint); /*! * Make a usrp1e from a device address. diff --git a/host/include/uhd/usrp/usrp2.hpp b/host/include/uhd/usrp/usrp2.hpp index 277ddc131..613b40ae3 100644 --- a/host/include/uhd/usrp/usrp2.hpp +++ b/host/include/uhd/usrp/usrp2.hpp @@ -29,17 +29,16 @@ namespace uhd{ namespace usrp{ class UHD_API usrp2 : public device{ public: /*! - * Discover usrp2 devices over the ethernet. + * Find usrp2 devices over the ethernet. * * Recommended key/value pairs for the device hint address: * hint["addr"] = address, where address is a resolvable address * or ip address, which may or may not be a broadcast address. * - * This static method will be called by the device::discover. * \param hint a device addr with the usrp2 address filled in * \return a vector of device addresses for all usrp2s found */ - static device_addrs_t discover(const device_addr_t &hint); + static device_addrs_t find(const device_addr_t &hint); /*! * Make a usrp2 from a device address. diff --git a/host/lib/device.cpp b/host/lib/device.cpp index ca45d0795..27a365d34 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -57,23 +57,23 @@ static size_t hash_device_addr( /*********************************************************************** * Registration **********************************************************************/ -typedef boost::tuple dev_fcn_reg_t; +typedef boost::tuple dev_fcn_reg_t; // instantiate the device function registry container UHD_SINGLETON_FCN(std::vector, get_dev_fcn_regs) void device::register_device( - const discover_t &discover, + const find_t &find, const make_t &make ){ //std::cout << "registering device" << std::endl; - get_dev_fcn_regs().push_back(dev_fcn_reg_t(discover, make)); + get_dev_fcn_regs().push_back(dev_fcn_reg_t(find, make)); } /*********************************************************************** * Discover **********************************************************************/ -device_addrs_t device::discover(const device_addr_t &hint){ +device_addrs_t device::find(const device_addr_t &hint){ device_addrs_t device_addrs; BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()){ diff --git a/host/lib/usrp/usrp1e/usrp1e_none.cpp b/host/lib/usrp/usrp1e/usrp1e_none.cpp index 1c8cf9a5b..84fb9276c 100644 --- a/host/lib/usrp/usrp1e/usrp1e_none.cpp +++ b/host/lib/usrp/usrp1e/usrp1e_none.cpp @@ -25,7 +25,7 @@ using namespace uhd::usrp; * when the required kernel module headers are not present. */ -device_addrs_t usrp1e::discover(const device_addr_t &){ +device_addrs_t usrp1e::find(const device_addr_t &){ return device_addrs_t(); //return empty list } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 9dce351be..b0ee395fb 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -30,13 +30,13 @@ using namespace uhd::transport; namespace asio = boost::asio; UHD_STATIC_BLOCK(register_usrp2_device){ - device::register_device(&usrp2::discover, &usrp2::make); + device::register_device(&usrp2::find, &usrp2::make); } /*********************************************************************** * Discovery over the udp transport **********************************************************************/ -uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ +uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ device_addrs_t usrp2_addrs; //if no address was specified, send a broadcast on each interface @@ -50,7 +50,7 @@ uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ new_hint["addr"] = if_addrs.bcast; //call discover with the new hint and append results - device_addrs_t new_usrp2_addrs = usrp2::discover(new_hint); + device_addrs_t new_usrp2_addrs = usrp2::find(new_hint); usrp2_addrs.insert(usrp2_addrs.begin(), new_usrp2_addrs.begin(), new_usrp2_addrs.end() ); @@ -83,7 +83,6 @@ uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in.data.ip_addr)); device_addr_t new_addr; new_addr["name"] = "USRP2"; - new_addr["transport"] = "udp"; new_addr["addr"] = ip_addr.to_string(); usrp2_addrs.push_back(new_addr); //dont break here, it will exit the while loop diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index 1fb132937..aa01d1e35 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -15,9 +15,9 @@ # along with this program. If not, see . # -ADD_EXECUTABLE(discover_usrps discover_usrps.cpp) -TARGET_LINK_LIBRARIES(discover_usrps uhd) -INSTALL(TARGETS discover_usrps RUNTIME DESTINATION ${RUNTIME_DIR}) +ADD_EXECUTABLE(uhd_find_devices uhd_find_devices.cpp) +TARGET_LINK_LIBRARIES(uhd_find_devices uhd) +INSTALL(TARGETS uhd_find_devices RUNTIME DESTINATION ${RUNTIME_DIR}) ADD_EXECUTABLE(usrp2_burner usrp2_burner.cpp) TARGET_LINK_LIBRARIES(usrp2_burner uhd) diff --git a/host/utils/discover_usrps.cpp b/host/utils/discover_usrps.cpp deleted file mode 100644 index 72c5b8822..000000000 --- a/host/utils/discover_usrps.cpp +++ /dev/null @@ -1,71 +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 . -// - -#include -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int UHD_SAFE_MAIN(int argc, char *argv[]){ - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("addr", po::value(), "resolvable network address") - ("node", po::value(), "path to linux device node") - ; - - 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("Discover USRPs %s") % desc << std::endl; - return ~0; - } - - //load the options into the address - uhd::device_addr_t device_addr; - if (vm.count("addr")){ - device_addr["addr"] = vm["addr"].as(); - } - if (vm.count("node")){ - device_addr["node"] = vm["node"].as(); - } - - //discover the usrps and print the results - uhd::device_addrs_t device_addrs = uhd::device::discover(device_addr); - - if (device_addrs.size() == 0){ - std::cerr << "No USRP Devices Found" << std::endl; - return ~0; - } - - for (size_t i = 0; i < device_addrs.size(); i++){ - std::cout << "--------------------------------------------------" << std::endl; - std::cout << "-- USRP Device " << i << std::endl; - std::cout << "--------------------------------------------------" << std::endl; - std::cout << device_addrs[i].to_string() << std::endl << std::endl; - uhd::device::make(device_addrs[i]); //test make - } - - return 0; -} diff --git a/host/utils/uhd_find_devices.cpp b/host/utils/uhd_find_devices.cpp new file mode 100644 index 000000000..b328216d0 --- /dev/null +++ b/host/utils/uhd_find_devices.cpp @@ -0,0 +1,71 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("addr", po::value(), "resolvable network address") + ("node", po::value(), "path to linux device node") + ; + + 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 Find Devices %s") % desc << std::endl; + return ~0; + } + + //load the options into the address + uhd::device_addr_t device_addr; + if (vm.count("addr")){ + device_addr["addr"] = vm["addr"].as(); + } + if (vm.count("node")){ + device_addr["node"] = vm["node"].as(); + } + + //discover the usrps and print the results + uhd::device_addrs_t device_addrs = uhd::device::find(device_addr); + + if (device_addrs.size() == 0){ + std::cerr << "No UHD Devices Found" << std::endl; + return ~0; + } + + for (size_t i = 0; i < device_addrs.size(); i++){ + std::cout << "--------------------------------------------------" << std::endl; + std::cout << "-- UHD Device " << i << std::endl; + std::cout << "--------------------------------------------------" << std::endl; + std::cout << device_addrs[i].to_string() << std::endl << std::endl; + uhd::device::make(device_addrs[i]); //test make + } + + return 0; +} -- cgit v1.2.3