commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3504 - gnuradio/branches/developers/michaelld/test_fu


From: michaelld
Subject: [Commit-gnuradio] r3504 - gnuradio/branches/developers/michaelld/test_fusb_darwin/usrp/host/lib
Date: Fri, 8 Sep 2006 12:22:11 -0600 (MDT)

Author: michaelld
Date: 2006-09-08 12:22:11 -0600 (Fri, 08 Sep 2006)
New Revision: 3504

Modified:
   
gnuradio/branches/developers/michaelld/test_fusb_darwin/usrp/host/lib/fusb_darwin.cc
Log:
Added better error printouts to the async callbacks.



Modified: 
gnuradio/branches/developers/michaelld/test_fusb_darwin/usrp/host/lib/fusb_darwin.cc
===================================================================
--- 
gnuradio/branches/developers/michaelld/test_fusb_darwin/usrp/host/lib/fusb_darwin.cc
        2006-09-08 14:45:26 UTC (rev 3503)
+++ 
gnuradio/branches/developers/michaelld/test_fusb_darwin/usrp/host/lib/fusb_darwin.cc
        2006-09-08 18:22:11 UTC (rev 3504)
@@ -48,8 +48,11 @@
 }
 
 fusb_ephandle*
-fusb_devhandle_darwin::make_ephandle (int endpoint, bool input_p,
-                                     int block_size, int nblocks)
+fusb_devhandle_darwin::make_ephandle
+(int endpoint,
+ bool input_p,
+ int block_size,
+ int nblocks)
 {
   return new fusb_ephandle_darwin (this, endpoint, input_p,
                                   block_size, nblocks);
@@ -57,9 +60,12 @@
 
 // ----------------------------------------------------------------
 
-fusb_ephandle_darwin::fusb_ephandle_darwin (fusb_devhandle_darwin* dh,
-                                           int endpoint, bool input_p,
-                                           int block_size, int nblocks)
+fusb_ephandle_darwin::fusb_ephandle_darwin
+(fusb_devhandle_darwin* dh,
+ int endpoint,
+ bool input_p,
+ int block_size,
+ int nblocks)
   : fusb_ephandle (endpoint, input_p, block_size, nblocks),
     d_devhandle (dh), d_pipeRef (0), d_transferType (0),
     d_interfaceRef (0),  d_interface (0), d_queue (0),
@@ -67,11 +73,13 @@
 {
   d_bufLenBytes = fusb_sysconfig::max_block_size();
 
-// create circular buffer
+  // create circular buffer
+
   d_buffer = new circular_buffer<char> (NUM_QUEUE_ITEMS * d_bufLenBytes,
                                        !d_input_p, d_input_p);
 
-// create the queue
+  // create the queue
+
   d_queue = new circular_linked_list <s_buffer_ptr> (NUM_QUEUE_ITEMS);
   d_queue->iterate_start ();
   s_node_ptr l_node = d_queue->iterate_next ();
@@ -121,15 +129,18 @@
 }
 
 bool
-fusb_ephandle_darwin::start ()
+fusb_ephandle_darwin::start
+()
 {
   UInt8  direction, number, interval;
   UInt16 maxPacketSize;
 
-// reset circular buffer
+  // reset circular buffer
+
   d_buffer->reset ();
 
-// reset the queue
+  // reset the queue
+
   d_queue->num_used (0);
   d_queue->iterate_start ();
   s_node_ptr l_node = d_queue->iterate_next ();
@@ -162,7 +173,7 @@
                   "interface used without being claimed");
   d_interface = *d_interfaceRef;
 
-// get read or write pipe info (depends on "d_input_p")
+  // get read or write pipe info (depends on "d_input_p")
 
   if (usb_debug > 3)
     fprintf (stderr, "fusb_ephandle_darwin::start "
@@ -170,6 +181,7 @@
             d_endpoint, d_input_p ? "TRUE" : "FALSE");
 
   int l_endpoint = (d_input_p ? USB_ENDPOINT_IN : USB_ENDPOINT_OUT);
+
   int pipeRef = ep_to_pipeRef (device, d_endpoint | l_endpoint);
   if (pipeRef < 0)
     USB_ERROR_STR (false, -EINVAL, "fusb_ephandle_darwin::start "
@@ -190,13 +202,16 @@
             d_endpoint, d_pipeRef, d_interface, d_interfaceRef, direction,
             number, interval, maxPacketSize);
 
-// set global start boolean
+  // set global start boolean
+
   d_started = true;
 
-// create the run thread, which allows OSX to process I/O separately
+  // create the run thread, which allows OSX to process I/O separately
+
   d_runThread = new mld_thread (run_thread, this);
 
-// wait until the threads are -really- going
+  // wait until the threads are -really- going
+
   d_runBlock->wait ();
 
   if (usb_debug)
@@ -207,7 +222,8 @@
 }
 
 void
