Lines 72-79
struct usb_handle {
Link Here
|
72 |
unsigned zero_mask; |
72 |
unsigned zero_mask; |
73 |
unsigned writeable = 1; |
73 |
unsigned writeable = 1; |
74 |
|
74 |
|
75 |
usbdevfs_urb urb_in; |
75 |
usbdevfs_urb *urb_in; |
76 |
usbdevfs_urb urb_out; |
76 |
usbdevfs_urb *urb_out; |
77 |
|
77 |
|
78 |
bool urb_in_busy = false; |
78 |
bool urb_in_busy = false; |
79 |
bool urb_out_busy = false; |
79 |
bool urb_out_busy = false; |
Lines 304-310
static int usb_bulk_write(usb_handle* h, const void* data, int len) {
Link Here
|
304 |
std::unique_lock<std::mutex> lock(h->mutex); |
304 |
std::unique_lock<std::mutex> lock(h->mutex); |
305 |
D("++ usb_bulk_write ++"); |
305 |
D("++ usb_bulk_write ++"); |
306 |
|
306 |
|
307 |
usbdevfs_urb* urb = &h->urb_out; |
307 |
usbdevfs_urb* urb = h->urb_out; |
308 |
memset(urb, 0, sizeof(*urb)); |
308 |
memset(urb, 0, sizeof(*urb)); |
309 |
urb->type = USBDEVFS_URB_TYPE_BULK; |
309 |
urb->type = USBDEVFS_URB_TYPE_BULK; |
310 |
urb->endpoint = h->ep_out; |
310 |
urb->endpoint = h->ep_out; |
Lines 343-349
static int usb_bulk_read(usb_handle* h, void* data, int len) {
Link Here
|
343 |
std::unique_lock<std::mutex> lock(h->mutex); |
343 |
std::unique_lock<std::mutex> lock(h->mutex); |
344 |
D("++ usb_bulk_read ++"); |
344 |
D("++ usb_bulk_read ++"); |
345 |
|
345 |
|
346 |
usbdevfs_urb* urb = &h->urb_in; |
346 |
usbdevfs_urb* urb = h->urb_in; |
347 |
memset(urb, 0, sizeof(*urb)); |
347 |
memset(urb, 0, sizeof(*urb)); |
348 |
urb->type = USBDEVFS_URB_TYPE_BULK; |
348 |
urb->type = USBDEVFS_URB_TYPE_BULK; |
349 |
urb->endpoint = h->ep_in; |
349 |
urb->endpoint = h->ep_in; |
Lines 388-394
static int usb_bulk_read(usb_handle* h, void* data, int len) {
Link Here
|
388 |
} |
388 |
} |
389 |
D("[ urb @%p status = %d, actual = %d ]", out, out->status, out->actual_length); |
389 |
D("[ urb @%p status = %d, actual = %d ]", out, out->status, out->actual_length); |
390 |
|
390 |
|
391 |
if (out == &h->urb_in) { |
391 |
if (out == h->urb_in) { |
392 |
D("[ reap urb - IN complete ]"); |
392 |
D("[ reap urb - IN complete ]"); |
393 |
h->urb_in_busy = false; |
393 |
h->urb_in_busy = false; |
394 |
if (urb->status != 0) { |
394 |
if (urb->status != 0) { |
Lines 397-403
static int usb_bulk_read(usb_handle* h, void* data, int len) {
Link Here
|
397 |
} |
397 |
} |
398 |
return urb->actual_length; |
398 |
return urb->actual_length; |
399 |
} |
399 |
} |
400 |
if (out == &h->urb_out) { |
400 |
if (out == h->urb_out) { |
401 |
D("[ reap urb - OUT compelete ]"); |
401 |
D("[ reap urb - OUT compelete ]"); |
402 |
h->urb_out_busy = false; |
402 |
h->urb_out_busy = false; |
403 |
h->cv.notify_all(); |
403 |
h->cv.notify_all(); |
Lines 501-510
void usb_kick(usb_handle* h) {
Link Here
|
501 |
** but this ensures that a reader blocked on REAPURB |
501 |
** but this ensures that a reader blocked on REAPURB |
502 |
** will get unblocked |
502 |
** will get unblocked |
503 |
*/ |
503 |
*/ |
504 |
ioctl(h->fd, USBDEVFS_DISCARDURB, &h->urb_in); |
504 |
ioctl(h->fd, USBDEVFS_DISCARDURB, h->urb_in); |
505 |
ioctl(h->fd, USBDEVFS_DISCARDURB, &h->urb_out); |
505 |
ioctl(h->fd, USBDEVFS_DISCARDURB, h->urb_out); |
506 |
h->urb_in.status = -ENODEV; |
506 |
h->urb_in->status = -ENODEV; |
507 |
h->urb_out.status = -ENODEV; |
507 |
h->urb_out->status = -ENODEV; |
508 |
h->urb_in_busy = false; |
508 |
h->urb_in_busy = false; |
509 |
h->urb_out_busy = false; |
509 |
h->urb_out_busy = false; |
510 |
h->cv.notify_all(); |
510 |
h->cv.notify_all(); |
Lines 520-525
int usb_close(usb_handle* h) {
Link Here
|
520 |
|
520 |
|
521 |
D("-- usb close %p (fd = %d) --", h, h->fd); |
521 |
D("-- usb close %p (fd = %d) --", h, h->fd); |
522 |
|
522 |
|
|
|
523 |
delete h->urb_in; |
524 |
delete h->urb_out; |
523 |
delete h; |
525 |
delete h; |
524 |
|
526 |
|
525 |
return 0; |
527 |
return 0; |
Lines 573-578
static void register_device(const char* dev_name, const char* dev_path, unsigned
Link Here
|
573 |
usb->ep_out = ep_out; |
575 |
usb->ep_out = ep_out; |
574 |
usb->zero_mask = zero_mask; |
576 |
usb->zero_mask = zero_mask; |
575 |
usb->max_packet_size = max_packet_size; |
577 |
usb->max_packet_size = max_packet_size; |
|
|
578 |
usb->urb_in = new usbdevfs_urb; |
579 |
usb->urb_out = new usbdevfs_urb; |
576 |
|
580 |
|
577 |
// Initialize mark so we don't get garbage collected after the device scan. |
581 |
// Initialize mark so we don't get garbage collected after the device scan. |
578 |
usb->mark = true; |
582 |
usb->mark = true; |