Skip to content
Permalink
Browse files

usb: device: Handle EAGAIN for device transfer

Handle EAGAIN for the transfer.

Fixes #13799

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information...
finikorg authored and carlescufi committed Apr 24, 2019
1 parent 5a4a658 commit c77e142fd5261a661c4859f06d0e210a80609e01
Showing with 12 additions and 3 deletions.
  1. +12 −3 subsys/usb/usb_device.c
@@ -1146,7 +1146,15 @@ int usb_disable(void)

int usb_write(u8_t ep, const u8_t *data, u32_t data_len, u32_t *bytes_ret)
{
return usb_dc_ep_write(ep, data, data_len, bytes_ret);
while (true) {
int ret = usb_dc_ep_write(ep, data, data_len, bytes_ret);

if (ret != -EAGAIN) {
return ret;
}

k_yield();
}
}

int usb_read(u8_t ep, u8_t *data, u32_t max_data_len, u32_t *ret_bytes)
@@ -1204,14 +1212,15 @@ static void usb_transfer_work(struct k_work *item)
if (trans->flags & USB_TRANS_WRITE) {
if (!trans->bsize) {
if (!(trans->flags & USB_TRANS_NO_ZLP)) {
usb_dc_ep_write(ep, NULL, 0, NULL);
usb_write(ep, NULL, 0, NULL);
}
trans->status = 0;
goto done;
}

ret = usb_dc_ep_write(ep, trans->buffer, trans->bsize, &bytes);
ret = usb_write(ep, trans->buffer, trans->bsize, &bytes);
if (ret) {
LOG_ERR("Transfer error %d", ret);
/* transfer error */
trans->status = -EINVAL;
goto done;

0 comments on commit c77e142

Please sign in to comment.
You can’t perform that action at this time.