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 <emil.obalski@nordicsemi.no>
This commit is contained in:
Emil Obalski 2020-01-17 14:37:11 +01:00 committed by Carles Cufí
commit 38aea280e7
2 changed files with 42 additions and 0 deletions

View file

@ -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);
}

View file

@ -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"