Changeset 9517

Show
Ignore:
Timestamp:
08/19/09 22:15:31 (4 years ago)
Author:
ttsou
Message:

hopeful simutaneous tx-rx using separate libusb_contexts

Location:
ossiedev/branches/ttsou/gnuradio/usrp/host/lib
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/ttsou/gnuradio/usrp/host/lib/fusb_libusb1.cc

    r9514 r9517  
    125125// ------------------------------------------------------------------------ 
    126126 
    127 fusb_devhandle_libusb1::fusb_devhandle_libusb1 (libusb_device_handle *udh) 
    128   : fusb_devhandle (udh), d_teardown (false) 
     127fusb_devhandle_libusb1::fusb_devhandle_libusb1 (libusb_device_handle *udh, 
     128                                                libusb_context *ctx) 
     129  : fusb_devhandle (udh), d_ctx (ctx), d_teardown (false) 
    129130{ 
    130131  // that's it  
     
    259260} 
    260261 
     262 
     263bool 
     264fusb_devhandle_libusb1::_reap (bool ok_to_block_p) 
     265{ 
     266  int ret; 
     267  if ((ret = libusb_handle_events(ctx)) < 0) 
     268    fprintf (stderr, "fusb::_reap libusb_handle_events()\n"); 
     269    
     270} 
     271 
    261272void 
    262273fusb_devhandle_libusb1::_wait_for_completion () 
     
    268279  tv.tv_usec =  0; 
    269280 
    270   // The regular libusb_handle_events sets a hardcoded timeout of 2 
    271   // seconds. Most of these calls should be changed to appropriate block / non- 
    272   // blocking version using libusb_handle_events_timeout. This was just a test 
    273   // usage.  
    274  
    275   while (!d_pending_rqsts.empty ()) { 
    276     if ((ret = libusb_handle_events_timeout(NULL, &tv)) < 0) { 
    277       fprintf (stderr, "fusb: libusb_handle_events error %d\n", ret); 
    278       break; 
    279     } 
    280   } 
     281  while (!d_pending_rqsts.empty ())  
     282    if (!_reap(true))  
     283      break;  
    281284 
    282285} 
     
    391394 
    392395  d_devhandle->_cancel_pending_rqsts (this); 
    393  
    394   // Do work, reap transfers, etc.  
    395   if (libusb_handle_events(NULL) < 0) {  
    396     perror ("fusb::libusb_handle_events"); 
    397     return false; 
    398   } 
     396  d_devhandle->_reap (false); 
    399397 
    400398  while (1) { 
     
    406404      break; 
    407405 
    408     if (libusb_handle_events(NULL) < 0) { 
    409       perror ("fusb::libusb_handle_events"); 
    410       return false; 
    411     } 
     406    if (!d_devhandle->_reap(true)) 
     407      break; 
    412408  } 
    413409 
     
    516512    } 
    517513 
    518     // Do work, reap transfers, etc.  
    519     libusb_handle_events(NULL); 
     514    if (!d_devhandle->_reap (true)) 
     515      return 0; 
    520516  } 
    521517} 
     
    605601 
    606602    while ((lut = completed_list_get ()) == 0 ) { 
    607       if (libusb_handle_events(NULL) < 0)  
    608         fprintf (stderr, "fusb: libusb_handle_events\n"); 
    609     } 
     603      if (!d_devhandle->_reap(true)) 
     604        return false;  
    610605 
    611606    if (lut->status != LIBUSB_TRANSFER_COMPLETED) { 
  • ossiedev/branches/ttsou/gnuradio/usrp/host/lib/usrp_basic.cc

    r9515 r9517  
    109109                        const std::string fpga_filename, 
    110110                        const std::string firmware_filename) 
    111   : d_udh (0), 
     111  : d_udh (0), d_ctx (0), 
    112112    d_usb_data_rate (16000000), // SWAG, see below 
    113113    d_bytes_per_poll ((int) (POLLING_INTERVAL * d_usb_data_rate)), 
     
    126126  memset (d_fpga_shadows, 0, sizeof (d_fpga_shadows)); 
    127127 
    128   usrp_one_time_init (); 
     128  usrp_one_time_init (d_ctx); 
    129129 
    130130  if (!usrp_load_standard_bits (which_board, false, fpga_filename, firmware_filename)) 
    131131    throw std::runtime_error ("usrp_basic/usrp_load_standard_bits"); 
    132132 
    133   struct libusb_device *dev = usrp_find_device (which_board); 
     133  struct libusb_device *dev = usrp_find_device (d_ctx, which_board); 
    134134  if (dev == 0){ 
    135135    fprintf (stderr, "usrp_basic: can't find usrp[%d]\n", which_board); 
     
    181181  // exits nicely.  
    182182 
    183   //libusb_exit (NULL); 
     183  // Trying to keep this enabled with contexts 
     184 
     185  libusb_exit (d_ctx); 
    184186} 
    185187 
  • ossiedev/branches/ttsou/gnuradio/usrp/host/lib/usrp_prims.cc

    r9514 r9517  
    105105 
    106106void 
    107 usrp_one_time_init () 
     107usrp_one_time_init (libusb_context *ctx) 
    108108{ 
    109109  static bool first = true; 
     
    111111  if (first){ 
    112112    first = false; 
    113     libusb_init (NULL);                 // usb library init 
     113    libusb_init (&ctx);                 // usb library init 
    114114  } 
    115115} 
     
    205205 
    206206struct libusb_device * 
    207 usrp_find_device (int nth, bool fx2_ok_p) 
     207usrp_find_device (int nth, bool fx2_ok_p, libusb_context *ctx) 
    208208{ 
    209209  libusb_device **list; 
     
    212212  int    n_found = 0; 
    213213 
    214   usrp_one_time_init (); 
     214  // Why is this init necessary? It throws off context use of libusb 
     215  //usrp_one_time_init (); 
    215216  
    216   size_t cnt = libusb_get_device_list(NULL, &list); 
     217  size_t cnt = libusb_get_device_list(ctx, &list); 
    217218  size_t i = 0; 
    218219