From 38aea280e75ed4b3d23abb0c5b3416008c7d7dff Mon Sep 17 00:00:00 2001 From: Emil Obalski Date: Fri, 17 Jan 2020 14:37:11 +0100 Subject: [PATCH] usb: Sync receiving data from ISO OUT endpoint with SOF This commit adds support for receiveing data from ISO OUT endpoint for NRF devices. NRF USB IP core does not generate IRQ when data are received on ISO OUT endpoint and it must be synchronized with SOF event. Enable SOF handling by default if usb audio is configured with NRF devices. Signed-off-by: Emil Obalski --- drivers/usb/device/usb_dc_nrfx.c | 41 ++++++++++++++++++++++++++++++++ subsys/usb/Kconfig | 1 + 2 files changed, 42 insertions(+) diff --git a/drivers/usb/device/usb_dc_nrfx.c b/drivers/usb/device/usb_dc_nrfx.c index 4e15149ff4f..85cea536905 100644 --- a/drivers/usb/device/usb_dc_nrfx.c +++ b/drivers/usb/device/usb_dc_nrfx.c @@ -1235,6 +1235,45 @@ static inline void usbd_reinit(void) } } +/** + * @brief funciton to generate fake receive request for + * ISO OUT EP. + * + * ISO OUT endpoint does not generate irq by itself and reading + * from ISO OUT ep is sunchronized with SOF frame. For more details + * refer to Nordic usbd specification. + */ +static void usbd_sof_trigger_iso_read(void) +{ + struct usbd_event *ev; + struct nrf_usbd_ep_ctx *ep_ctx; + + ep_ctx = endpoint_ctx(NRFX_USBD_EPOUT8); + if (!ep_ctx) { + LOG_ERR("There is no ISO ep"); + return; + } + + if (ep_ctx->cfg.en) { + /* Dissect receive request + * if the iso OUT ep is enabled + */ + ep_ctx->read_pending = true; + ep_ctx->read_complete = true; + ev = usbd_evt_alloc(); + if (!ev) { + LOG_ERR("Failed to alloc evt"); + return; + } + ev->evt_type = USBD_EVT_EP; + ev->evt.ep_evt.evt_type = EP_EVT_RECV_REQ; + ev->evt.ep_evt.ep = ep_ctx; + usbd_evt_put(ev); + usbd_work_schedule(); + } else { + LOG_DBG("Endpoint is not enabled"); + } +} /* Work handler */ static void usbd_work_handler(struct k_work *item) @@ -1273,6 +1312,8 @@ static void usbd_work_handler(struct k_work *item) } break; case USBD_EVT_SOF: + usbd_sof_trigger_iso_read(); + if (ctx->status_cb) { ctx->status_cb(USB_DC_SOF, NULL); } diff --git a/subsys/usb/Kconfig b/subsys/usb/Kconfig index 60a7d997191..1dc879b726c 100644 --- a/subsys/usb/Kconfig +++ b/subsys/usb/Kconfig @@ -72,6 +72,7 @@ config USB_NUMOF_EP_WRITE_RETRIES config USB_DEVICE_SOF bool "Enable Start of Frame processing in events" + default y if (USB_DEVICE_AUDIO && NRFX_USBD) config USB_DEVICE_REMOTE_WAKEUP bool "Enable support for remote wakeup"