summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-08-27 16:59:24 -0700
committerJosh Blum <josh@joshknows.com>2010-08-27 16:59:24 -0700
commit39629ec4aa1b8409b0c5470ebe51d92589b5957e (patch)
tree79c2c7e3a7c1d05da112af9a18f683d0c07cf987
parentaa2ef7d246e93f4e6c0cb8b9b985a487cd2ea548 (diff)
parentec8005e3d5d1a80f89f5cfbaa8e1cdadf2d14db6 (diff)
downloaduhd-39629ec4aa1b8409b0c5470ebe51d92589b5957e.tar.gz
uhd-39629ec4aa1b8409b0c5470ebe51d92589b5957e.tar.bz2
uhd-39629ec4aa1b8409b0c5470ebe51d92589b5957e.zip
Merge branch 'usrp1' of ettus.sourcerepo.com:ettus/uhdpriv into usrp1
-rw-r--r--host/lib/transport/libusb1_base.cpp50
-rw-r--r--host/lib/transport/libusb1_base.hpp2
-rw-r--r--host/lib/transport/libusb1_control.cpp2
-rw-r--r--host/lib/transport/libusb1_device_handle.cpp33
-rw-r--r--host/lib/transport/libusb1_zero_copy.cpp25
-rw-r--r--host/lib/usrp/usrp1/usrp1_ctrl.cpp4
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.cpp3
7 files changed, 76 insertions, 43 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;
};
diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.cpp b/host/lib/usrp/usrp1/usrp1_ctrl.cpp
index b7c6bdaf6..98226b738 100644
--- a/host/lib/usrp/usrp1/usrp1_ctrl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_ctrl.cpp
@@ -19,6 +19,7 @@
#include "usrp_commands.h"
#include <uhd/transport/usb_control.hpp>
#include <boost/functional/hash.hpp>
+#include <boost/thread/thread.hpp>
#include <iostream>
#include <fstream>
#include <sstream>
@@ -209,6 +210,9 @@ public:
usrp_set_firmware_hash(hash);
file.close();
+ //wait for things to settle
+ boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
+
return USRP_FIRMWARE_LOAD_SUCCESS;
}
//type anything else is unhandled
diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp
index d37eec566..3c3306525 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.cpp
@@ -69,9 +69,6 @@ static device_addrs_t usrp1_find(const device_addr_t &hint)
}
}
- //wait for things to settle
- boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
-
//get descriptors again with serial number
device_list = usb_device_handle::get_device_list();