diff options
author | Johnathan Corgan <jcorgan@corganenterprises.com> | 2009-08-17 23:46:30 -0400 |
---|---|---|
committer | ttsou <ttsou@vt.edu> | 2009-09-15 18:06:27 -0400 |
commit | b5aa407ec2b1bdebc1c950a9428789fe50327776 (patch) | |
tree | ecbc04220951ee75640cdcc17048d81525f54d0c /usrp/host/lib/usrp_basic.cc | |
parent | 895f2e04a9d962cfe56d416691600b5c619ea180 (diff) |
Applied libusb-1.0 patch set from Thomas Tsou <ttsou@vt.edu>:
This patch set updates the usrp to support libusb-1.0. Asynchronous I/O
through libusb is added with fusb_libusb1.*, which is heavily based on
fusb_linux.*. In short, URB's and ioctl calls are replaced with
libusb_transfer structs and native calls. Transfer reaping is handled by
libusb and associated callbacks. I get 32Mb/s on all of my machines using
test_usrp_standard_rx or tx. Due to the API rewrite in 1.0 from 0.12, there
are alot of changes, many are simply name changes.
Known Issues:
Transmit and receive both work, but not at same time
(e.g. usrp_benchmark_usb.py). libusb does not create any internal threads,
so for a single session fusb_libusb1 works in the same manner as
fusb_linux with the callback called at controlled times. With multiple
libusb sessions the callback may occur at any time and threading issues
come into play causing behavior to become undefined. The use of separate
libusb_contexts _might_ solve this issue; I have not had the time to look
into it.
Diffstat (limited to 'usrp/host/lib/usrp_basic.cc')
-rw-r--r-- | usrp/host/lib/usrp_basic.cc | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/usrp/host/lib/usrp_basic.cc b/usrp/host/lib/usrp_basic.cc index 4f3df5212e..a8b44edabb 100644 --- a/usrp/host/lib/usrp_basic.cc +++ b/usrp/host/lib/usrp_basic.cc @@ -31,7 +31,7 @@ #include "fpga_regs_standard.h" #include "fusb.h" #include "db_boards.h" -#include <usb.h> +#include <libusb-1.0/libusb.h> #include <stdexcept> #include <assert.h> #include <math.h> @@ -55,24 +55,22 @@ static const double POLLING_INTERVAL = 0.1; // seconds //////////////////////////////////////////////////////////////// -static struct usb_dev_handle * -open_rx_interface (struct usb_device *dev) +static struct libusb_device_handle * +open_rx_interface (struct libusb_device *dev) { - struct usb_dev_handle *udh = usrp_open_rx_interface (dev); + struct libusb_device_handle *udh = usrp_open_rx_interface (dev); if (udh == 0){ fprintf (stderr, "usrp_basic_rx: can't open rx interface\n"); - usb_strerror (); } return udh; } -static struct usb_dev_handle * -open_tx_interface (struct usb_device *dev) +static struct libusb_device_handle * +open_tx_interface (struct libusb_device *dev) { - struct usb_dev_handle *udh = usrp_open_tx_interface (dev); + struct libusb_device_handle *udh = usrp_open_tx_interface (dev); if (udh == 0){ fprintf (stderr, "usrp_basic_tx: can't open tx interface\n"); - usb_strerror (); } return udh; } @@ -106,8 +104,8 @@ static unsigned char common_regs[] = { usrp_basic::usrp_basic (int which_board, - struct usb_dev_handle * - open_interface (struct usb_device *dev), + struct libusb_device_handle * + open_interface (struct libusb_device *dev), const std::string fpga_filename, const std::string firmware_filename) : d_udh (0), @@ -132,7 +130,7 @@ usrp_basic::usrp_basic (int which_board, if (!usrp_load_standard_bits (which_board, false, fpga_filename, firmware_filename)) throw std::runtime_error ("usrp_basic/usrp_load_standard_bits"); - struct usb_device *dev = usrp_find_device (which_board); + struct libusb_device *dev = usrp_find_device (which_board); if (dev == 0){ fprintf (stderr, "usrp_basic: can't find usrp[%d]\n", which_board); throw std::runtime_error ("usrp_basic/usrp_find_device"); @@ -175,7 +173,14 @@ usrp_basic::~usrp_basic () d_db.resize(0); // forget db shared ptrs if (d_udh) - usb_close (d_udh); + libusb_close (d_udh); + + // There's no reference count on the number of times libusb is initialized. + // libusb_init can be called multiple times, but libusb_exit shuts down + // everything. Leave libusb running for now. Need to add a count so that it + // exits nicely. + + //libusb_exit (NULL); } void @@ -834,7 +839,6 @@ usrp_basic_rx::~usrp_basic_rx () { if (!set_rx_enable (false)){ fprintf (stderr, "usrp_basic_rx: set_fpga_rx_enable failed\n"); - usb_strerror (); } d_ephandle->stop (); @@ -859,13 +863,11 @@ usrp_basic_rx::start () if (!d_ephandle->start ()){ fprintf (stderr, "usrp_basic_rx: failed to start end point streaming"); - usb_strerror (); return false; } if (!set_rx_enable (true)){ fprintf (stderr, "usrp_basic_rx: set_rx_enable failed\n"); - usb_strerror (); return false; } @@ -879,13 +881,11 @@ usrp_basic_rx::stop () if (!set_rx_enable(false)){ fprintf (stderr, "usrp_basic_rx: set_rx_enable(false) failed\n"); - usb_strerror (); ok = false; } if (!d_ephandle->stop()){ fprintf (stderr, "usrp_basic_rx: failed to stop end point streaming"); - usb_strerror (); ok = false; } @@ -959,7 +959,6 @@ usrp_basic_rx::read (void *buf, int len, bool *overrun) d_bytes_seen = 0; if (!usrp_check_rx_overrun (d_udh, overrun)){ fprintf (stderr, "usrp_basic_rx: usrp_check_rx_overrun failed\n"); - usb_strerror (); } } @@ -1264,13 +1263,11 @@ usrp_basic_tx::start () if (!set_tx_enable (true)){ fprintf (stderr, "usrp_basic_tx: set_tx_enable failed\n"); - usb_strerror (); return false; } if (!d_ephandle->start ()){ fprintf (stderr, "usrp_basic_tx: failed to start end point streaming"); - usb_strerror (); return false; } @@ -1284,13 +1281,11 @@ usrp_basic_tx::stop () if (!d_ephandle->stop ()){ fprintf (stderr, "usrp_basic_tx: failed to stop end point streaming"); - usb_strerror (); ok = false; } if (!set_tx_enable (false)){ fprintf (stderr, "usrp_basic_tx: set_tx_enable(false) failed\n"); - usb_strerror (); ok = false; } @@ -1364,7 +1359,6 @@ usrp_basic_tx::write (const void *buf, int len, bool *underrun) d_bytes_seen = 0; if (!usrp_check_tx_underrun (d_udh, underrun)){ fprintf (stderr, "usrp_basic_tx: usrp_check_tx_underrun failed\n"); - usb_strerror (); } } |