Skip to content

Commit

Permalink
drivers: usb: common: nrf_usbd_common: Handle USB SoF IRQ first
Browse files Browse the repository at this point in the history
The processing order is relevant if the IRQ handler call is delayed and
multiple interrupts are pending. Handle USB SoF before other interrupts
to ensure that it would be reported before other USB events (e.g. before
completed USB data transfers).

Signed-off-by: Marek Pieta <[email protected]>
  • Loading branch information
MarekPieta authored and nashif committed Aug 15, 2024
1 parent 1dbfa7f commit cd931fd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,16 @@ void nrf_usbd_common_irq_handler(void)
volatile uint32_t *dma_endevent;
uint32_t epdatastatus = 0;

/* Always check and clear SOF but call handler only if SOF interrupt
* is actually enabled.
*/
if (NRF_USBD->EVENTS_SOF) {
NRF_USBD->EVENTS_SOF = 0;
if (NRF_USBD->INTENSET & USBD_INTEN_SOF_Msk) {
ev_sof_handler();
}
}

/* Clear EPDATA event and only then get and clear EPDATASTATUS to make
* sure we don't miss any event.
*/
Expand Down Expand Up @@ -1066,16 +1076,6 @@ void nrf_usbd_common_irq_handler(void)
ev_usbreset_handler();
}

/* Always check and clear SOF but call handler only if SOF interrupt
* is actually enabled.
*/
if (NRF_USBD->EVENTS_SOF) {
NRF_USBD->EVENTS_SOF = 0;
if (NRF_USBD->INTENSET & USBD_INTEN_SOF_Msk) {
ev_sof_handler();
}
}

if (NRF_USBD->EVENTS_USBEVENT) {
NRF_USBD->EVENTS_USBEVENT = 0;
ev_usbevent_handler();
Expand Down

0 comments on commit cd931fd

Please sign in to comment.