-fusb_ephandle_darwin::run_thread (void* arg)
+fusb_ephandle_darwin::run_thread
+(void* arg)
 {
   fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(arg);
   mld_mutex_ptr l_runThreadRunning = This->d_runThreadRunning;
@@ -227,34 +243,44 @@
   usb_interface_t* l_interface = This->d_interface;
   CFRunLoopSourceRef l_cfSource;
 
-// create async run loop
+  // create async run loop
+
   l_interface->CreateInterfaceAsyncEventSource (l_interfaceRef, &l_cfSource);
   CFRunLoopAddSource (CFRunLoopGetCurrent (), l_cfSource,
                      kCFRunLoopDefaultMode);
-// get run loop reference, to allow other threads to stop
+
+  // get run loop reference, to allow other threads to stop
+
   This->d_CFRunLoopRef = CFRunLoopGetCurrent ();
 
   mld_thread_ptr l_rwThread = NULL;
 
   if (l_input_p) {
     l_rwThread = new mld_thread (read_thread, arg);
-// wait until the the rwThread is -really- going
+
+    // wait until the the rwThread is -really- going
+
     l_readBlock->wait ();
   }
 
-// now signal the run condition to release and finish ::start()
+  // now signal the run condition to release and finish ::start()
+
   This->d_runBlock->signal ();
 
-// run the loop
+  // run the loop
+
   CFRunLoopRun ();
 
   if (l_input_p) {
-// wait for read_thread () to finish
+
+    // wait for read_thread () to finish
+
     l_readRunning->lock ();
     l_readRunning->unlock ();
   }
 
-// remove run loop stuff
+  // remove run loop stuff
+
   CFRunLoopRemoveSource (CFRunLoopGetCurrent (),
                         l_cfSource, kCFRunLoopDefaultMode);
 
@@ -266,7 +292,8 @@
 }
 
 void
-fusb_ephandle_darwin::read_thread (void* arg)
+fusb_ephandle_darwin::read_thread
+(void* arg)
 {
   if (usb_debug)
     fprintf (stderr, "fusb_ephandle_darwin::read_thread: starting.\n");
@@ -276,7 +303,8 @@
   mld_mutex_ptr l_readRunning = This->d_readRunning;
   l_readRunning->lock ();
 
-// signal the read condition from run_thread() to continue
+  // signal the read condition from run_thread() to continue
+
   mld_condition_ptr l_readBlock = This->d_readBlock;
   l_readBlock->signal ();
 
@@ -295,74 +323,108 @@
 }
 
 void
