Skip to content

Commit

Permalink
drivers: usb: udc_dwc2: Synchronize thread with UDC API
Browse files Browse the repository at this point in the history
UDC API handlers and DWC2 driver thread share not only software
constructs, but also the underlying hardware. Ensure that any UDC API
call is not preempted by DWC2 driver thread (and vice versa) by
acquiring the lock in thread handler.

Signed-off-by: Tomasz Moń <[email protected]>
  • Loading branch information
tmon-nordic authored and fabiobaltieri committed Sep 25, 2024
1 parent c2f2d8c commit 5fc0405
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/usb/udc/udc_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,8 @@ static ALWAYS_INLINE void dwc2_thread_handler(void *const arg)
*/
evt = k_event_wait(&priv->drv_evt, UINT32_MAX, false, K_FOREVER);

udc_lock_internal(dev, K_FOREVER);

if (evt & BIT(DWC2_DRV_EVT_XFER)) {
k_event_clear(&priv->drv_evt, BIT(DWC2_DRV_EVT_XFER));

Expand Down Expand Up @@ -2794,6 +2796,8 @@ static ALWAYS_INLINE void dwc2_thread_handler(void *const arg)

config->irq_enable_func(dev);
}

udc_unlock_internal(dev);
}

static const struct udc_api udc_dwc2_api = {
Expand Down

0 comments on commit 5fc0405

Please sign in to comment.