/* -*- c++ -*- */
/*
- * Copyright 2003 Free Software Foundation, Inc.
- *
+ * Copyright 2003,2009 Free Software Foundation, Inc.
+ *
* This file is part of GNU Radio
- *
+ *
* GNU Radio 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, or (at your option)
* any later version.
- *
+ *
* GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
#include <errno.h>
#include <string.h>
-#define MINIMIZE_TX_BUFFERING true
+#define MINIMIZE_TX_BUFFERING true
-static const int MAX_BLOCK_SIZE = fusb_sysconfig::max_block_size();
+static const int MAX_BLOCK_SIZE = fusb_sysconfig::max_block_size();
static const int DEFAULT_BLOCK_SIZE = MAX_BLOCK_SIZE;
static const int DEFAULT_BUFFER_SIZE = 4 * (1L << 20); // 4 MB endpoint
static const int LIBUSB_TIMEOUT = 0; // no timeout
}
// ------------------------------------------------------------------------
-// libusb_transfer allocation, deallocation, and callback
+// libusb_transfer allocation, deallocation, and callback
// ------------------------------------------------------------------------
static void
if (lut->endpoint & 0x80)
delete [] ((unsigned char *) lut->buffer);
- libusb_free_transfer(lut);
+ libusb_free_transfer(lut);
}
/*
* The callback means the libusb_transfer is completed whether sent, cancelled,
* or failed. Move the libusb_transfer from the pending list to the
- * completed list. If the cancel is from the destructor then free the
+ * completed list. If the cancel is from the destructor then free the
* transfer instead; normally this won't happen since all endpoints should be
* destroyed first leaving the pending list empty.
*/
{
// Fish out devhandle from endpoint
- fusb_devhandle_libusb1* dev_handle =
+ fusb_devhandle_libusb1* dev_handle =
lut_get_ephandle(lut)->get_fusb_devhandle_libusb1();
dev_handle->pending_remove(lut);
free_lut (lut);
return;
}
-
+
lut_get_ephandle(lut)->completed_list_add(lut);
-}
+}
static libusb_transfer*
alloc_lut (fusb_ephandle_libusb1 *self, int buffer_length, int endpoint,
// Load the libusb_transfer for bulk transfer
libusb_fill_bulk_transfer (lut, // transfer
- dev_handle, // dev_handle
+ dev_handle, // dev_handle
endpoint, // endpoint
write_buffer, // buffer
buffer_length, // length
- generic_callback, // callback
+ generic_callback, // callback
self, // user_data
LIBUSB_TIMEOUT); // timeout
libusb_context *ctx)
: fusb_devhandle (udh), d_ctx (ctx), d_teardown (false)
{
- // that's it
+ // that's it
}
fusb_devhandle_libusb1::~fusb_devhandle_libusb1 ()
}
/*
- * devhandle list manipulators
+ * devhandle list manipulators
*/
-void
+void
fusb_devhandle_libusb1::pending_add (libusb_transfer *lut)
{
d_pending_rqsts.push_back (lut);
}
/*
- * Match libusb_tranfer with the pending list and erase
+ * Match libusb_tranfer with the pending list and erase
* Return true if found, false otherwise
*/
}
/*
- * Attempt to cancel any pending libusb_transfer transactions.
+ * Attempt to cancel any pending libusb_transfer transactions.
* Return true in the absence of errors, which does not mean that the transfer
* is cancelled. Cancellation can be checked after the callback is fired off
- * by libusb.
- */
+ * by libusb.
+ */
bool
fusb_devhandle_libusb1::_cancel_lut (libusb_transfer *lut)
tv.tv_sec = 0;
tv.tv_usec = 0;
}
-
+
if ((ret = libusb_handle_events_timeout(d_ctx, &tv)) < 0) {
fprintf (stderr, "fusb::_reap libusb_handle_events() %i\n", ret);
return false;
}
-
+
return true;
}
fusb_devhandle_libusb1::_wait_for_completion ()
{
- while (!d_pending_rqsts.empty ())
- if (!_reap(true))
- break;
+ while (!d_pending_rqsts.empty ())
+ if (!_reap(true))
+ break;
}
fprintf(stderr, "fusb_ephandle_libusb1::ctor: d_block_size = %d d_nblocks = %d\n",
d_block_size, d_nblocks);
- // allocate libusb_transfers
+ // allocate libusb_transfers
for (int i = 0; i < d_nblocks; i++)
d_free_list.push_back (alloc_lut (this, d_block_size, d_endpoint,
d_input_p, d_write_buffer, d_devhandle));
}
/*
- * Cancel all transfers in progress or pending and return to initial state
+ * Cancel all transfers in progress or pending and return to initial state
*/
bool
}
// ------------------------------------------------------------------------
-// routines for writing
+// routines for writing
// ------------------------------------------------------------------------
#if (MINIMIZE_TX_BUFFERING)
{
if (!d_started) // doesn't matter here, but keeps semantics constant
return -1;
-
+
if (d_input_p)
return -1;
n += m;
src += m;
-
+
if (!submit_lut(lut))
return -1;
while ((lut = completed_list_get ()) != 0) {
// Check for any errors or short writes that were reporetd in the transfer.
- // libusb1 sets status, actual_length.
+ // libusb1 sets status, actual_length.
- if (lut->status != LIBUSB_TRANSFER_COMPLETED) {
+ if (lut->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf (stderr, "fusb: (status %d) \n", lut->status );
- }
+ }
else if (lut->actual_length != lut->length){
fprintf (stderr, "fusb: short write xfer: %d != %d\n",
lut->actual_length, lut->length);
}
// ------------------------------------------------------------------------
-// routines for reading
+// routines for reading
// ------------------------------------------------------------------------
int
while (1) {
- while ((lut = completed_list_get ()) == 0 )
+ while ((lut = completed_list_get ()) == 0 )
if (!d_devhandle->_reap(true))
- return false;
+ return false;
if (lut->status != LIBUSB_TRANSFER_COMPLETED) {
- fprintf (stderr, "fust: (rd status %d) %s\n", lut->status,
+ fprintf (stderr, "fust: (rd status %d) %s\n", lut->status,
strerror (-lut->status));
lut->actual_length = 0;
free_list_add (lut);
/*
- * ephandle list manipulation
+ * ephandle list manipulation
*/