summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2026-12-02 21:58:47 +0800
committersakumisu <[email protected]>2026-12-03 10:22:19 +0800
commitdc59af7914f877c833cd6a662f05a5e842e622fa (patch)
tree56008a937d056f50c6810ade31f76a4a5fe4fed5
parent6a683fae2eb0f42b4f65174e9aae9bb1d5d42dce (diff)
update(port/dwc2/usb_hc_dwc2): move intr & iso transfer into sof, support more frame binterval
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--port/dwc2/usb_hc_dwc2.c323
1 files changed, 231 insertions, 92 deletions
diff --git a/port/dwc2/usb_hc_dwc2.c b/port/dwc2/usb_hc_dwc2.c
index bb98441f..09a8ea45 100644
--- a/port/dwc2/usb_hc_dwc2.c
+++ b/port/dwc2/usb_hc_dwc2.c
@@ -15,6 +15,9 @@
#define USB_OTG_HC(i) ((DWC2_HostChannelTypeDef *)(bus->hcd.reg_base + USB_OTG_HOST_CHANNEL_BASE + ((i)*USB_OTG_HOST_CHANNEL_SIZE)))
struct dwc2_chan {
+ usb_dlist_t list;
+ uint16_t start_frame;
+ bool start_frame_valid;
uint8_t ep0_state;
uint16_t num_packets;
uint32_t xferlen;
@@ -37,6 +40,8 @@ struct dwc2_hcd {
volatile bool port_occ;
struct dwc2_hw_params hw_params;
struct dwc2_user_params user_params;
+ usb_dlist_t intr_list;
+ uint16_t intr_frame;
struct dwc2_chan chan_pool[16];
} g_dwc2_hcd[CONFIG_USBHOST_MAX_BUS];
@@ -306,12 +311,46 @@ static void dwc2_chan_init(struct usbh_bus *bus,
dwc2_chan_splt_init(bus, ch_num);
}
+static uint32_t dwc2_intr_xfer_time_us(struct usbh_bus *bus, struct dwc2_chan *chan, uint32_t size, uint16_t num_packets)
+{
+ uint32_t fifo_words;
+ uint32_t bits;
+ uint32_t xfer_us;
+
+ fifo_words = g_dwc2_hcd[bus->hcd.hcd_id].user_params.host_perio_tx_fifo_size;
+ fifo_words -= MIN(fifo_words, USB_OTG_HOST->HPTXSTS & USB_OTG_HPTXSTS_PTXFSAVL);
+ size += fifo_words * 4U;
+ /* Worst-case bit stuffing, plus token/data/handshake and host overhead. */
+ bits = (size * 56U + 5U) / 6U;
+ if (chan->urb->hport->speed == USB_SPEED_HIGH || chan->do_ssplit) {
+ xfer_us = num_packets + (bits * 21U + 9999U) / 10000U;
+ } else if (chan->urb->hport->speed == USB_SPEED_FULL) {
+ xfer_us = 11U * num_packets + (bits * 84U + 999U) / 1000U;
+ } else {
+ xfer_us = 68U * num_packets + (bits * 677U + 999U) / 1000U;
+ }
+ /* Leave time for the final channel register writes. */
+ return xfer_us + 2U;
+}
+
static inline void dwc2_chan_transfer(struct usbh_bus *bus, uint8_t ch_num, uint8_t ep_addr, uint8_t *buf, uint32_t size, uint16_t num_packets, uint8_t pid)
{
__IO uint32_t tmpreg;
uint8_t is_oddframe;
+ uint16_t frame_number;
+ struct dwc2_chan *chan;
+ uint32_t hfnum;
+ uint32_t frame_us = 0;
+ uint32_t xfer_us = 0;
+ uint32_t remaining_us;
size_t flags;
+ chan = &g_dwc2_hcd[bus->hcd.hcd_id].chan_pool[ch_num];
+ if (USB_GET_ENDPOINT_TYPE(chan->urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_INTERRUPT && !chan->do_csplit) {
+ xfer_us = dwc2_intr_xfer_time_us(bus, chan, size, num_packets);
+ frame_us = chan->urb->hport->speed == USB_SPEED_HIGH || chan->do_ssplit ? 125U : 1000U;
+ }
+
/* Initialize the HCTSIZn register */
USB_OTG_HC(ch_num)->HCTSIZ = (size & USB_OTG_HCTSIZ_XFRSIZ) |
(((uint32_t)num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |
@@ -325,14 +364,24 @@ static inline void dwc2_chan_transfer(struct usbh_bus *bus, uint8_t ch_num, uint
/* Enable channel interrupts required for this transfer. */
USB_OTG_HC((uint32_t)ch_num)->HCINTMSK = USB_OTG_HCINTMSK_CHHM;
- is_oddframe = (((uint32_t)USB_OTG_HOST->HFNUM & 0x01U) != 0U) ? 0U : 1U;
- USB_OTG_HC(ch_num)->HCCHAR &= ~USB_OTG_HCCHAR_ODDFRM;
- USB_OTG_HC(ch_num)->HCCHAR |= (uint32_t)is_oddframe << 29;
+ hfnum = USB_OTG_HOST->HFNUM;
+ frame_number = hfnum & 0x3FFFU;
+ is_oddframe = (frame_number & 0x01U) != 0U ? 0U : 1U;
+ if (frame_us) {
+ remaining_us = ((hfnum >> 16) * frame_us) / ((USB_OTG_HOST->HFIR & USB_OTG_HFIR_FRIVL) + 1U);
+ if (remaining_us <= xfer_us) {
+ frame_number = (frame_number + 1U) & 0x3FFFU;
+ }
+ is_oddframe = frame_number & 0x01U;
+ /* Base the next interval on the selected wire frame, including deferral. */
+ chan->start_frame = (chan->start_frame +
+ ((frame_number - g_dwc2_hcd[bus->hcd.hcd_id].intr_frame) & 0x3FFFU)) & 0x3FFFU;
+ }
/* Set host channel enable */
tmpreg = USB_OTG_HC(ch_num)->HCCHAR;
- tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
- tmpreg |= USB_OTG_HCCHAR_CHENA;
+ tmpreg &= ~(USB_OTG_HCCHAR_CHDIS | USB_OTG_HCCHAR_ODDFRM);
+ tmpreg |= USB_OTG_HCCHAR_CHENA | ((uint32_t)is_oddframe << 29);
USB_OTG_HC(ch_num)->HCCHAR = tmpreg;
usb_osal_leave_critical_section(flags);
@@ -500,6 +549,7 @@ static void dwc2_chan_free(struct dwc2_chan *chan)
chan->urb->hcpriv = NULL;
chan->urb = NULL;
}
+ chan->start_frame_valid = false;
chan->inuse = false;
usb_osal_leave_critical_section(flags);
}
@@ -634,6 +684,10 @@ static void dwc2_bulk_intr_urb_init(struct usbh_bus *bus, uint8_t chidx, struct
datalen = buflen;
}
+ if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_INTERRUPT) {
+ datalen = MIN(datalen, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize) * (USB_GET_MULT(urb->ep->wMaxPacketSize) + 1U));
+ }
+
chan->num_packets = dwc2_calculate_packet_num(datalen, urb->ep->bEndpointAddress, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), &chan->xferlen);
dwc2_chan_init(bus,
chidx,
@@ -659,6 +713,36 @@ static void dwc2_iso_urb_init(struct usbh_bus *bus, uint8_t chidx, struct usbh_u
}
#endif
+static void dwc2_intr_urb_enqueue(struct usbh_bus *bus, struct dwc2_chan *chan)
+{
+ size_t flags;
+ uint16_t frame;
+ uint16_t next_frame;
+ uint16_t elapsed;
+
+ flags = usb_osal_enter_critical_section();
+ frame = usbh_get_frame_number(bus) & 0x3FFFU;
+ if (!chan->start_frame_valid) {
+ /* First submission starts at the next SOF. */
+ next_frame = frame + 1U;
+ } else {
+ next_frame = chan->start_frame;
+ elapsed = (frame - next_frame) & 0x3FFFU;
+ /* A difference below half the counter range means the deadline is due. */
+ if (elapsed < 0x2000U) {
+ next_frame = frame + 1U;
+ }
+ }
+ chan->start_frame = next_frame & 0x3FFFU;
+ chan->start_frame_valid = true;
+ if (usb_dlist_isempty(&g_dwc2_hcd[bus->hcd.hcd_id].intr_list)) {
+ USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_SOF;
+ }
+ usb_dlist_insert_before(&g_dwc2_hcd[bus->hcd.hcd_id].intr_list, &chan->list);
+ USB_OTG_GLB->GINTMSK |= USB_OTG_GINTMSK_SOFM;
+ usb_osal_leave_critical_section(flags);
+}
+
static void dwc2_urb_waitup(struct usbh_urb *urb)
{
struct dwc2_chan *chan;
@@ -693,6 +777,7 @@ int usb_hc_init(struct usbh_bus *bus)
int ret;
memset(&g_dwc2_hcd[bus->hcd.hcd_id], 0, sizeof(struct dwc2_hcd));
+ usb_dlist_init(&g_dwc2_hcd[bus->hcd.hcd_id].intr_list);
usb_hc_low_level_init(bus);
@@ -715,6 +800,7 @@ int usb_hc_init(struct usbh_bus *bus)
}
for (uint8_t chidx = 0; chidx < g_dwc2_hcd[bus->hcd.hcd_id].hw_params.host_channels; chidx++) {
+ usb_dlist_init(&g_dwc2_hcd[bus->hcd.hcd_id].chan_pool[chidx].list);
g_dwc2_hcd[bus->hcd.hcd_id].chan_pool[chidx].waitsem = usb_osal_sem_create(0);
USB_ASSERT(g_dwc2_hcd[bus->hcd.hcd_id].chan_pool[chidx].waitsem != NULL);
}
@@ -1050,6 +1136,7 @@ int usbh_submit_urb(struct usbh_urb *urb)
chan->urb = urb;
chan->is_timeout = false;
chan->do_ssplit = 0;
+ chan->do_csplit = 0;
if (urb->hport->speed != USB_SPEED_HIGH &&
usbh_get_port_speed(bus, 0) == USB_SPEED_HIGH) {
@@ -1086,9 +1173,11 @@ int usbh_submit_urb(struct usbh_urb *urb)
dwc2_control_urb_init(bus, chidx, urb, urb->setup, urb->transfer_buffer, urb->transfer_buffer_length);
break;
case USB_ENDPOINT_TYPE_BULK:
- case USB_ENDPOINT_TYPE_INTERRUPT:
dwc2_bulk_intr_urb_init(bus, chidx, urb, urb->transfer_buffer, urb->transfer_buffer_length);
break;
+ case USB_ENDPOINT_TYPE_INTERRUPT:
+ dwc2_intr_urb_enqueue(bus, chan);
+ break;
case USB_ENDPOINT_TYPE_ISOCHRONOUS:
USB_ASSERT_MSG(0, "Do not support iso transfer");
break;
@@ -1132,7 +1221,14 @@ int usbh_kill_urb(struct usbh_urb *urb)
/* URB is not completed yet */
if (urb->errorcode == -USB_ERR_BUSY) {
- dwc2_halt(bus, chan->chidx);
+ if (!usb_dlist_isempty(&chan->list)) {
+ usb_dlist_remove(&chan->list);
+ if (usb_dlist_isempty(&g_dwc2_hcd[bus->hcd.hcd_id].intr_list)) {
+ USB_OTG_GLB->GINTMSK &= ~USB_OTG_GINTMSK_SOFM;
+ }
+ } else {
+ dwc2_halt(bus, chan->chidx);
+ }
urb->errorcode = -USB_ERR_SHUTDOWN;
if (!chan->is_timeout) {
@@ -1203,7 +1299,10 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
}
} else if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_ISOCHRONOUS) {
} else {
- if (chan->do_ssplit && urb->transfer_buffer_length > 0 && (count == USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize))) {
+ if (USB_GET_ENDPOINT_TYPE(chan->urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_INTERRUPT && urb->transfer_buffer_length > 0 &&
+ count > 0 && (count % USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize)) == 0) {
+ dwc2_intr_urb_enqueue(bus, chan);
+ } else if (chan->do_ssplit && urb->transfer_buffer_length > 0 && (count == USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize))) {
dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
} else {
usb_dcache_invalidate((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->actual_length, CONFIG_USB_ALIGN_SIZE));
@@ -1217,35 +1316,27 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
} else if (chan_intstatus & USB_OTG_HCINT_STALL) {
urb->errorcode = -USB_ERR_STALL;
dwc2_urb_waitup(urb);
- } else if (chan_intstatus & USB_OTG_HCINT_NAK) {
- if (chan->do_ssplit) {
- /* restart ssplit transfer */
- switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
- case USB_ENDPOINT_TYPE_CONTROL:
- chan->do_csplit = 0;
- dwc2_control_urb_init(bus, ch_num, urb, urb->setup, urb->transfer_buffer + urb->actual_length - 8, urb->transfer_buffer_length);
- break;
- case USB_ENDPOINT_TYPE_BULK:
- chan->do_csplit = 0;
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
- break;
- case USB_ENDPOINT_TYPE_INTERRUPT:
- chan->do_csplit = 0;
- dwc2_chan_enable_csplit(bus, ch_num, false);
- urb->errorcode = -USB_ERR_NAK;
- dwc2_urb_waitup(urb);
- break;
-
- default:
- break;
- }
+ } else if (chan_intstatus & USB_OTG_HCINT_TXERR) {
+ urb->errorcode = -USB_ERR_IO;
+ dwc2_urb_waitup(urb);
+ } else if (chan_intstatus & USB_OTG_HCINT_BBERR) {
+ urb->errorcode = -USB_ERR_BABBLE;
+ dwc2_urb_waitup(urb);
+ } else if (chan_intstatus & USB_OTG_HCINT_DTERR) {
+ urb->errorcode = -USB_ERR_DT;
+ dwc2_urb_waitup(urb);
+ } else if (chan_intstatus & USB_OTG_HCINT_FRMOR) {
+ if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_INTERRUPT) {
+ /* A missed periodic slot must not terminate interrupt polling. */
+ chan->do_csplit = 0;
+ dwc2_intr_urb_enqueue(bus, chan);
} else {
- urb->errorcode = -USB_ERR_NAK;
+ urb->errorcode = -USB_ERR_IO;
dwc2_urb_waitup(urb);
}
- } else if (chan_intstatus & USB_OTG_HCINT_ACK) {
+ } else if (chan_intstatus & USB_OTG_HCINT_NYET) {
if (chan->do_ssplit) {
- /* start csplit transfer */
+ /* restart csplit transfer */
chan->do_csplit = 1;
chan->ssplit_frame = dwc2_get_full_frame_num(bus);
switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
@@ -1260,10 +1351,30 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
default:
break;
}
+ } else {
+ urb->errorcode = -USB_ERR_NAK;
+ dwc2_urb_waitup(urb);
}
- } else if (chan_intstatus & USB_OTG_HCINT_NYET) {
+ } else if (chan_intstatus & USB_OTG_HCINT_NAK) {
+ /* restart previous transfer */
+ chan->do_csplit = 0;
+ switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
+ case USB_ENDPOINT_TYPE_CONTROL:
+ dwc2_control_urb_init(bus, ch_num, urb, urb->setup, urb->transfer_buffer + urb->actual_length - 8, urb->transfer_buffer_length);
+ break;
+ case USB_ENDPOINT_TYPE_BULK:
+ dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
+ break;
+ case USB_ENDPOINT_TYPE_INTERRUPT:
+ dwc2_intr_urb_enqueue(bus, chan);
+ break;
+
+ default:
+ break;
+ }
+ } else if (chan_intstatus & USB_OTG_HCINT_ACK) {
if (chan->do_ssplit) {
- /* restart csplit transfer */
+ /* start csplit transfer */
chan->do_csplit = 1;
chan->ssplit_frame = dwc2_get_full_frame_num(bus);
switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
@@ -1278,22 +1389,7 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
default:
break;
}
- } else {
- urb->errorcode = -USB_ERR_NAK;
- dwc2_urb_waitup(urb);
}
- } else if (chan_intstatus & USB_OTG_HCINT_TXERR) {
- urb->errorcode = -USB_ERR_IO;
- dwc2_urb_waitup(urb);
- } else if (chan_intstatus & USB_OTG_HCINT_BBERR) {
- urb->errorcode = -USB_ERR_BABBLE;
- dwc2_urb_waitup(urb);
- } else if (chan_intstatus & USB_OTG_HCINT_DTERR) {
- urb->errorcode = -USB_ERR_DT;
- dwc2_urb_waitup(urb);
- } else if (chan_intstatus & USB_OTG_HCINT_FRMOR) {
- urb->errorcode = -USB_ERR_IO;
- dwc2_urb_waitup(urb);
}
}
}
@@ -1371,7 +1467,9 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
}
} else if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_ISOCHRONOUS) {
} else {
- if (chan->do_ssplit && urb->transfer_buffer_length > 0) {
+ if (USB_GET_ENDPOINT_TYPE(chan->urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_INTERRUPT && urb->transfer_buffer_length > 0) {
+ dwc2_intr_urb_enqueue(bus, chan);
+ } else if (chan->do_ssplit && urb->transfer_buffer_length > 0) {
dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
} else {
urb->errorcode = 0;
@@ -1384,23 +1482,36 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
} else if (chan_intstatus & USB_OTG_HCINT_STALL) {
urb->errorcode = -USB_ERR_STALL;
dwc2_urb_waitup(urb);
- } else if (chan_intstatus & USB_OTG_HCINT_NAK) {
+ } else if (chan_intstatus & USB_OTG_HCINT_TXERR) {
+ urb->errorcode = -USB_ERR_IO;
+ dwc2_urb_waitup(urb);
+ } else if (chan_intstatus & USB_OTG_HCINT_BBERR) {
+ urb->errorcode = -USB_ERR_BABBLE;
+ dwc2_urb_waitup(urb);
+ } else if (chan_intstatus & USB_OTG_HCINT_DTERR) {
+ urb->errorcode = -USB_ERR_DT;
+ dwc2_urb_waitup(urb);
+ } else if (chan_intstatus & USB_OTG_HCINT_FRMOR) {
+ if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_INTERRUPT) {
+ /* A missed periodic slot must not terminate interrupt polling. */
+ chan->do_csplit = 0;
+ dwc2_intr_urb_enqueue(bus, chan);
+ } else {
+ urb->errorcode = -USB_ERR_IO;
+ dwc2_urb_waitup(urb);
+ }
+ } else if (chan_intstatus & USB_OTG_HCINT_NYET) {
if (chan->do_ssplit) {
- /* restart ssplit transfer */
+ /* restart csplit transfer */
+ chan->do_csplit = 1;
+ chan->ssplit_frame = dwc2_get_full_frame_num(bus);
switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
case USB_ENDPOINT_TYPE_CONTROL:
- chan->do_csplit = 0;
dwc2_control_urb_init(bus, ch_num, urb, urb->setup, urb->transfer_buffer + urb->actual_length - 8, urb->transfer_buffer_length);
break;
case USB_ENDPOINT_TYPE_BULK:
- chan->do_csplit = 0;
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
- break;
case USB_ENDPOINT_TYPE_INTERRUPT:
- chan->do_csplit = 0;
- dwc2_chan_enable_csplit(bus, ch_num, false);
- urb->errorcode = -USB_ERR_NAK;
- dwc2_urb_waitup(urb);
+ dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
break;
default:
@@ -1410,6 +1521,23 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
urb->errorcode = -USB_ERR_NAK;
dwc2_urb_waitup(urb);
}
+ } else if (chan_intstatus & USB_OTG_HCINT_NAK) {
+ /* restart previous transfer */
+ chan->do_csplit = 0;
+ switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
+ case USB_ENDPOINT_TYPE_CONTROL:
+ dwc2_control_urb_init(bus, ch_num, urb, urb->setup, urb->transfer_buffer + urb->actual_length - 8, urb->transfer_buffer_length);
+ break;
+ case USB_ENDPOINT_TYPE_BULK:
+ dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
+ break;
+ case USB_ENDPOINT_TYPE_INTERRUPT:
+ dwc2_intr_urb_enqueue(bus, chan);
+ break;
+
+ default:
+ break;
+ }
} else if (chan_intstatus & USB_OTG_HCINT_ACK) {
if (chan->do_ssplit) {
/* start csplit transfer */
@@ -1428,40 +1556,48 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
break;
}
}
- } else if (chan_intstatus & USB_OTG_HCINT_NYET) {
- if (chan->do_ssplit) {
- /* restart csplit transfer */
- chan->do_csplit = 1;
- chan->ssplit_frame = dwc2_get_full_frame_num(bus);
- switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
- case USB_ENDPOINT_TYPE_CONTROL:
- dwc2_control_urb_init(bus, ch_num, urb, urb->setup, urb->transfer_buffer + urb->actual_length - 8, urb->transfer_buffer_length);
- break;
- case USB_ENDPOINT_TYPE_BULK:
- case USB_ENDPOINT_TYPE_INTERRUPT:
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
- break;
+ }
+ }
+}
- default:
- break;
- }
- } else {
- urb->errorcode = -USB_ERR_NAK;
- dwc2_urb_waitup(urb);
+static void dwc2_sof_irq_handler(struct usbh_bus *bus)
+{
+ struct dwc2_chan *chan;
+ struct usbh_urb *urb;
+ usb_dlist_t *list, *next;
+ uint16_t frame_number;
+ uint32_t interval;
+
+ USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_SOF;
+ frame_number = usbh_get_frame_number(bus) & 0x3FFFU;
+ g_dwc2_hcd[bus->hcd.hcd_id].intr_frame = frame_number;
+
+ usb_dlist_for_each_safe(list, next, &g_dwc2_hcd[bus->hcd.hcd_id].intr_list) {
+ chan = usb_dlist_entry(list, struct dwc2_chan, list);
+ urb = chan->urb;
+ if (((frame_number - chan->start_frame) & 0x3FFFU) >= 0x2000U) {
+ continue;
+ }
+ /* Leave remaining polls queued if the ISR has crossed a frame. */
+ if ((usbh_get_frame_number(bus) & 0x3FFFU) != frame_number) {
+ break;
+ }
+ usb_dlist_remove(list);
+ if (urb->hport->speed == USB_SPEED_HIGH) {
+ interval = 1UL << (urb->ep->bInterval - 1U);
+ interval = MIN(interval, 8192U);
+ } else {
+ interval = urb->ep->bInterval;
+ if (chan->do_ssplit) {
+ interval *= 8U;
}
- } else if (chan_intstatus & USB_OTG_HCINT_TXERR) {
- urb->errorcode = -USB_ERR_IO;
- dwc2_urb_waitup(urb);
- } else if (chan_intstatus & USB_OTG_HCINT_BBERR) {
- urb->errorcode = -USB_ERR_BABBLE;
- dwc2_urb_waitup(urb);
- } else if (chan_intstatus & USB_OTG_HCINT_DTERR) {
- urb->errorcode = -USB_ERR_DT;
- dwc2_urb_waitup(urb);
- } else if (chan_intstatus & USB_OTG_HCINT_FRMOR) {
- urb->errorcode = -USB_ERR_IO;
- dwc2_urb_waitup(urb);
}
+ chan->start_frame = (frame_number + interval) & 0x3FFFU;
+ dwc2_bulk_intr_urb_init(bus, chan->chidx, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
+ }
+
+ if (usb_dlist_isempty(&g_dwc2_hcd[bus->hcd.hcd_id].intr_list)) {
+ USB_OTG_GLB->GINTMSK &= ~USB_OTG_GINTMSK_SOFM;
}
}
@@ -1563,5 +1699,8 @@ void USBH_IRQHandler(uint8_t busid)
}
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_HCINT;
}
+ if (gint_status & USB_OTG_GINTSTS_SOF) {
+ dwc2_sof_irq_handler(bus);
+ }
}
}