-fusb_ephandle_darwin::read_issue (s_both_ptr l_both)
+fusb_ephandle_darwin::read_issue
+(s_both_ptr l_both)
 {
   if ((! l_both) || (! d_started))
     return;
 
-// set the node and buffer from the input "both"
+  // set the node and buffer from the input "both"
+
   s_node_ptr l_node = l_both->node ();
   s_buffer_ptr l_buf = l_node->object ();
   void* v_buffer = (void*) l_buf->buffer ();
 
-// read up to d_bufLenBytes
+  // read up to d_bufLenBytes
+
   UInt32 bufLen = d_bufLenBytes;
   l_buf->n_used (bufLen);
 
-// setup system call result
+  // setup system call result
+
   io_return_t result = kIOReturnSuccess;
 
-  if (d_transferType == kUSBInterrupt)
-/* This is an interrupt pipe. We can't specify a timeout. */
+  if (d_transferType == kUSBInterrupt) {
+
+    // This is an interrupt pipe; can't specify a timeout.
+
     result = d_interface->ReadPipeAsync
       (d_interfaceRef, d_pipeRef, v_buffer, bufLen,
        (IOAsyncCallback1) read_completed, (void*) l_both);
-  else
+
+  } else {
+
     result = d_interface->ReadPipeAsyncTO
       (d_interfaceRef, d_pipeRef, v_buffer, bufLen, 0, USB_TIMEOUT,
        (IOAsyncCallback1) read_completed, (void*) l_both);
 
-  if (result != kIOReturnSuccess)
+  }
+
+  if (result != kIOReturnSuccess) {
     USB_ERROR_STR_NO_RET (- darwin_to_errno (result),
                          "fusb_ephandle_darwin::read_issue "
                          "(ReadPipeAsync%s): %s",
                          d_transferType == kUSBInterrupt ? "" : "TO",
                          darwin_error_str (result));
+  }
 }
 
 void
-fusb_ephandle_darwin::read_completed (void* refCon,
-                                     io_return_t result,
-                                     void* io_size)
+fusb_ephandle_darwin::read_completed
+(void* refCon,
+ io_return_t result,
+ void* io_size)
 {
   UInt32 l_size = (UInt32) 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 
());
+  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);
+  if (result != kIOReturnSuccess) {
 
-// add this read to the transfer buffer
-  if (l_buffer->enqueue (l_buf->buffer (), l_size) == -1) {
-    fputs ("iU", stderr);
-    fflush (stderr);
+    USB_ERROR_STR_NO_RET (-darwin_to_errno (result),
+                         "fusb_ephandle_darwin::read_completed: Warning: %s",
+                         darwin_error_str (result));
+
+    if (This->d_started == false) {
+
+      fprintf (stderr, "Trying to transfer but FUSB not yet started!\n");
+
+    } else if (l_i_size != l_size) {
+
+      fprintf (stderr, "Expected %ld bytes; read %ld.\n",
+              l_i_size, l_size);
+
+    }
   }
 
-// set buffer's # data to 0
+  if (l_size != 0) {
+
+    // add this read to the transfer buffer
+
+    if (l_buffer->enqueue (l_buf->buffer (), l_size) == -1) {
+      fputs ("iU", stderr);
+      fflush (stderr);
+    }
+  }
+
+  // set buffer's # data to 0
+
   l_buf->n_used (0);
 
-// issue another read for this "both"
+  // issue another read for this "both"
+
   This->read_issue (l_both);
 }
 
 int
-fusb_ephandle_darwin::read (void* buffer, int nbytes)
+fusb_ephandle_darwin::read
+(void* buffer,
+ int nbytes)
 {
   UInt32 l_nbytes = (UInt32) nbytes;
   d_buffer->dequeue ((char*) buffer, &l_nbytes);
@@ -370,45 +432,59 @@
 }
 
 int
