From 2d7995747e3a8ee6e894dc8f5dfae62a38bed03c Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Tue, 22 Apr 2025 10:36:02 +0200 Subject: [PATCH] drivers: udc: add SOF Kconfig option and SOF event helper Add helper to handle SOF interrupts/events and new Kconfig option to disable SOF interrupt. Signed-off-by: Johann Fischer --- drivers/usb/udc/Kconfig | 6 ++++++ drivers/usb/udc/udc_common.h | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/usb/udc/Kconfig b/drivers/usb/udc/Kconfig index b6c49e6b3e7..b2c64634315 100644 --- a/drivers/usb/udc/Kconfig +++ b/drivers/usb/udc/Kconfig @@ -42,6 +42,12 @@ config UDC_BUF_FORCE_NOCACHE Place the buffer pools in the nocache memory region if the driver cannot handle buffers in cached memory. +config UDC_ENABLE_SOF + bool "SOF interrupt processing" + help + Enabled SoF interrupts can cause a very high CPU load on high-speed + controllers because the interrupt rate would be 125 µs. + config UDC_WORKQUEUE bool "Use a dedicate work queue for UDC drivers" help diff --git a/drivers/usb/udc/udc_common.h b/drivers/usb/udc/udc_common.h index 8cad6b6dd1c..ed6712e95ae 100644 --- a/drivers/usb/udc/udc_common.h +++ b/drivers/usb/udc/udc_common.h @@ -156,6 +156,29 @@ int udc_submit_event(const struct device *dev, int udc_submit_ep_event(const struct device *dev, struct net_buf *const buf, const int err); + +/** + * @brief Helper function to send UDC SOF event to a higher level. + * + * Type of this event is hardcoded to UDC_EVT_SOF. + * + * @param[in] dev Pointer to device struct of the driver instance + */ +#if defined(CONFIG_UDC_ENABLE_SOF) +static inline void udc_submit_sof_event(const struct device *dev) +{ + struct udc_data *data = dev->data; + struct udc_event drv_evt = { + .type = UDC_EVT_SOF, + .dev = dev, + }; + + (void)data->event_cb(dev, &drv_evt); +} +#else +#define udc_submit_sof_event(dev) ARG_UNUSED(dev) +#endif + /** * @brief Helper function to enable endpoint. *