diff options
Diffstat (limited to 'usrp')
-rw-r--r-- | usrp/host/lib/circular_buffer.h | 83 | ||||
-rw-r--r-- | usrp/host/lib/circular_linked_list.h | 34 | ||||
-rw-r--r-- | usrp/host/lib/darwin_libusb.h | 171 | ||||
-rw-r--r-- | usrp/host/lib/fusb_darwin.cc | 177 | ||||
-rw-r--r-- | usrp/host/lib/fusb_darwin.h | 20 | ||||
-rw-r--r-- | usrp/host/lib/usrp_prims_libusb0.cc | 1 | ||||
-rw-r--r-- | usrp/usrp.pc.in | 2 |
7 files changed, 273 insertions, 215 deletions
diff --git a/usrp/host/lib/circular_buffer.h b/usrp/host/lib/circular_buffer.h index 8898e4194..6d491fb6f 100644 --- a/usrp/host/lib/circular_buffer.h +++ b/usrp/host/lib/circular_buffer.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -24,6 +24,7 @@ #define _CIRCULAR_BUFFER_H_ #include "mld_threads.h" +#include <iostream> #include <stdexcept> #ifndef DO_DEBUG @@ -43,8 +44,8 @@ private: T* d_buffer; // the following are in Items (type T) - UInt32 d_bufLen_I, d_readNdx_I, d_writeNdx_I; - UInt32 d_n_avail_write_I, d_n_avail_read_I; + size_t d_bufLen_I, d_readNdx_I, d_writeNdx_I; + size_t d_n_avail_write_I, d_n_avail_read_I; // stuff to control access to class internals mld_mutex_ptr d_internal; @@ -69,7 +70,7 @@ private: }; public: - circular_buffer (UInt32 bufLen_I, + circular_buffer (size_t bufLen_I, bool doWriteBlock = true, bool doFullRead = false) { if (bufLen_I == 0) throw std::runtime_error ("circular_buffer(): " @@ -81,10 +82,10 @@ public: d_internal = NULL; d_readBlock = d_writeBlock = NULL; reset (); - DEBUG (fprintf (stderr, "c_b(): buf len (items) = %ld, " - "doWriteBlock = %s, doFullRead = %s\n", d_bufLen_I, - (d_doWriteBlock ? "true" : "false"), - (d_doFullRead ? "true" : "false"));); + DEBUG (std::cerr << "c_b(): buf len (items) = " << d_bufLen_ + << ", doWriteBlock = " << (d_doWriteBlock ? "true" : "false") + << ", doFullRead = " << (d_doFullRead ? "true" : "false") + << std::endl); }; ~circular_buffer () { @@ -92,21 +93,21 @@ public: delete [] d_buffer; }; - inline UInt32 n_avail_write_items () { + inline size_t n_avail_write_items () { d_internal->lock (); - UInt32 retVal = d_n_avail_write_I; + size_t retVal = d_n_avail_write_I; d_internal->unlock (); return (retVal); }; - inline UInt32 n_avail_read_items () { + inline size_t n_avail_read_items () { d_internal->lock (); - UInt32 retVal = d_n_avail_read_I; + size_t retVal = d_n_avail_read_I; d_internal->unlock (); return (retVal); }; - inline UInt32 buffer_length_items () {return (d_bufLen_I);}; + inline size_t buffer_length_items () {return (d_bufLen_I);}; inline bool do_write_block () {return (d_doWriteBlock);}; inline bool do_full_read () {return (d_doFullRead);}; @@ -149,14 +150,15 @@ public: * buffer length is larger than the instantiated buffer length */ - int enqueue (T* buf, UInt32 bufLen_I) { - DEBUG (fprintf (stderr, "enqueue: buf = %X, bufLen = %ld, #av_wr = %ld, " - "#av_rd = %ld.\n", (unsigned int)buf, bufLen_I, - d_n_avail_write_I, d_n_avail_read_I);); + int enqueue (T* buf, size_t bufLen_I) { + DEBUG (std::cerr << "enqueue: buf = " << (void*) buf + << ", bufLen = " << bufLen_I + << ", #av_wr = " << d_n_avail_write_I + << ", #av_rd = " << d_n_avail_read_I << std::endl); if (bufLen_I > d_bufLen_I) { - fprintf (stderr, "cannot add buffer longer (%ld" - ") than instantiated length (%ld" - ").\n", bufLen_I, d_bufLen_I); + std::cerr << "ERROR: cannot add buffer longer (" + << bufLen_I << ") than instantiated length (" + << d_bufLen_I << ")." << std::endl; throw std::runtime_error ("circular_buffer::enqueue()"); } @@ -175,25 +177,25 @@ public: if (bufLen_I > d_n_avail_write_I) { if (d_doWriteBlock) { while (bufLen_I > d_n_avail_write_I) { - DEBUG (fprintf (stderr, "enqueue: #len > #a, waiting.\n");); + DEBUG (std::cerr << "enqueue: #len > #a, waiting." << std::endl); // wait will automatically unlock() the internal mutex d_writeBlock->wait (); // and lock() it here. if (d_doAbort) { d_internal->unlock (); - DEBUG (fprintf (stderr, "enqueue: #len > #a, aborting.\n");); + DEBUG (std::cerr << "enqueue: #len > #a, aborting." << std::endl); return (2); } - DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n");); + DEBUG (std::cerr << "enqueue: #len > #a, done waiting." << std::endl); } } else { d_n_avail_read_I = d_bufLen_I - bufLen_I; d_n_avail_write_I = bufLen_I; - DEBUG (fprintf (stderr, "circular_buffer::enqueue: overflow\n");); + DEBUG (std::cerr << "circular_buffer::enqueue: overflow" << std::endl); retval = -1; } } - UInt32 n_now_I = d_bufLen_I - d_writeNdx_I, n_start_I = 0; + size_t n_now_I = d_bufLen_I - d_writeNdx_I, n_start_I = 0; if (n_now_I > bufLen_I) n_now_I = bufLen_I; else if (n_now_I < bufLen_I) @@ -232,23 +234,24 @@ public: * buffer length is larger than the instantiated buffer length */ - int dequeue (T* buf, UInt32* bufLen_I) { - DEBUG (fprintf (stderr, "dequeue: buf = %X, *bufLen = %ld, #av_wr = %ld, " - "#av_rd = %ld.\n", (unsigned int)buf, *bufLen_I, - d_n_avail_write_I, d_n_avail_read_I);); + int dequeue (T* buf, size_t* bufLen_I) { + DEBUG (std::cerr << "dequeue: buf = " << ((void*) buf) + << ", *bufLen = " << (*bufLen_I) + << ", #av_wr = " << d_n_avail_write_I + << ", #av_rd = " << d_n_avail_read_I << std::endl); if (!bufLen_I) throw std::runtime_error ("circular_buffer::dequeue(): " "input bufLen pointer is NULL.\n"); if (!buf) throw std::runtime_error ("circular_buffer::dequeue(): " "input buffer pointer is NULL.\n"); - UInt32 l_bufLen_I = *bufLen_I; + size_t l_bufLen_I = *bufLen_I; if (l_bufLen_I == 0) return (0); if (l_bufLen_I > d_bufLen_I) { - fprintf (stderr, "cannot remove buffer longer (%ld" - ") than instantiated length (%ld" - ").\n", l_bufLen_I, d_bufLen_I); + std::cerr << "ERROR: cannot remove buffer longer (" + << l_bufLen_I << ") than instantiated length (" + << d_bufLen_I << ")." << std::endl; throw std::runtime_error ("circular_buffer::dequeue()"); } @@ -259,34 +262,34 @@ public: } if (d_doFullRead) { while (d_n_avail_read_I < l_bufLen_I) { - DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n");); + DEBUG (std::cerr << "dequeue: #a < #len, waiting." << std::endl); // wait will automatically unlock() the internal mutex d_readBlock->wait (); // and lock() it here. if (d_doAbort) { d_internal->unlock (); - DEBUG (fprintf (stderr, "dequeue: #a < #len, aborting.\n");); + DEBUG (std::cerr << "dequeue: #a < #len, aborting." << std::endl); return (2); } - DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n");); + DEBUG (std::cerr << "dequeue: #a < #len, done waiting." << std::endl); } } else { while (d_n_avail_read_I == 0) { - DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n");); + DEBUG (std::cerr << "dequeue: #a == 0, waiting." << std::endl); // wait will automatically unlock() the internal mutex d_readBlock->wait (); // and lock() it here. if (d_doAbort) { d_internal->unlock (); - DEBUG (fprintf (stderr, "dequeue: #a == 0, aborting.\n");); + DEBUG (std::cerr << "dequeue: #a == 0, aborting." << std::endl); return (2); } - DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n");); + DEBUG (std::cerr << "dequeue: #a == 0, done waiting." << std::endl); } } if (l_bufLen_I > d_n_avail_read_I) l_bufLen_I = d_n_avail_read_I; - UInt32 n_now_I = d_bufLen_I - d_readNdx_I, n_start_I = 0; + size_t n_now_I = d_bufLen_I - d_readNdx_I, n_start_I = 0; if (n_now_I > l_bufLen_I) n_now_I = l_bufLen_I; else if (n_now_I < l_bufLen_I) diff --git a/usrp/host/lib/circular_linked_list.h b/usrp/host/lib/circular_linked_list.h index e495d609b..97fe2c1a8 100644 --- a/usrp/host/lib/circular_linked_list.h +++ b/usrp/host/lib/circular_linked_list.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -109,12 +109,12 @@ template <class T> class circular_linked_list { private: s_node_ptr d_current, d_iterate, d_available, d_inUse; - UInt32 d_n_nodes, d_n_used; + size_t d_n_nodes, d_n_used; mld_mutex_ptr d_internal; mld_condition_ptr d_ioBlock; public: - circular_linked_list (UInt32 n_nodes) { + circular_linked_list (size_t n_nodes) { if (n_nodes == 0) throw std::runtime_error ("circular_linked_list(): n_nodes == 0"); @@ -136,7 +136,7 @@ public: l_prev->next (l_next); l_prev->prev (l_next); if (n_nodes > 2) { - UInt32 n = n_nodes - 2; + size_t n = n_nodes - 2; while (n-- > 0) { d_current = new s_node<T> (l_prev, l_next); d_current->set_available (); @@ -171,17 +171,17 @@ public: d_internal->lock (); // find an available node s_node_ptr l_node = d_available; - DEBUG (fprintf (stderr, "w ");); + DEBUG (std::cerr << "w "); while (! l_node) { - DEBUG (fprintf (stderr, "x\n");); + DEBUG (std::cerr << "x" << std::endl); // the ioBlock condition will automatically unlock() d_internal d_ioBlock->wait (); // and lock() is here - DEBUG (fprintf (stderr, "y\n");); + DEBUG (std::cerr << "y" << std::endl); l_node = d_available; } - DEBUG (fprintf (stderr, "::f_n_a_n: #u = %ld, node = %p\n", - num_used(), l_node);); + DEBUG (std::cerr << "::f_n_a_n: #u = " << num_used() + << ", node = " << l_node << std::endl); // remove this one from the current available list if (num_available () == 1) { // last one, just set available to NULL @@ -203,8 +203,8 @@ public: void make_node_available (s_node_ptr l_node) { if (!l_node) return; d_internal->lock (); - DEBUG (fprintf (stderr, "::m_n_a: #u = %ld, node = %p\n", - num_used(), l_node);); + DEBUG (std::cerr << "::m_n_a: #u = " << num_used() + << ", node = " << l_node << std::endl); // remove this node from the inUse list if (num_used () == 1) { // last one, just set inUse to NULL @@ -219,10 +219,10 @@ public: l_node->insert_before (d_available); d_n_used--; - DEBUG (fprintf (stderr, "s%ld ", d_n_used);); + DEBUG (std::cerr << "s" << d_n_used); // signal the condition when new data arrives d_ioBlock->signal (); - DEBUG (fprintf (stderr, "t ");); + DEBUG (std::cerr << "t "); // unlock the mutex for thread safety d_internal->unlock (); @@ -251,10 +251,10 @@ public: __INLINE__ T object () { return (d_current->d_object); }; __INLINE__ void object (T l_object) { d_current->d_object = l_object; }; - __INLINE__ UInt32 num_nodes () { return (d_n_nodes); }; - __INLINE__ UInt32 num_used () { return (d_n_used); }; - __INLINE__ void num_used (UInt32 l_n_used) { d_n_used = l_n_used; }; - __INLINE__ UInt32 num_available () { return (d_n_nodes - d_n_used); }; + __INLINE__ size_t num_nodes () { return (d_n_nodes); }; + __INLINE__ size_t num_used () { return (d_n_used); }; + __INLINE__ void num_used (size_t l_n_used) { d_n_used = l_n_used; }; + __INLINE__ size_t num_available () { return (d_n_nodes - d_n_used); }; __INLINE__ void num_used_inc (void) { if (d_n_used < d_n_nodes) ++d_n_used; }; diff --git a/usrp/host/lib/darwin_libusb.h b/usrp/host/lib/darwin_libusb.h index 063a2e9c6..8446f044e 100644 --- a/usrp/host/lib/darwin_libusb.h +++ b/usrp/host/lib/darwin_libusb.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -42,28 +42,41 @@ #include <IOKit/IOKitLib.h> extern "C" { -static char * + +static const char* darwin_error_strings[] = { + "no error", + "device not opened for exclusive access", + "no connection to an IOService", + "no asyc port has been opened for interface", + "another process has device opened for exclusive access", + "pipe is stalled", + "could not establish a connection to Darin kernel", + "invalid argument", + "unknown error" +}; + +static const char * darwin_error_str (int result) { switch (result) { case kIOReturnSuccess: - return "no error"; + return (darwin_error_strings[0]); case kIOReturnNotOpen: - return "device not opened for exclusive access"; + return (darwin_error_strings[1]); case kIOReturnNoDevice: - return "no connection to an IOService"; + return (darwin_error_strings[2]); case kIOUSBNoAsyncPortErr: - return "no asyc port has been opened for interface"; + return (darwin_error_strings[3]); case kIOReturnExclusiveAccess: - return "another process has device opened for exclusive access"; + return (darwin_error_strings[4]); case kIOUSBPipeStalled: - return "pipe is stalled"; + return (darwin_error_strings[5]); case kIOReturnError: - return "could not establish a connection to Darin kernel"; + return (darwin_error_strings[6]); case kIOReturnBadArgument: - return "invalid argument"; + return (darwin_error_strings[7]); default: - return "unknown error"; + return (darwin_error_strings[8]); } } @@ -103,40 +116,49 @@ extern char usb_error_str[1024]; extern int usb_error_errno; extern usb_error_type_t usb_error_type; -#define USB_ERROR(r, x) \ - do { \ - usb_error_type = USB_ERROR_TYPE_ERRNO; \ - usb_error_errno = x; \ - return r; \ - } while (0) - -#define USB_ERROR_STR(r, x, format, args...) \ - do { \ - usb_error_type = USB_ERROR_TYPE_STRING; \ - snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \ - if (usb_debug) \ - fprintf(stderr, "USB error: %s\n", usb_error_str); \ - return r; \ - } while (0) - -#define USB_ERROR_STR_ORIG(x, format, args...) \ - do { \ - usb_error_type = USB_ERROR_TYPE_STRING; \ - snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \ - if (usb_debug) \ - fprintf(stderr, "USB error: %s\n", usb_error_str); \ - return x; \ - } while (0) - -#define USB_ERROR_STR_NO_RET(x, format, args...) \ - do { \ - usb_error_type = USB_ERROR_TYPE_STRING; \ - snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \ - if (usb_debug) \ - fprintf(stderr, "USB error: %s\n", usb_error_str); \ - } while (0) - -/* simple function that figures out what pipeRef is associated with an endpoint */ +#define USB_ERROR(r, x) \ + do { \ + usb_error_type = USB_ERROR_TYPE_ERRNO; \ + usb_error_errno = x; \ + return (r); \ + } while (0) + +#define USB_ERROR_STR(r, x, format, args...) \ + do { \ + usb_error_type = USB_ERROR_TYPE_STRING; \ + snprintf (usb_error_str, sizeof (usb_error_str) - 1, \ + format, ## args); \ + if (usb_debug) { \ + std::cerr << "USB error: " << usb_error_str << std::cerr; \ + } \ + return (r); \ + } while (0) + +#define USB_ERROR_STR_ORIG(x, format, args...) \ + do { \ + usb_error_type = USB_ERROR_TYPE_STRING; \ + snprintf (usb_error_str, sizeof (usb_error_str) - 1, \ + format, ## args); \ + if (usb_debug) { \ + std::cerr << "USB error: " << usb_error_str << std::endl; \ + } \ + return (x); \ + } while (0) + +#define USB_ERROR_STR_NO_RET(x, format, args...) \ + do { \ + usb_error_type = USB_ERROR_TYPE_STRING; \ + snprintf (usb_error_str, sizeof (usb_error_str) - 1, \ + format, ## args); \ + if (usb_debug) { \ + std::cerr << "USB error: " << usb_error_str << std::endl; \ + } \ + } while (0) + +/* + * simple function that figures out what pipeRef + * is associated with an endpoint + */ static int ep_to_pipeRef (darwin_dev_handle *device, int ep) { io_return_t ret; @@ -145,45 +167,60 @@ static int ep_to_pipeRef (darwin_dev_handle *device, int ep) UInt16 dont_care2; int i; - if (usb_debug > 3) - fprintf(stderr, "Converting ep address to pipeRef.\n"); + if (usb_debug > 3) { + std::cerr << "Converting ep address to pipeRef." << std::endl; + } /* retrieve the total number of endpoints on this interface */ ret = (*(device->interface))->GetNumEndpoints(device->interface, &numep); if ( ret ) { - if ( usb_debug > 3 ) - fprintf ( stderr, "ep_to_pipeRef: interface is %p\n", device->interface ); - USB_ERROR_STR_ORIG ( -ret, "ep_to_pipeRef: can't get number of endpoints for interface" ); + if ( usb_debug > 3 ) { + std::cerr << "ep_to_pipeRef: interface is " + << device->interface << std::endl; + } + USB_ERROR_STR_ORIG ( -ret, "ep_to_pipeRef: can't get number of " + "endpoints for interface" ); } /* iterate through the pipeRefs until we find the correct one */ for (i = 1 ; i <= numep ; i++) { - ret = (*(device->interface))->GetPipeProperties(device->interface, i, &direction, &number, - &dont_care1, &dont_care2, &dont_care3); + ret = (*(device->interface))->GetPipeProperties + (device->interface, i, &direction, &number, + &dont_care1, &dont_care2, &dont_care3); if (ret != kIOReturnSuccess) { - fprintf (stderr, "ep_to_pipeRef: an error occurred getting pipe information on pipe %d\n", - i ); - USB_ERROR_STR_ORIG (-darwin_to_errno(ret), "ep_to_pipeRef(GetPipeProperties): %s", darwin_error_str(ret)); - } + std::cerr << "ep_to_pipeRef: an error occurred getting " + << "pipe information on pipe " << i << std::endl; - if (usb_debug > 3) - fprintf (stderr, "ep_to_pipeRef: Pipe %i: DIR: %i number: %i\n", i, direction, number); + USB_ERROR_STR_ORIG (-darwin_to_errno(ret), + "ep_to_pipeRef(GetPipeProperties): %s", + darwin_error_str(ret)); + } - /* calculate the endpoint of the pipe and check it versus the requested endpoint */ - if ( ((direction << 7 & USB_ENDPOINT_DIR_MASK) | (number & USB_ENDPOINT_ADDRESS_MASK)) == ep ) { - if (usb_debug > 3) - fprintf(stderr, "ep_to_pipeRef: pipeRef for ep address 0x%02x found: 0x%02x\n", ep, i); + if (usb_debug > 3) { + std::cerr << "ep_to_pipeRef: Pipe " << i << ": DIR: " + << direction << " number: " << number << std::endl; + } - return i; + /* calculate the endpoint of the pipe and check it versus + the requested endpoint */ + if ( ((direction << 7 & USB_ENDPOINT_DIR_MASK) | + (number & USB_ENDPOINT_ADDRESS_MASK)) == ep ) { + if (usb_debug > 3) { + std::cerr << "ep_to_pipeRef: pipeRef for ep address " + << ep << " found: " << i << std::endl; + } + return (i); } } - if (usb_debug > 3) - fprintf(stderr, "ep_to_pipeRef: No pipeRef found with endpoint address 0x%02x.\n", ep); - + if (usb_debug > 3) { + std::cerr << "ep_to_pipeRef: No pipeRef found with endpoint address " + << ep << std::endl; + } + /* none of the found pipes match the requested endpoint */ - return -1; + return (-1); } } diff --git a/usrp/host/lib/fusb_darwin.cc b/usrp/host/lib/fusb_darwin.cc index 737387b87..95c4878aa 100644 --- a/usrp/host/lib/fusb_darwin.cc +++ b/usrp/host/lib/fusb_darwin.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -33,6 +33,7 @@ #include "fusb.h" #include "fusb_darwin.h" #include "darwin_libusb.h" +#include <iostream> static const int USB_TIMEOUT = 100; // in milliseconds static const UInt8 NUM_QUEUE_ITEMS = 20; @@ -153,9 +154,10 @@ fusb_ephandle_darwin::start () USB_ERROR_STR (false, -ENOENT, "fusb_ephandle_darwin::start: " "device not initialized"); - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::start: " - "dev = %p, device = %p\n", dev, device); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::start: dev = " << + (void*) dev << ", device = " << (void*) device << std::endl; + } d_interfaceRef = device->interface; if (! d_interfaceRef) @@ -165,10 +167,10 @@ fusb_ephandle_darwin::start () // get read or write pipe info (depends on "d_input_p") - if (usb_debug > 3) - fprintf (stderr, "fusb_ephandle_darwin::start " - "d_endpoint = %d, d_input_p = %s\n", - d_endpoint, d_input_p ? "TRUE" : "FALSE"); + if (usb_debug > 3) { + std::cerr << "fusb_ephandle_darwin::start d_endpoint = " << d_endpoint + << ", d_input_p = " << (d_input_p ? "TRUE" : "FALSE") << std::endl; + } int l_endpoint = (d_input_p ? USB_ENDPOINT_IN : USB_ENDPOINT_OUT); int pipeRef = ep_to_pipeRef (device, d_endpoint | l_endpoint); @@ -184,12 +186,14 @@ fusb_ephandle_darwin::start () &d_transferType, &maxPacketSize, &interval); - if (usb_debug == 3) - fprintf (stderr, "fusb_ephandle_darwin::start: %s: ep = 0x%02x, " - "pipeRef = %d, d_i = %p, d_iR = %p, if_dir = %d, if_# = %d, " - "if_int = %d, if_maxPS = %d\n", d_input_p ? "read" : "write", - d_endpoint, d_pipeRef, d_interface, d_interfaceRef, direction, - number, interval, maxPacketSize); + if (usb_debug == 3) { + std::cerr << "fusb_ephandle_darwin::start: " << (d_input_p ? "read" : "write") + << ": ep = " << d_endpoint << ", pipeRef = " << d_pipeRef << "interface = " + << d_interface << ", interfaceRef = " << d_interfaceRef + << ", if_direction = " << direction << ", if_# = " << number + << ", if_interval = " << interval << ", if_maxPacketSize = " + << maxPacketSize << std::endl; + } // set global start boolean d_started = true; @@ -205,9 +209,10 @@ fusb_ephandle_darwin::start () // going; this will unlock the mutex before waiting for a signal () d_runBlock->wait (); - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::start: %s started.\n", - d_input_p ? "read" : "write"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::start: " << (d_input_p ? "read" : "write") + << " started." << std::endl; + } return (true); } @@ -229,10 +234,10 @@ fusb_ephandle_darwin::run_thread (void* arg) bool l_input_p = This->d_input_p; - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::run_thread: " - "starting for %s.\n", - l_input_p ? "read" : "write"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::run_thread: starting for " + << (l_input_p ? "read" : "write") << "." << std::endl; + } usb_interface_t** l_interfaceRef = This->d_interfaceRef; usb_interface_t* l_interface = This->d_interface; @@ -286,9 +291,10 @@ fusb_ephandle_darwin::run_thread (void* arg) CFRunLoopRemoveSource (CFRunLoopGetCurrent (), l_cfSource, kCFRunLoopDefaultMode); - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::run_thread: finished for %s.\n", - l_input_p ? "read" : "write"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::run_thread: finished for " + << (l_input_p ? "read" : "write") << "." << std::endl; + } // release the run thread running mutex l_runThreadRunning->unlock (); @@ -297,8 +303,9 @@ fusb_ephandle_darwin::run_thread (void* arg) void fusb_ephandle_darwin::read_thread (void* arg) { - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::read_thread: starting.\n"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::read_thread: starting." << std::endl; + } fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(arg); @@ -331,8 +338,9 @@ fusb_ephandle_darwin::read_thread (void* arg) l_node = l_queue->iterate_next (); } - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::read_thread: finished.\n"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::read_thread: finished." << std::endl; + } // release the read running mutex, to let the parent thread knows // that this thread is finished @@ -343,10 +351,11 @@ void fusb_ephandle_darwin::read_issue (s_both_ptr l_both) { if ((! l_both) || (! d_started)) { - if (usb_debug > 4) - fprintf (stderr, "fusb_ephandle_darwin::read_issue: Doing nothing; " - "l_both is %X; started is %s\n", (unsigned int) l_both, - d_started ? "TRUE" : "FALSE"); + if (usb_debug > 4) { + std::cerr << "fusb_ephandle_darwin::read_issue: Doing nothing; " + << "l_both is " << (void*) l_both << "; started is " + << (d_started ? "TRUE" : "FALSE") << std::endl; + } return; } @@ -356,7 +365,7 @@ fusb_ephandle_darwin::read_issue (s_both_ptr l_both) void* v_buffer = (void*) l_buf->buffer (); // read up to d_bufLenBytes - UInt32 bufLen = d_bufLenBytes; + size_t bufLen = d_bufLenBytes; l_buf->n_used (bufLen); // setup system call result @@ -378,9 +387,10 @@ fusb_ephandle_darwin::read_issue (s_both_ptr l_both) "(ReadPipeAsync%s): %s", d_transferType == kUSBInterrupt ? "" : "TO", darwin_error_str (result)); - else if (usb_debug > 4) - fprintf (stderr, "fusb_ephandle_darwin::read_issue: " - "Queued %X (%ld Bytes)\n", (unsigned int) l_both, bufLen); + else if (usb_debug > 4) { + std::cerr << "fusb_ephandle_darwin::read_issue: Queued " << (void*) l_both + << " (" << bufLen << " Bytes)" << std::endl; + } } void @@ -388,26 +398,27 @@ fusb_ephandle_darwin::read_completed (void* refCon, io_return_t result, void* io_size) { - UInt32 l_size = (UInt32) io_size; + size_t l_size = (size_t) io_size; s_both_ptr l_both = static_cast<s_both_ptr>(refCon); fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(l_both->This ()); s_node_ptr l_node = l_both->node (); circular_buffer<char>* l_buffer = This->d_buffer; s_buffer_ptr l_buf = l_node->object (); - UInt32 l_i_size = l_buf->n_used (); - - if (This->d_started && (l_i_size != l_size)) - fprintf (stderr, "fusb_ephandle_darwin::read_completed: " - "Expected %ld bytes; read %ld.\n", - l_i_size, l_size); - else if (usb_debug > 4) - fprintf (stderr, "fusb_ephandle_darwin::read_completed: " - "Read %X (%ld bytes)\n", - (unsigned int) l_both, l_size); - -// add this read to the transfer buffer + size_t l_i_size = l_buf->n_used (); + + if (This->d_started && (l_i_size != l_size)) { + std::cerr << "fusb_ephandle_darwin::read_completed: Expected " << l_i_size + << " bytes; read " << l_size << "." << std::endl; + } else if (usb_debug > 4) { + std::cerr << "fusb_ephandle_darwin::read_completed: Read " << (void*) l_both + << " (" << l_size << " bytes)" << std::endl; + } + +// add this read to the transfer buffer, and check for overflow +// -> data is being enqueued faster than it can be dequeued if (l_buffer->enqueue (l_buf->buffer (), l_size) == -1) { - fputs ("iU", stderr); +// print out that there's an overflow + fputs ("uO", stderr); fflush (stderr); } @@ -421,11 +432,13 @@ fusb_ephandle_darwin::read_completed (void* refCon, int fusb_ephandle_darwin::read (void* buffer, int nbytes) { - UInt32 l_nbytes = (UInt32) nbytes; + size_t l_nbytes = (size_t) nbytes; d_buffer->dequeue ((char*) buffer, &l_nbytes); - if (usb_debug > 4) - fprintf (stderr, "fusb_ephandle_darwin::read: request for %d bytes, %ld bytes retrieved.\n", nbytes, l_nbytes); + if (usb_debug > 4) { + std::cerr << "fusb_ephandle_darwin::read: request for " << nbytes + << " bytes, " << l_nbytes << " bytes retrieved." << std::endl; + } return ((int) l_nbytes); } @@ -433,18 +446,18 @@ fusb_ephandle_darwin::read (void* buffer, int nbytes) int fusb_ephandle_darwin::write (const void* buffer, int nbytes) { - UInt32 l_nbytes = (UInt32) nbytes; + size_t l_nbytes = (size_t) nbytes; if (! d_started) { - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::write: Not yet started.\n"); - + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::write: Not yet started." << std::endl; + } return (0); } while (l_nbytes != 0) { // find out how much data to copy; limited to "d_bufLenBytes" per node - UInt32 t_nbytes = (l_nbytes > d_bufLenBytes) ? d_bufLenBytes : l_nbytes; + size_t t_nbytes = (l_nbytes > d_bufLenBytes) ? d_bufLenBytes : l_nbytes; // get next available node to write into; // blocks internally if none available @@ -476,8 +489,8 @@ fusb_ephandle_darwin::write (const void* buffer, int nbytes) d_transferType == kUSBInterrupt ? "" : "TO", darwin_error_str (result)); else if (usb_debug > 4) { - fprintf (stderr, "fusb_ephandle_darwin::write_thread: " - "Queued %X (%ld Bytes)\n", (unsigned int) l_both, t_nbytes); + std::cerr << "fusb_ephandle_darwin::write_thread: Queued " << (void*) l_both + << " (" << t_nbytes << " Bytes)" << std::endl; } l_nbytes -= t_nbytes; } @@ -492,19 +505,19 @@ fusb_ephandle_darwin::write_completed (void* refCon, { s_both_ptr l_both = static_cast<s_both_ptr>(refCon); fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(l_both->This ()); - UInt32 l_size = (UInt32) io_size; + size_t l_size = (size_t) io_size; s_node_ptr l_node = l_both->node (); s_queue_ptr l_queue = This->d_queue; s_buffer_ptr l_buf = l_node->object (); - UInt32 l_i_size = l_buf->n_used (); - - if (This->d_started && (l_i_size != l_size)) - fprintf (stderr, "fusb_ephandle_darwin::write_completed: " - "Expected %ld bytes written; wrote %ld.\n", - l_i_size, l_size); - else if (usb_debug > 4) - fprintf (stderr, "fusb_ephandle_darwin::write_completed: " - "Wrote %X (%ld Bytes)\n", (unsigned int) l_both, l_size); + size_t l_i_size = l_buf->n_used (); + + if (This->d_started && (l_i_size != l_size)) { + std::cerr << "fusb_ephandle_darwin::write_completed: Expected " << l_i_size + << " bytes written; wrote " << l_size << "." << std::endl; + } else if (usb_debug > 4) { + std::cerr << "fusb_ephandle_darwin::write_completed: Wrote " << (void*) l_both + << " (" << l_size << " Bytes)" << std::endl; + } // set buffer's # data to 0 l_buf->n_used (0); @@ -515,8 +528,9 @@ fusb_ephandle_darwin::write_completed (void* refCon, void fusb_ephandle_darwin::abort () { - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::abort: starting.\n"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::abort: starting." << std::endl; + } io_return_t result = d_interface->AbortPipe (d_interfaceRef, d_pipeRef); @@ -524,8 +538,9 @@ fusb_ephandle_darwin::abort () USB_ERROR_STR_NO_RET (- darwin_to_errno (result), "fusb_ephandle_darwin::abort " "(AbortPipe): %s", darwin_error_str (result)); - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::abort: finished.\n"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::abort: finished." << std::endl; + } } bool @@ -534,9 +549,10 @@ fusb_ephandle_darwin::stop () if (! d_started) return (true); - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::stop: stopping %s.\n", - d_input_p ? "read" : "write"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::stop: stopping " + << (d_input_p ? "read" : "write") << "." << std::endl; + } d_started = false; @@ -556,9 +572,10 @@ fusb_ephandle_darwin::stop () d_runThreadRunning->lock (); d_runThreadRunning->unlock (); - if (usb_debug) - fprintf (stderr, "fusb_ephandle_darwin::stop: %s stopped.\n", - d_input_p ? "read" : "write"); + if (usb_debug) { + std::cerr << "fusb_ephandle_darwin::stop: " << (d_input_p ? "read" : "write") + << " stopped." << std::endl; + } return (true); } diff --git a/usrp/host/lib/fusb_darwin.h b/usrp/host/lib/fusb_darwin.h index bb717b58c..735e5f16d 100644 --- a/usrp/host/lib/fusb_darwin.h +++ b/usrp/host/lib/fusb_darwin.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -75,10 +75,10 @@ class s_buffer { private: char* d_buffer; - UInt32 d_n_used, d_n_alloc; + size_t d_n_used, d_n_alloc; public: - inline s_buffer (UInt32 n_alloc = 0) { + inline s_buffer (size_t n_alloc = 0) { d_n_used = 0; d_n_alloc = n_alloc; if (n_alloc) { @@ -92,17 +92,17 @@ public: delete [] d_buffer; } }; - inline UInt32 n_used () { return (d_n_used); }; - inline void n_used (UInt32 bufLen) { + inline size_t n_used () { return (d_n_used); }; + inline void n_used (size_t bufLen) { d_n_used = (bufLen > d_n_alloc) ? d_n_alloc : bufLen; }; - inline UInt32 n_alloc () { return (d_n_alloc); }; - void buffer (char* l_buffer, UInt32 bufLen) { + inline size_t n_alloc () { return (d_n_alloc); }; + void buffer (char* l_buffer, size_t bufLen) { if (bufLen > d_n_alloc) { - fprintf (stderr, "s_buffer::set: Copying only allocated bytes.\n"); + std::cerr << "s_buffer::set: Copying only allocated bytes." << std::endl; bufLen = d_n_alloc; } if (!l_buffer) { - fprintf (stderr, "s_buffer::set: NULL buffer.\n"); + std::cerr << "s_buffer::set: NULL buffer." << std::endl; return; } bcopy (l_buffer, d_buffer, bufLen); @@ -173,7 +173,7 @@ public: usb_interface_t* d_interface; s_queue_ptr d_queue; circular_buffer<char>* d_buffer; - UInt32 d_bufLenBytes; + size_t d_bufLenBytes; mld_mutex_ptr d_readRunning; mld_condition_ptr d_runBlock, d_readBlock; diff --git a/usrp/host/lib/usrp_prims_libusb0.cc b/usrp/host/lib/usrp_prims_libusb0.cc index 0d685d84f..7053786d8 100644 --- a/usrp/host/lib/usrp_prims_libusb0.cc +++ b/usrp/host/lib/usrp_prims_libusb0.cc @@ -69,6 +69,7 @@ _get_usb_string_descriptor (struct usb_dev_handle *udh, int index, fprintf (stderr, "usrp: usb_get_string_descriptor failed: %s\n", usb_strerror()); } + return ret; } diff --git a/usrp/usrp.pc.in b/usrp/usrp.pc.in index 297775fb1..2a15a05fd 100644 --- a/usrp/usrp.pc.in +++ b/usrp/usrp.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: usrp Description: USRP Client Side C++ interface -Requires: libusb @usrp_darwin_omnithread_pc_requires@ +Requires: @LIBUSB_PKG_CONFIG_NAME@ @usrp_darwin_omnithread_pc_requires@ Version: @VERSION@ Libs: -L${libdir} -lusrp Cflags: -I${includedir} |