Skip to content

Commit

Permalink
usb: device: Add transfer cancel helper
Browse files Browse the repository at this point in the history
Add usb_cancel_transfers() helper to cancel all ongoing transfers.

Signed-off-by: Andrei Emeltchenko <[email protected]>
  • Loading branch information
finikorg authored and carlescufi committed May 22, 2019
1 parent 54000fb commit bf76b2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/usb/usb_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
18 changes: 18 additions & 0 deletions subsys/usb/usb_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bf76b2a

Please sign in to comment.