From baef621beda22faa56e7c659ff221d33a6537251 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Thu, 29 Dec 2022 01:42:49 +0100 Subject: [PATCH] drivers: udc: add helper functions to set/check endpoint busy state Add helper functions to set and check endpoint busy state. Signed-off-by: Johann Fischer --- drivers/usb/udc/udc_common.c | 19 +++++++++++++++++++ drivers/usb/udc/udc_common.h | 20 ++++++++++++++++++++ include/zephyr/drivers/usb/udc.h | 2 ++ 3 files changed, 41 insertions(+) diff --git a/drivers/usb/udc/udc_common.c b/drivers/usb/udc/udc_common.c index 0e23d05b25d..9ecaa8b99be 100644 --- a/drivers/usb/udc/udc_common.c +++ b/drivers/usb/udc/udc_common.c @@ -46,6 +46,25 @@ struct udc_ep_config *udc_get_ep_cfg(const struct device *dev, const uint8_t ep) return data->ep_lut[USB_EP_LUT_IDX(ep)]; } +bool udc_ep_is_busy(const struct device *dev, const uint8_t ep) +{ + struct udc_ep_config *ep_cfg; + + ep_cfg = udc_get_ep_cfg(dev, ep); + __ASSERT(ep_cfg != NULL, "ep 0x%02x is not available", ep); + + return ep_cfg->stat.busy; +} + +void udc_ep_set_busy(const struct device *dev, const uint8_t ep, const bool busy) +{ + struct udc_ep_config *ep_cfg; + + ep_cfg = udc_get_ep_cfg(dev, ep); + __ASSERT(ep_cfg != NULL, "ep 0x%02x is not available", ep); + ep_cfg->stat.busy = busy; +} + int udc_register_ep(const struct device *dev, struct udc_ep_config *const cfg) { struct udc_data *data = dev->data; diff --git a/drivers/usb/udc/udc_common.h b/drivers/usb/udc/udc_common.h index fd8703b2cdd..2807e60250d 100644 --- a/drivers/usb/udc/udc_common.h +++ b/drivers/usb/udc/udc_common.h @@ -58,6 +58,26 @@ void udc_set_suspended(const struct device *dev, const bool value); struct udc_ep_config *udc_get_ep_cfg(const struct device *dev, const uint8_t ep); +/** + * @brief Checks if the endpoint is busy + * + * @param[in] dev Pointer to device struct of the driver instance + * @param[in] ep Endpoint address + * + * @return true if endpoint is busy + */ +bool udc_ep_is_busy(const struct device *dev, const uint8_t ep); + +/** + * @brief Helper function to set endpoint busy state + * + * @param[in] dev Pointer to device struct of the driver instance + * @param[in] ep Endpoint address + * @param[in] busy Busy state + */ +void udc_ep_set_busy(const struct device *dev, const uint8_t ep, + const bool busy); + /** * @brief Get UDC request from endpoint FIFO. * diff --git a/include/zephyr/drivers/usb/udc.h b/include/zephyr/drivers/usb/udc.h index 30d1d767646..0f87f357748 100644 --- a/include/zephyr/drivers/usb/udc.h +++ b/include/zephyr/drivers/usb/udc.h @@ -80,6 +80,8 @@ struct udc_ep_stat { uint32_t data1 : 1; /** If double buffering is supported, last used buffer is odd */ uint32_t odd : 1; + /** Endpoint is busy */ + uint32_t busy : 1; }; /**