From 18ff730d529ae9060921693a85a3491794c2c8f9 Mon Sep 17 00:00:00 2001 From: Allen Martin Date: Wed, 31 Jul 2013 16:10:45 -0700 Subject: tegrarcm: Add timeout to USB xfers This prevents tegrarcm from just hanging in the event that the target gets in some bad state and stops responding to USB (like downloading a bad BCT). Set default timeout to 1s which should be plenty long enough for the max xfer size of 4096 bytes. Signed-off-by: Allen Martin Reviewed-by: Stephen Warren --- src/usb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/usb.c b/src/usb.c index 16f3d90..450bc80 100644 --- a/src/usb.c +++ b/src/usb.c @@ -34,6 +34,9 @@ #include "usb.h" #include "debug.h" +// USB xfer timeout in ms +#define USB_TIMEOUT 1000 + #define USB_XFER_MAX 4096 // @@ -225,7 +228,7 @@ int usb_write(usb_device_t *usb, uint8_t *buf, int len) while (len) { chunk_size = MIN(len, USB_XFER_MAX); ret = libusb_bulk_transfer(usb->handle, usb->endpt_out, buf, - chunk_size, &actual_chunk, 0); + chunk_size, &actual_chunk, USB_TIMEOUT); if (ret != LIBUSB_SUCCESS) { dprintf("write failure: %d\n", ret); return EIO; @@ -252,7 +255,7 @@ int usb_read(usb_device_t *usb, uint8_t *buf, int len, int *actual_len) while (len) { chunk_size = MIN(len, USB_XFER_MAX); ret = libusb_bulk_transfer(usb->handle, usb->endpt_in, buf, - chunk_size, &actual_chunk, 0); + chunk_size, &actual_chunk, USB_TIMEOUT); if (ret != LIBUSB_SUCCESS) { dprintf("read failure: %d\n", ret); return EIO; -- cgit v1.2.1