-fusb_ephandle_darwin::write (const void* buffer, int nbytes)
+fusb_ephandle_darwin::write
+(const void* buffer,
+ int nbytes)
 {
   UInt32 l_nbytes = (UInt32) nbytes;
 
   if (! d_started) return (0);
 
   while (l_nbytes != 0) {
-// find out how much data to copy; limited to "d_bufLenBytes" per node
+
+    // find out how much data to copy;
+    // limited to "d_bufLenBytes" per node
+
     UInt32 t_nbytes = (l_nbytes > d_bufLenBytes) ? d_bufLenBytes : l_nbytes;
 
-// get next available node to write into;
-// blocks internally if none available
+    // get next available node to write into;
+    // blocks internally if none available
+
     s_node_ptr l_node = d_queue->find_next_available_node ();
 
-// copy the input into the node's buffer
+    // copy the input into the node's buffer
+
     s_buffer_ptr l_buf = l_node->object ();
     l_buf->buffer ((char*) buffer, t_nbytes);
     void* v_buffer = (void*) l_buf->buffer ();
 
-// setup callback parameter & system call return
+    // setup callback parameter & system call return
+
     s_both_ptr l_both = l_node->both ();
     io_return_t result = kIOReturnSuccess;
 
     if (d_transferType == kUSBInterrupt)
-/* This is an interrupt pipe ... can't specify a timeout. */
+
+      // This is an interrupt pipe ... can't specify a timeout.
+
       result = d_interface->WritePipeAsync
        (d_interfaceRef, d_pipeRef, v_buffer, l_nbytes,
         (IOAsyncCallback1) write_completed, (void*) l_both);
+
     else
+
       result = d_interface->WritePipeAsyncTO
        (d_interfaceRef, d_pipeRef, v_buffer, l_nbytes, 0, USB_TIMEOUT,
         (IOAsyncCallback1) write_completed, (void*) l_both);
 
-    if (result != kIOReturnSuccess)
+    if (result != kIOReturnSuccess) {
       USB_ERROR_STR (-1, - darwin_to_errno (result),
                     "fusb_ephandle_darwin::write_thread "
                     "(WritePipeAsync%s): %s",
                     d_transferType == kUSBInterrupt ? "" : "TO",
                     darwin_error_str (result));
+    }
+
     l_nbytes -= t_nbytes;
   }
 
@@ -416,31 +492,50 @@
 }
 
 void
-fusb_ephandle_darwin::write_completed (void* refCon,
-                                      io_return_t result,
-                                      void* io_size)
+fusb_ephandle_darwin::write_completed
+(void* refCon,
+ io_return_t result,
+ void* 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 
());
+  fusb_ephandle_darwin* This =
+    static_cast<fusb_ephandle_darwin*>(l_both->This ());
   UInt32 l_size = (UInt32) 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);
+  if (result != kIOReturnSuccess) {
 
-// set buffer's # data to 0
+    USB_ERROR_STR_NO_RET (-darwin_to_errno (result),
+                         "fusb_ephandle_darwin::write_completed: Warning: %s",
+                         darwin_error_str (result));
+
+    if (This->d_started == false) {
+
+      fprintf (stderr, "Trying to transfer but FUSB not yet started!\n");
+
+    } else if (l_i_size != l_size) {
+
+      fprintf (stderr, "Expected %ld bytes written; wrote %ld.\n",
+              l_i_size, l_size);
+
+    }
+  }
+
+  // set buffer's # data to 0
+
   l_buf->n_used (0);
-// make the node available for reuse
+
+  // make the node available for reuse
+
   l_queue->make_node_available (l_node);
 }
 
 void
-fusb_ephandle_darwin::abort ()
+fusb_ephandle_darwin::abort
+()
 {
   if (usb_debug)
     fprintf (stderr, "fusb_ephandle_darwin::abort: starting.\n");
@@ -451,12 +546,14 @@
     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");
 }
 
 bool
-fusb_ephandle_darwin::stop ()
+fusb_ephandle_darwin::stop
+()
 {
   if (! d_started)
     return (true);
@@ -467,19 +564,24 @@
 
   d_started = false;
 
-// abort any pending IO transfers
+  // abort any pending IO transfers
+
   abort ();
 
-// wait for write transfer to finish
+  // wait for write transfer to finish
+
   wait_for_completion ();
 
-// tell IO buffer to abort any waiting conditions
+  // tell IO buffer to abort any waiting conditions
+
   d_buffer->abort ();
 
-// stop the run loop
+  // stop the run loop
+
   CFRunLoopStop (d_CFRunLoopRef);
 
-// wait for the runThread to stop
+  // wait for the runThread to stop
+
   d_runThreadRunning->lock ();
   d_runThreadRunning->unlock ();
 
@@ -491,7 +593,8 @@
 }
 
 void
-fusb_ephandle_darwin::wait_for_completion ()
+fusb_ephandle_darwin::wait_for_completion
+()
 {
   if (d_queue)
     while (d_queue->in_use ())





reply via email to

[Prev in Thread] Current Thread [Next in Thread]