Changeset 9517
- Timestamp:
- 08/19/09 22:15:31 (4 years ago)
- Location:
- ossiedev/branches/ttsou/gnuradio/usrp/host/lib
- Files:
-
- 3 modified
-
fusb_libusb1.cc (modified) (7 diffs)
-
usrp_basic.cc (modified) (3 diffs)
-
usrp_prims.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ossiedev/branches/ttsou/gnuradio/usrp/host/lib/fusb_libusb1.cc
r9514 r9517 125 125 // ------------------------------------------------------------------------ 126 126 127 fusb_devhandle_libusb1::fusb_devhandle_libusb1 (libusb_device_handle *udh) 128 : fusb_devhandle (udh), d_teardown (false) 127 fusb_devhandle_libusb1::fusb_devhandle_libusb1 (libusb_device_handle *udh, 128 libusb_context *ctx) 129 : fusb_devhandle (udh), d_ctx (ctx), d_teardown (false) 129 130 { 130 131 // that's it … … 259 260 } 260 261 262 263 bool 264 fusb_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 261 272 void 262 273 fusb_devhandle_libusb1::_wait_for_completion () … … 268 279 tv.tv_usec = 0; 269 280 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; 281 284 282 285 } … … 391 394 392 395 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); 399 397 400 398 while (1) { … … 406 404 break; 407 405 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; 412 408 } 413 409 … … 516 512 } 517 513 518 // Do work, reap transfers, etc.519 libusb_handle_events(NULL);514 if (!d_devhandle->_reap (true)) 515 return 0; 520 516 } 521 517 } … … 605 601 606 602 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; 610 605 611 606 if (lut->status != LIBUSB_TRANSFER_COMPLETED) { -
ossiedev/branches/ttsou/gnuradio/usrp/host/lib/usrp_basic.cc
r9515 r9517 109 109 const std::string fpga_filename, 110 110 const std::string firmware_filename) 111 : d_udh (0), 111 : d_udh (0), d_ctx (0), 112 112 d_usb_data_rate (16000000), // SWAG, see below 113 113 d_bytes_per_poll ((int) (POLLING_INTERVAL * d_usb_data_rate)), … … 126 126 memset (d_fpga_shadows, 0, sizeof (d_fpga_shadows)); 127 127 128 usrp_one_time_init ( );128 usrp_one_time_init (d_ctx); 129 129 130 130 if (!usrp_load_standard_bits (which_board, false, fpga_filename, firmware_filename)) 131 131 throw std::runtime_error ("usrp_basic/usrp_load_standard_bits"); 132 132 133 struct libusb_device *dev = usrp_find_device ( which_board);133 struct libusb_device *dev = usrp_find_device (d_ctx, which_board); 134 134 if (dev == 0){ 135 135 fprintf (stderr, "usrp_basic: can't find usrp[%d]\n", which_board); … … 181 181 // exits nicely. 182 182 183 //libusb_exit (NULL); 183 // Trying to keep this enabled with contexts 184 185 libusb_exit (d_ctx); 184 186 } 185 187 -
ossiedev/branches/ttsou/gnuradio/usrp/host/lib/usrp_prims.cc
r9514 r9517 105 105 106 106 void 107 usrp_one_time_init ( )107 usrp_one_time_init (libusb_context *ctx) 108 108 { 109 109 static bool first = true; … … 111 111 if (first){ 112 112 first = false; 113 libusb_init ( NULL); // usb library init113 libusb_init (&ctx); // usb library init 114 114 } 115 115 } … … 205 205 206 206 struct libusb_device * 207 usrp_find_device (int nth, bool fx2_ok_p )207 usrp_find_device (int nth, bool fx2_ok_p, libusb_context *ctx) 208 208 { 209 209 libusb_device **list; … … 212 212 int n_found = 0; 213 213 214 usrp_one_time_init (); 214 // Why is this init necessary? It throws off context use of libusb 215 //usrp_one_time_init (); 215 216 216 size_t cnt = libusb_get_device_list( NULL, &list);217 size_t cnt = libusb_get_device_list(ctx, &list); 217 218 size_t i = 0; 218 219