summaryrefslogtreecommitdiff
path: root/usrp
diff options
context:
space:
mode:
authorMichael2009-10-15 09:43:20 -0400
committerMichael2009-10-15 09:43:20 -0400
commit11cb05e10b5311bbaebfc67a6358d21fcd1b948d (patch)
tree12baf6d49efc472e46e1fe1e483a7cd089c27fc4 /usrp
parentcc5253b05a49d87a81f8510188c40196b0965fad (diff)
downloadgnuradio-11cb05e10b5311bbaebfc67a6358d21fcd1b948d.tar.gz
gnuradio-11cb05e10b5311bbaebfc67a6358d21fcd1b948d.tar.bz2
gnuradio-11cb05e10b5311bbaebfc67a6358d21fcd1b948d.zip
OSX 10.6 x86_64 fixes for configure and libusb; Audio is next
Diffstat (limited to 'usrp')
-rw-r--r--usrp/host/lib/circular_buffer.h26
-rw-r--r--usrp/host/lib/darwin_libusb.h35
-rw-r--r--usrp/host/lib/fusb_darwin.cc167
-rw-r--r--usrp/host/lib/fusb_darwin.h14
4 files changed, 135 insertions, 107 deletions
diff --git a/usrp/host/lib/circular_buffer.h b/usrp/host/lib/circular_buffer.h
index 8898e4194..996b1b74b 100644
--- a/usrp/host/lib/circular_buffer.h
+++ b/usrp/host/lib/circular_buffer.h
@@ -43,8 +43,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 +69,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(): "
@@ -92,21 +92,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,7 +149,7 @@ public:
* buffer length is larger than the instantiated buffer length
*/
- int enqueue (T* buf, UInt32 bufLen_I) {
+ int enqueue (T* buf, size_t 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););
@@ -193,7 +193,7 @@ public:
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,7 +232,7 @@ public:
* buffer length is larger than the instantiated buffer length
*/
- int dequeue (T* buf, UInt32* bufLen_I) {
+ int dequeue (T* buf, size_t* 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););
@@ -242,7 +242,7 @@ public:
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) {
@@ -286,7 +286,7 @@ public:
}
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/darwin_libusb.h b/usrp/host/lib/darwin_libusb.h
index 063a2e9c6..a9cd2055a 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]);
}
}
diff --git a/usrp/host/lib/fusb_darwin.cc b/usrp/host/lib/fusb_darwin.cc
index 737387b87..91185de28 100644
--- a/usrp/host/lib/fusb_darwin.cc
+++ b/usrp/host/lib/fusb_darwin.cc
@@ -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,22 +398,21 @@ 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);
+ 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
if (l_buffer->enqueue (l_buf->buffer (), l_size) == -1) {
@@ -421,11 +430,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 +444,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 +487,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 +503,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 +526,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 +536,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 +547,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 +570,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..63016648b 100644
--- a/usrp/host/lib/fusb_darwin.h
+++ b/usrp/host/lib/fusb_darwin.h
@@ -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,11 +92,11 @@ 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");
bufLen = d_n_alloc;
@@ -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;