From 2c672b92c805c7cf92df728831f73d2d5e83e21c Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 17 Apr 2019 14:02:48 +0300 Subject: [PATCH] usb: device: Add usb_transfer_is_busy() function Add usb_transfer_is_busy() function to check if there is ongoing transfer. Signed-off-by: Andrei Emeltchenko --- include/usb/usb_device.h | 10 ++++++++++ subsys/usb/usb_device.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/usb/usb_device.h b/include/usb/usb_device.h index fe405c65256..fbe7fa72c9c 100644 --- a/include/usb/usb_device.h +++ b/include/usb/usb_device.h @@ -418,6 +418,16 @@ int usb_transfer_sync(u8_t ep, u8_t *data, size_t dlen, unsigned int flags); */ void usb_cancel_transfer(u8_t ep); +/** + * @brief Check that transfer is ongoing for the endpoint + * + * @param[in] ep Endpoint address corresponding to the one + * listed in the device configuration table + * + * @return true if transfer is ongoing, false otherwise. + */ +bool usb_transfer_is_busy(u8_t ep); + /** * @brief Start the USB remote wakeup procedure * diff --git a/subsys/usb/usb_device.c b/subsys/usb/usb_device.c index 696416c0e49..6fb3af87897 100644 --- a/subsys/usb/usb_device.c +++ b/subsys/usb/usb_device.c @@ -1194,6 +1194,17 @@ static struct usb_transfer_data *usb_ep_get_transfer(u8_t ep) return NULL; } +bool usb_transfer_is_busy(u8_t ep) +{ + struct usb_transfer_data *trans = usb_ep_get_transfer(ep); + + if (trans && trans->status == -EBUSY) { + return true; + } + + return false; +} + static void usb_transfer_work(struct k_work *item) { struct usb_transfer_data *trans;