Skip to content

Commit a953bdf

Browse files
kasjernashif
authored andcommitted
drivers: usb_device: smartbond: Delay message USB_DC_EP_DATA_OUT
Callback with USB_DC_EP_DATA_OUT was called directly from interrupt handler (handle_ep0_rx()) while rest of the interrupt conditions were not checked yet. Some interfaces started next transfer directly from this callback resulting in case where TX endpoint was still marked as busy and transfer was eventually abandoned. Now message is sent from all affected endpoints after every USB pending interrupt is handled. Signed-off-by: Jerzy Kasenberg <[email protected]>
1 parent f456852 commit a953bdf

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/usb/device/usb_dc_smartbond.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ struct usb_dc_state {
135135
uint8_t nfsr;
136136
usb_dc_status_callback status_cb;
137137
struct smartbond_ep_state ep_state[2][4];
138+
/** Bitmask of EP OUT endpoints that received data during interrupt */
139+
uint8_t ep_out_data;
138140
atomic_ptr_t dma_ep[2]; /** DMA used by channel */
139141
};
140142

@@ -468,8 +470,7 @@ static void handle_ep0_rx(void)
468470
read_rx_fifo(ep0_out_state, fifo_bytes);
469471
if (rxs0 & USB_USB_RXS0_REG_USB_RX_LAST_Msk) {
470472
ep0_out_state->data1 ^= 1;
471-
472-
ep0_out_state->cb(EP0_OUT, USB_DC_EP_DATA_OUT);
473+
dev_state.ep_out_data |= 1;
473474
}
474475
}
475476
}
@@ -581,8 +582,7 @@ static void handle_epx_rx_ev(uint8_t ep_idx)
581582
} else {
582583
ep_state->data1 ^= 1;
583584
atomic_clear(&ep_state->busy);
584-
ep_state->cb(ep_state->ep_addr,
585-
USB_DC_EP_DATA_OUT);
585+
dev_state.ep_out_data |= BIT(ep_idx);
586586
}
587587
}
588588
} while (fifo_bytes > FIFO_READ_THRESHOLD);
@@ -914,6 +914,16 @@ static void usb_dc_smartbond_isr(void)
914914
if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_ALT)) {
915915
handle_alt_ev();
916916
}
917+
918+
for (int i = 0; dev_state.ep_out_data && i < 4; ++i) {
919+
uint8_t mask = BIT(i);
920+
921+
if (dev_state.ep_out_data & mask) {
922+
dev_state.ep_out_data ^= mask;
923+
dev_state.ep_state[0][i].cb(dev_state.ep_state[0][i].ep_addr,
924+
USB_DC_EP_DATA_OUT);
925+
}
926+
}
917927
}
918928

919929
/**

0 commit comments

Comments
 (0)