Skip to content
Permalink
Browse files

usb: device: Add transfer cancel helper

Add usb_cancel_transfers() helper to cancel all ongoing transfers.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information...
finikorg authored and carlescufi committed May 16, 2019
1 parent 54000fb commit bf76b2acc3f4b956c2a37c96402c430718f6946a
Showing with 23 additions and 0 deletions.
  1. +5 −0 include/usb/usb_device.h
  2. +18 −0 subsys/usb/usb_device.c
@@ -418,6 +418,11 @@ int usb_transfer_sync(u8_t ep, u8_t *data, size_t dlen, unsigned int flags);
*/
void usb_cancel_transfer(u8_t ep);

/**
* @brief Cancel all ongoing transfers
*/
void usb_cancel_transfers(void);

/**
* @brief Check that transfer is ongoing for the endpoint
*
@@ -1419,6 +1419,24 @@ void usb_cancel_transfer(u8_t ep)
irq_unlock(key);
}

void usb_cancel_transfers(void)
{
for (int i = 0; i < ARRAY_SIZE(usb_dev.transfer); i++) {
struct usb_transfer_data *trans = &usb_dev.transfer[i];
unsigned int key;

key = irq_lock();

if (trans->status == -EBUSY) {
trans->status = -ECANCELED;
k_work_submit(&trans->work);
LOG_DBG("Cancel transfer");
}

irq_unlock(key);
}
}

struct usb_transfer_sync_priv {
int tsize;
struct k_sem sem;

0 comments on commit bf76b2a

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