diff options
author | Josh Blum <josh@joshknows.com> | 2010-08-27 16:59:24 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-08-27 16:59:24 -0700 |
commit | 39629ec4aa1b8409b0c5470ebe51d92589b5957e (patch) | |
tree | 79c2c7e3a7c1d05da112af9a18f683d0c07cf987 /host/lib/transport | |
parent | aa2ef7d246e93f4e6c0cb8b9b985a487cd2ea548 (diff) | |
parent | ec8005e3d5d1a80f89f5cfbaa8e1cdadf2d14db6 (diff) | |
download | uhd-39629ec4aa1b8409b0c5470ebe51d92589b5957e.tar.gz uhd-39629ec4aa1b8409b0c5470ebe51d92589b5957e.tar.bz2 uhd-39629ec4aa1b8409b0c5470ebe51d92589b5957e.zip |
Merge branch 'usrp1' of ettus.sourcerepo.com:ettus/uhdpriv into usrp1
Diffstat (limited to 'host/lib/transport')
-rw-r--r-- | host/lib/transport/libusb1_base.cpp | 50 | ||||
-rw-r--r-- | host/lib/transport/libusb1_base.hpp | 2 | ||||
-rw-r--r-- | host/lib/transport/libusb1_control.cpp | 2 | ||||
-rw-r--r-- | host/lib/transport/libusb1_device_handle.cpp | 33 | ||||
-rw-r--r-- | host/lib/transport/libusb1_zero_copy.cpp | 25 |
5 files changed, 72 insertions, 40 deletions
diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp index 6965de214..493d4eff3 100644 --- a/host/lib/transport/libusb1_base.cpp +++ b/host/lib/transport/libusb1_base.cpp @@ -16,10 +16,22 @@ // #include "libusb1_base.hpp" +#include <uhd/utils/assert.hpp> #include <iostream> using namespace uhd::transport; +bool check_fsf_device(libusb_device *dev) +{ + libusb_device_descriptor desc; + + if (libusb_get_device_descriptor(dev, &desc) < 0) { + UHD_ASSERT_THROW("USB: failed to get device descriptor"); + } + + return desc.idVendor == 0xfffe; +} + void libusb::init(libusb_context **ctx, int debug_level) { if (libusb_init(ctx) < 0) @@ -28,27 +40,47 @@ void libusb::init(libusb_context **ctx, int debug_level) libusb_set_debug(*ctx, debug_level); } +std::vector<libusb_device *> libusb::get_fsf_device_list(libusb_context *ctx) +{ + libusb_device **libusb_dev_list; + std::vector<libusb_device *> fsf_dev_list; + + ssize_t dev_cnt = libusb_get_device_list(ctx, &libusb_dev_list); + + //find the FSF devices + for (ssize_t i = 0; i < dev_cnt; i++) { + libusb_device *dev = libusb_dev_list[i]; + + if (check_fsf_device(dev)) + fsf_dev_list.push_back(dev); + else + libusb_unref_device(dev); + } + + libusb_free_device_list(libusb_dev_list, 0); + + return fsf_dev_list; +} libusb_device_handle *libusb::open_device(libusb_context *ctx, usb_device_handle::sptr handle) { - libusb_device **dev_list; - libusb_device_handle *dev_handle; + libusb_device_handle *dev_handle = NULL; + std::vector<libusb_device *> fsf_dev_list = get_fsf_device_list(ctx); - ssize_t dev_cnt = libusb_get_device_list(ctx, &dev_list); - - //find and open the receive device - for (ssize_t i = 0; i < dev_cnt; i++) { - libusb_device *dev = dev_list[i]; + //find and open the USB device + for (size_t i = 0; i < fsf_dev_list.size(); i++) { + libusb_device *dev = fsf_dev_list[i]; if (compare_device(dev, handle)) { libusb_open(dev, &dev_handle); + libusb_unref_device(dev); break; } + + libusb_unref_device(dev); } - libusb_free_device_list(dev_list, 0); - return dev_handle; } diff --git a/host/lib/transport/libusb1_base.hpp b/host/lib/transport/libusb1_base.hpp index ae560cd52..708a42c73 100644 --- a/host/lib/transport/libusb1_base.hpp +++ b/host/lib/transport/libusb1_base.hpp @@ -27,6 +27,8 @@ namespace uhd { namespace transport { namespace libusb { void init(libusb_context **ctx, int debug_level); + std::vector<libusb_device *> get_fsf_device_list(libusb_context *ctx); + libusb_device_handle *open_device(libusb_context *ctx, usb_device_handle::sptr handle); diff --git a/host/lib/transport/libusb1_control.cpp b/host/lib/transport/libusb1_control.cpp index 8bf271256..4b827c350 100644 --- a/host/lib/transport/libusb1_control.cpp +++ b/host/lib/transport/libusb1_control.cpp @@ -20,7 +20,7 @@ using namespace uhd::transport; -const int libusb_debug_level = 3; +const int libusb_debug_level = 0; const int libusb_timeout = 0; /*********************************************************************** diff --git a/host/lib/transport/libusb1_device_handle.cpp b/host/lib/transport/libusb1_device_handle.cpp index 5289f668f..3476fdc4e 100644 --- a/host/lib/transport/libusb1_device_handle.cpp +++ b/host/lib/transport/libusb1_device_handle.cpp @@ -20,7 +20,7 @@ using namespace uhd::transport; -const int libusb_debug_level = 3; +const int libusb_debug_level = 0; class libusb1_device_handle_impl : public usb_device_handle { public: @@ -88,38 +88,21 @@ usb_device_handle::sptr make_usb_device_handle(libusb_device *dev) device_addr)); } -bool check_fsf_device(libusb_device *dev) -{ - libusb_device_descriptor desc; - - if (libusb_get_device_descriptor(dev, &desc) < 0) { - UHD_ASSERT_THROW("USB: failed to get device descriptor"); - } - - return desc.idVendor == 0xfffe; -} - std::vector<usb_device_handle::sptr> usb_device_handle::get_device_list() { libusb_context *ctx = NULL; - libusb_device **list; - std::vector<usb_device_handle::sptr> device_list; + std::vector<libusb_device *> libusb_device_list; + std::vector<usb_device_handle::sptr> device_handle_list; libusb::init(&ctx, libusb_debug_level); - ssize_t cnt = libusb_get_device_list(ctx, &list); - - if (cnt < 0) - throw std::runtime_error("USB: enumeration failed"); + libusb_device_list = libusb::get_fsf_device_list(ctx); - ssize_t i = 0; - for (i = 0; i < cnt; i++) { - libusb_device *dev = list[i]; - if (check_fsf_device(dev)) - device_list.push_back(make_usb_device_handle(dev)); + for (size_t i = 0; i < libusb_device_list.size(); i++) { + libusb_device *dev = libusb_device_list[i]; + device_handle_list.push_back(make_usb_device_handle(dev)); } - libusb_free_device_list(list, 0); libusb_exit(ctx); - return device_list; + return device_handle_list; } diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 55aa10cbb..4469991b8 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -25,7 +25,7 @@ using namespace uhd::transport; -const int libusb_debug_level = 3; +const int libusb_debug_level = 0; const int libusb_timeout = 0; /*********************************************************************** @@ -555,7 +555,7 @@ public: libusb_managed_send_buffer_impl(libusb_transfer *lut, usb_endpoint *endpoint, size_t buff_size) - : _buff(lut->buffer, buff_size) + : _buff(lut->buffer, buff_size), _committed(false) { _lut = lut; _endpoint = endpoint; @@ -563,18 +563,32 @@ public: ~libusb_managed_send_buffer_impl() { - /* NOP */ + if (!_committed) { + _lut->length = 0; + _lut->actual_length = 0; + _endpoint->submit(_lut); + } } ssize_t commit(size_t num_bytes) { + if (_committed) { + std::cerr << "UHD: send buffer already committed" << std::endl; + return 0; + } + + UHD_ASSERT_THROW(num_bytes <= boost::asio::buffer_size(_buff)); + _lut->length = num_bytes; _lut->actual_length = 0; - if (_endpoint->submit(_lut)) + if (_endpoint->submit(_lut)) { + _committed = true; return num_bytes; - else + } + else { return 0; + } } private: @@ -586,6 +600,7 @@ private: libusb_transfer *_lut; usb_endpoint *_endpoint; const boost::asio::mutable_buffer _buff; + bool _committed; }; |