jtag_libusb_bulk_read|write: return error code instead of size
[openocd.git] / src / jtag / aice / aice_usb.c
index 324ec7c32a651ae43e919b45a00b12939a31e0af..9e474134239d9db42d022d60abbfb0b773dcd000 100644 (file)
@@ -349,41 +349,53 @@ static void aice_unpack_dthmb(uint8_t *cmd_ack_code, uint8_t *target_id,
 /* calls the given usb_bulk_* function, allowing for the data to
  * trickle in with some timeouts  */
 static int usb_bulk_with_retries(
-                       int (*f)(jtag_libusb_device_handle *, int, char *, int, int),
+                       int (*f)(jtag_libusb_device_handle *, int, char *, int, int, int *),
                        jtag_libusb_device_handle *dev, int ep,
-                       char *bytes, int size, int timeout)
+                       char *bytes, int size, int timeout, int *transferred)
 {
        int tries = 3, count = 0;
 
        while (tries && (count < size)) {
-               int result = f(dev, ep, bytes + count, size - count, timeout);
-               if (result > 0)
+               int result, ret;
+
+               ret = f(dev, ep, bytes + count, size - count, timeout, &result);
+               if (ERROR_OK == ret)
                        count += result;
-               else if ((-ETIMEDOUT != result) || !--tries)
-                       return result;
+               else if ((ERROR_TIMEOUT_REACHED != ret) || !--tries)
+                       return ret;
        }
-       return count;
+
+       *transferred = count;
+       return ERROR_OK;
 }
 
 static int wrap_usb_bulk_write(jtag_libusb_device_handle *dev, int ep,
-               char *buff, int size, int timeout)
+               char *buff, int size, int timeout, int *transferred)
 {
+
        /* usb_bulk_write() takes const char *buff */
-       return jtag_libusb_bulk_write(dev, ep, buff, size, timeout);
+       jtag_libusb_bulk_write(dev, ep, buff, size, timeout, transferred);
+
+       return 0;
 }
 
 static inline int usb_bulk_write_ex(jtag_libusb_device_handle *dev, int ep,
                char *bytes, int size, int timeout)
 {
-       return usb_bulk_with_retries(&wrap_usb_bulk_write,
-                       dev, ep, bytes, size, timeout);
+       int tr = 0;
+
+       usb_bulk_with_retries(&wrap_usb_bulk_write,
+                       dev, ep, bytes, size, timeout, &tr);
+       return tr;
 }
 
 static inline int usb_bulk_read_ex(jtag_libusb_device_handle *dev, int ep,
                char *bytes, int size, int timeout)
 {
-       return usb_bulk_with_retries(&jtag_libusb_bulk_read,
-                       dev, ep, bytes, size, timeout);
+       int tr = 0;
+       usb_bulk_with_retries(&jtag_libusb_bulk_read,
+                       dev, ep, bytes, size, timeout, &tr);
+       return tr;
 }
 
 /* Write data from out_buffer to USB. */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)