|
@@ -20,7 +20,6 @@ struct dwc2_chan {
|
|
|
uint32_t xferlen;
|
|
|
uint8_t chidx;
|
|
|
bool inuse;
|
|
|
- bool dir_in;
|
|
|
bool do_ssplit;
|
|
|
bool do_csplit;
|
|
|
uint8_t hub_addr;
|
|
@@ -136,7 +135,12 @@ static inline void dwc2_set_mode(struct usbh_bus *bus, uint8_t mode)
|
|
|
USB_OTG_GLB->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
|
|
|
}
|
|
|
|
|
|
- usb_osal_msleep(50);
|
|
|
+ while (1) {
|
|
|
+ if ((USB_OTG_GLB->GINTSTS & 0x1U) == USB_OTG_MODE_HOST) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ usb_osal_msleep(10);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static inline int dwc2_flush_rxfifo(struct usbh_bus *bus)
|
|
@@ -222,7 +226,14 @@ static inline uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t po
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static inline void dwc2_chan_char_init(struct usbh_bus *bus, uint8_t ch_num, uint8_t devaddr, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps, uint8_t speed)
|
|
|
+static inline void dwc2_chan_char_init(struct usbh_bus *bus,
|
|
|
+ uint8_t ch_num,
|
|
|
+ uint8_t dev_addr,
|
|
|
+ uint8_t ep_addr,
|
|
|
+ uint8_t ep_type,
|
|
|
+ uint16_t ep_mps,
|
|
|
+ uint8_t ep_mult,
|
|
|
+ uint8_t speed)
|
|
|
{
|
|
|
uint32_t regval;
|
|
|
|
|
@@ -230,7 +241,8 @@ static inline void dwc2_chan_char_init(struct usbh_bus *bus, uint8_t ch_num, uin
|
|
|
regval = (((uint32_t)ep_mps << USB_OTG_HCCHAR_MPSIZ_Pos) & USB_OTG_HCCHAR_MPSIZ) |
|
|
|
((((uint32_t)ep_addr & 0x7FU) << USB_OTG_HCCHAR_EPNUM_Pos) & USB_OTG_HCCHAR_EPNUM) |
|
|
|
(((uint32_t)ep_type << USB_OTG_HCCHAR_EPTYP_Pos) & USB_OTG_HCCHAR_EPTYP) |
|
|
|
- (((uint32_t)devaddr << USB_OTG_HCCHAR_DAD_Pos) & USB_OTG_HCCHAR_DAD);
|
|
|
+ (((uint32_t)ep_mult << USB_OTG_HCCHAR_MC_Pos) & USB_OTG_HCCHAR_MC) |
|
|
|
+ (((uint32_t)dev_addr << USB_OTG_HCCHAR_DAD_Pos) & USB_OTG_HCCHAR_DAD);
|
|
|
|
|
|
if ((ep_addr & 0x80U) == 0x80U) {
|
|
|
regval |= USB_OTG_HCCHAR_EPDIR;
|
|
@@ -272,7 +284,14 @@ static inline void dwc2_chan_splt_init(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void dwc2_chan_init(struct usbh_bus *bus, uint8_t ch_num, uint8_t devaddr, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps, uint8_t speed)
|
|
|
+static void dwc2_chan_init(struct usbh_bus *bus,
|
|
|
+ uint8_t ch_num,
|
|
|
+ uint8_t dev_addr,
|
|
|
+ uint8_t ep_addr,
|
|
|
+ uint8_t ep_type,
|
|
|
+ uint16_t ep_mps,
|
|
|
+ uint8_t ep_mult,
|
|
|
+ uint8_t speed)
|
|
|
{
|
|
|
/* Clear old interrupt conditions for this host channel. */
|
|
|
USB_OTG_HC((uint32_t)ch_num)->HCINT = 0xFFFFFFFFU;
|
|
@@ -283,33 +302,47 @@ static void dwc2_chan_init(struct usbh_bus *bus, uint8_t ch_num, uint8_t devaddr
|
|
|
/* Enable the top level host channel interrupt. */
|
|
|
USB_OTG_HOST->HAINTMSK |= 1UL << (ch_num & 0xFU);
|
|
|
|
|
|
- dwc2_chan_char_init(bus, ch_num, devaddr, ep_addr, ep_type, ep_mps, speed);
|
|
|
+ dwc2_chan_char_init(bus, ch_num, dev_addr, ep_addr, ep_type, ep_mps, ep_mult, speed);
|
|
|
dwc2_chan_splt_init(bus, ch_num);
|
|
|
}
|
|
|
|
|
|
-/* For IN channel HCTSIZ.XferSize is expected to be an integer multiple of ep_mps size.*/
|
|
|
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;
|
|
|
- struct dwc2_chan *chan;
|
|
|
-
|
|
|
- chan = &g_dwc2_hcd[bus->hcd.hcd_id].chan_pool[ch_num];
|
|
|
|
|
|
/* Initialize the HCTSIZn register */
|
|
|
USB_OTG_HC(ch_num)->HCTSIZ = (size & USB_OTG_HCTSIZ_XFRSIZ) |
|
|
|
(((uint32_t)num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |
|
|
|
(((uint32_t)pid << 29) & USB_OTG_HCTSIZ_DPID);
|
|
|
|
|
|
- if (!(ep_addr & 0x80)) {
|
|
|
- chan->dir_in = false;
|
|
|
- usb_dcache_clean((uintptr_t)buf, USB_ALIGN_UP(size, CONFIG_USB_ALIGN_SIZE));
|
|
|
+ /* xfer_buff MUST be 32-bits aligned */
|
|
|
+ USB_OTG_HC(ch_num)->HCDMA = (uint32_t)buf;
|
|
|
+
|
|
|
+ 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;
|
|
|
+
|
|
|
+ /* Set host channel enable */
|
|
|
+ tmpreg = USB_OTG_HC(ch_num)->HCCHAR;
|
|
|
+ tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
|
|
|
+ tmpreg |= USB_OTG_HCCHAR_CHENA;
|
|
|
+ USB_OTG_HC(ch_num)->HCCHAR = tmpreg;
|
|
|
+}
|
|
|
+
|
|
|
+static inline void dwc2_chan_enable_csplit(struct usbh_bus *bus, uint8_t ch_num, bool enable)
|
|
|
+{
|
|
|
+ if (enable) {
|
|
|
+ USB_OTG_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_COMPLSPLT;
|
|
|
} else {
|
|
|
- chan->dir_in = true;
|
|
|
+ USB_OTG_HC((uint32_t)ch_num)->HCSPLT &= ~USB_OTG_HCSPLT_COMPLSPLT;
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- /* xfer_buff MUST be 32-bits aligned */
|
|
|
- USB_OTG_HC(ch_num)->HCDMA = (uint32_t)buf;
|
|
|
+static inline void dwc2_chan_reenable(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
+{
|
|
|
+ __IO uint32_t tmpreg;
|
|
|
+ uint8_t is_oddframe;
|
|
|
|
|
|
is_oddframe = (((uint32_t)USB_OTG_HOST->HFNUM & 0x01U) != 0U) ? 0U : 1U;
|
|
|
USB_OTG_HC(ch_num)->HCCHAR &= ~USB_OTG_HCCHAR_ODDFRM;
|
|
@@ -338,7 +371,6 @@ static void dwc2_halt(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
value = USB_OTG_HC(ch_num)->HCCHAR;
|
|
|
value |= USB_OTG_HCCHAR_CHDIS;
|
|
|
value |= USB_OTG_HCCHAR_CHENA;
|
|
|
- value &= ~USB_OTG_HCCHAR_EPDIR;
|
|
|
USB_OTG_HC(ch_num)->HCCHAR = value;
|
|
|
do {
|
|
|
if (++count > 200000U) {
|
|
@@ -352,6 +384,7 @@ static void dwc2_halt(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
static int usbh_reset_port(struct usbh_bus *bus, const uint8_t port)
|
|
|
{
|
|
|
__IO uint32_t hprt0 = 0U;
|
|
|
+ volatile uint32_t timeout = 0;
|
|
|
|
|
|
hprt0 = USB_OTG_HPRT;
|
|
|
|
|
@@ -364,6 +397,14 @@ static int usbh_reset_port(struct usbh_bus *bus, const uint8_t port)
|
|
|
usb_osal_msleep(10U);
|
|
|
|
|
|
while (!(USB_OTG_HPRT & USB_OTG_HPRT_PENA)) {
|
|
|
+ if (!(USB_OTG_HPRT & USB_OTG_HPRT_PCSTS)) {
|
|
|
+ return -USB_ERR_NOTCONN; /* Port not connected */
|
|
|
+ }
|
|
|
+ timeout++;
|
|
|
+ if (timeout > 10) {
|
|
|
+ USB_LOG_ERR("Reset port timeout\r\n");
|
|
|
+ return -USB_ERR_TIMEOUT;
|
|
|
+ }
|
|
|
usb_osal_msleep(10U);
|
|
|
}
|
|
|
return 0;
|
|
@@ -463,6 +504,10 @@ static void dwc2_chan_free(struct dwc2_chan *chan)
|
|
|
size_t flags;
|
|
|
|
|
|
flags = usb_osal_enter_critical_section();
|
|
|
+ if (chan->urb) {
|
|
|
+ chan->urb->hcpriv = NULL;
|
|
|
+ chan->urb = NULL;
|
|
|
+ }
|
|
|
chan->inuse = false;
|
|
|
usb_osal_leave_critical_section(flags);
|
|
|
}
|
|
@@ -519,27 +564,62 @@ static void dwc2_control_urb_init(struct usbh_bus *bus, uint8_t chidx, struct us
|
|
|
if (chan->ep0_state == DWC2_EP0_STATE_SETUP) /* fill setup */
|
|
|
{
|
|
|
chan->num_packets = dwc2_calculate_packet_num(8, 0x00, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), &chan->xferlen);
|
|
|
- dwc2_chan_init(bus, chidx, urb->hport->dev_addr, 0x00, USB_ENDPOINT_TYPE_CONTROL, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), urb->hport->speed);
|
|
|
+ dwc2_chan_init(bus,
|
|
|
+ chidx,
|
|
|
+ urb->hport->dev_addr,
|
|
|
+ 0x00,
|
|
|
+ USB_ENDPOINT_TYPE_CONTROL,
|
|
|
+ USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize),
|
|
|
+ 1,
|
|
|
+ urb->hport->speed);
|
|
|
dwc2_chan_transfer(bus, chidx, 0x00, (uint8_t *)setup, chan->xferlen, chan->num_packets, HC_PID_SETUP);
|
|
|
} else if (chan->ep0_state == DWC2_EP0_STATE_INDATA) /* fill in data */
|
|
|
{
|
|
|
chan->num_packets = dwc2_calculate_packet_num(datalen, 0x80, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), &chan->xferlen);
|
|
|
- dwc2_chan_init(bus, chidx, urb->hport->dev_addr, 0x80, USB_ENDPOINT_TYPE_CONTROL, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), urb->hport->speed);
|
|
|
+ dwc2_chan_init(bus,
|
|
|
+ chidx,
|
|
|
+ urb->hport->dev_addr,
|
|
|
+ 0x80,
|
|
|
+ USB_ENDPOINT_TYPE_CONTROL,
|
|
|
+ USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize),
|
|
|
+ 1,
|
|
|
+ urb->hport->speed);
|
|
|
dwc2_chan_transfer(bus, chidx, 0x80, buffer, chan->xferlen, chan->num_packets, data_pid);
|
|
|
} else if (chan->ep0_state == DWC2_EP0_STATE_OUTDATA) /* fill out data */
|
|
|
{
|
|
|
chan->num_packets = dwc2_calculate_packet_num(datalen, 0x00, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), &chan->xferlen);
|
|
|
- dwc2_chan_init(bus, chidx, urb->hport->dev_addr, 0x00, USB_ENDPOINT_TYPE_CONTROL, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), urb->hport->speed);
|
|
|
+ dwc2_chan_init(bus,
|
|
|
+ chidx,
|
|
|
+ urb->hport->dev_addr,
|
|
|
+ 0x00,
|
|
|
+ USB_ENDPOINT_TYPE_CONTROL,
|
|
|
+ USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize),
|
|
|
+ 1,
|
|
|
+ urb->hport->speed);
|
|
|
dwc2_chan_transfer(bus, chidx, 0x00, buffer, chan->xferlen, chan->num_packets, data_pid);
|
|
|
} else if (chan->ep0_state == DWC2_EP0_STATE_INSTATUS) /* fill in status */
|
|
|
{
|
|
|
chan->num_packets = dwc2_calculate_packet_num(0, 0x80, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), &chan->xferlen);
|
|
|
- dwc2_chan_init(bus, chidx, urb->hport->dev_addr, 0x80, USB_ENDPOINT_TYPE_CONTROL, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), urb->hport->speed);
|
|
|
+ dwc2_chan_init(bus,
|
|
|
+ chidx,
|
|
|
+ urb->hport->dev_addr,
|
|
|
+ 0x80,
|
|
|
+ USB_ENDPOINT_TYPE_CONTROL,
|
|
|
+ USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize),
|
|
|
+ 1,
|
|
|
+ urb->hport->speed);
|
|
|
dwc2_chan_transfer(bus, chidx, 0x80, NULL, chan->xferlen, chan->num_packets, HC_PID_DATA1);
|
|
|
} else if (chan->ep0_state == DWC2_EP0_STATE_OUTSTATUS) /* fill out status */
|
|
|
{
|
|
|
chan->num_packets = dwc2_calculate_packet_num(0, 0x00, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), &chan->xferlen);
|
|
|
- dwc2_chan_init(bus, chidx, urb->hport->dev_addr, 0x00, USB_ENDPOINT_TYPE_CONTROL, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), urb->hport->speed);
|
|
|
+ dwc2_chan_init(bus,
|
|
|
+ chidx,
|
|
|
+ urb->hport->dev_addr,
|
|
|
+ 0x00,
|
|
|
+ USB_ENDPOINT_TYPE_CONTROL,
|
|
|
+ USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize),
|
|
|
+ 1,
|
|
|
+ urb->hport->speed);
|
|
|
dwc2_chan_transfer(bus, chidx, 0x00, NULL, chan->xferlen, chan->num_packets, HC_PID_DATA1);
|
|
|
}
|
|
|
}
|
|
@@ -562,7 +642,14 @@ static void dwc2_bulk_intr_urb_init(struct usbh_bus *bus, uint8_t chidx, struct
|
|
|
}
|
|
|
|
|
|
chan->num_packets = dwc2_calculate_packet_num(datalen, urb->ep->bEndpointAddress, USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), &chan->xferlen);
|
|
|
- dwc2_chan_init(bus, chidx, urb->hport->dev_addr, urb->ep->bEndpointAddress, USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes), USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize), urb->hport->speed);
|
|
|
+ dwc2_chan_init(bus,
|
|
|
+ chidx,
|
|
|
+ urb->hport->dev_addr,
|
|
|
+ urb->ep->bEndpointAddress,
|
|
|
+ USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes),
|
|
|
+ USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize),
|
|
|
+ USB_GET_MULT(urb->ep->wMaxPacketSize) + 1,
|
|
|
+ urb->hport->speed);
|
|
|
dwc2_chan_transfer(bus, chidx, urb->ep->bEndpointAddress, buffer, chan->xferlen, chan->num_packets, urb->data_toggle == 0 ? HC_PID_DATA0 : HC_PID_DATA1);
|
|
|
}
|
|
|
|
|
@@ -845,8 +932,7 @@ int usbh_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, u
|
|
|
dwc2_drivebus(bus, 1);
|
|
|
break;
|
|
|
case HUB_PORT_FEATURE_RESET:
|
|
|
- usbh_reset_port(bus, port);
|
|
|
- break;
|
|
|
+ return usbh_reset_port(bus, port);
|
|
|
|
|
|
default:
|
|
|
return -USB_ERR_NOTSUPP;
|
|
@@ -930,11 +1016,6 @@ int usbh_submit_urb(struct usbh_urb *urb)
|
|
|
return -USB_ERR_BUSY;
|
|
|
}
|
|
|
|
|
|
- chidx = dwc2_chan_alloc(bus);
|
|
|
- if (chidx == -1) {
|
|
|
- return -USB_ERR_NOMEM;
|
|
|
- }
|
|
|
-
|
|
|
if (urb->ep->bEndpointAddress & 0x80) {
|
|
|
/* Check if pipe rx fifo is overflow */
|
|
|
if (USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize) > (g_dwc2_hcd[bus->hcd.hcd_id].user_params.host_rx_fifo_size * 4)) {
|
|
@@ -954,6 +1035,11 @@ int usbh_submit_urb(struct usbh_urb *urb)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ chidx = dwc2_chan_alloc(bus);
|
|
|
+ if (chidx == -1) {
|
|
|
+ return -USB_ERR_NOMEM;
|
|
|
+ }
|
|
|
+
|
|
|
flags = usb_osal_enter_critical_section();
|
|
|
|
|
|
chan = &g_dwc2_hcd[bus->hcd.hcd_id].chan_pool[chidx];
|
|
@@ -975,6 +1061,25 @@ int usbh_submit_urb(struct usbh_urb *urb)
|
|
|
|
|
|
usb_osal_leave_critical_section(flags);
|
|
|
|
|
|
+ if (urb->setup) {
|
|
|
+ usb_dcache_clean((uintptr_t)urb->setup, USB_ALIGN_UP(sizeof(struct usb_setup_packet), CONFIG_USB_ALIGN_SIZE));
|
|
|
+
|
|
|
+ if (urb->transfer_buffer) {
|
|
|
+ if (urb->setup->bmRequestType & 0x80) {
|
|
|
+ usb_dcache_invalidate((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE));
|
|
|
+ } else {
|
|
|
+ usb_dcache_clean((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (urb->transfer_buffer && (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) != USB_ENDPOINT_TYPE_ISOCHRONOUS)) {
|
|
|
+ if (urb->ep->bEndpointAddress & 0x80) {
|
|
|
+ usb_dcache_invalidate((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE));
|
|
|
+ } else {
|
|
|
+ usb_dcache_clean((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+
|
|
|
switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
|
|
|
case USB_ENDPOINT_TYPE_CONTROL:
|
|
|
chan->ep0_state = DWC2_EP0_STATE_SETUP;
|
|
@@ -1026,8 +1131,6 @@ int usbh_kill_urb(struct usbh_urb *urb)
|
|
|
|
|
|
dwc2_halt(bus, chan->chidx);
|
|
|
|
|
|
- chan->urb = NULL;
|
|
|
- urb->hcpriv = NULL;
|
|
|
urb->errorcode = -USB_ERR_SHUTDOWN;
|
|
|
|
|
|
if (urb->timeout) {
|
|
@@ -1036,6 +1139,10 @@ int usbh_kill_urb(struct usbh_urb *urb)
|
|
|
dwc2_chan_free(chan);
|
|
|
}
|
|
|
|
|
|
+ if (urb->complete) {
|
|
|
+ urb->complete(urb->arg, urb->errorcode);
|
|
|
+ }
|
|
|
+
|
|
|
usb_osal_leave_critical_section(flags);
|
|
|
|
|
|
return 0;
|
|
@@ -1046,8 +1153,6 @@ static inline void dwc2_urb_waitup(struct usbh_urb *urb)
|
|
|
struct dwc2_chan *chan;
|
|
|
|
|
|
chan = (struct dwc2_chan *)urb->hcpriv;
|
|
|
- chan->urb = NULL;
|
|
|
- urb->hcpriv = NULL;
|
|
|
|
|
|
if (urb->timeout) {
|
|
|
usb_osal_sem_give(chan->waitsem);
|
|
@@ -1079,31 +1184,26 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
if (chan_intstatus & USB_OTG_HCINT_CHH) {
|
|
|
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
|
|
|
if (chan_intstatus & USB_OTG_HCINT_XFRC) {
|
|
|
- urb->errorcode = 0;
|
|
|
-
|
|
|
uint32_t count = chan->xferlen - (USB_OTG_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_XFRSIZ); /* how many size has received */
|
|
|
- //uint32_t has_used_packets = chan->num_packets - ((USB_OTG_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) >> 19); /* how many packets have used */
|
|
|
+ uint8_t data_toggle = ((USB_OTG_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_DPID) >> USB_OTG_HCTSIZ_DPID_Pos);
|
|
|
|
|
|
urb->actual_length += count;
|
|
|
urb->transfer_buffer_length -= count;
|
|
|
|
|
|
- uint8_t data_toggle = ((USB_OTG_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_DPID) >> USB_OTG_HCTSIZ_DPID_Pos);
|
|
|
-
|
|
|
if (data_toggle == HC_PID_DATA0) {
|
|
|
urb->data_toggle = 0;
|
|
|
} else {
|
|
|
urb->data_toggle = 1;
|
|
|
}
|
|
|
|
|
|
- if (chan->dir_in) {
|
|
|
- usb_dcache_invalidate((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(count, CONFIG_USB_ALIGN_SIZE));
|
|
|
+ if (chan->do_csplit) {
|
|
|
+ chan->do_csplit = 0;
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, false);
|
|
|
}
|
|
|
|
|
|
- chan->do_csplit = 0;
|
|
|
-
|
|
|
if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_CONTROL) {
|
|
|
if (chan->ep0_state == DWC2_EP0_STATE_INDATA) {
|
|
|
- if (chan->do_ssplit && urb->transfer_buffer_length > 0) {
|
|
|
+ if (chan->do_ssplit && urb->transfer_buffer_length > 0 && (count == USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize))) {
|
|
|
dwc2_control_urb_init(bus, ch_num, urb, urb->setup, urb->transfer_buffer + urb->actual_length - 8, urb->transfer_buffer_length);
|
|
|
} else {
|
|
|
chan->ep0_state = DWC2_EP0_STATE_OUTSTATUS;
|
|
@@ -1111,6 +1211,7 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
}
|
|
|
} else if (chan->ep0_state == DWC2_EP0_STATE_INSTATUS) {
|
|
|
chan->ep0_state = DWC2_EP0_STATE_SETUP;
|
|
|
+ urb->errorcode = 0;
|
|
|
dwc2_urb_waitup(urb);
|
|
|
}
|
|
|
} else if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
|
@@ -1118,6 +1219,8 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
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));
|
|
|
+ urb->errorcode = 0;
|
|
|
dwc2_urb_waitup(urb);
|
|
|
}
|
|
|
}
|
|
@@ -1129,20 +1232,20 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
dwc2_urb_waitup(urb);
|
|
|
} else if (chan_intstatus & USB_OTG_HCINT_NAK) {
|
|
|
if (chan->do_ssplit) {
|
|
|
- /*
|
|
|
- * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
|
|
|
- * interrupt. Re-start the SSPLIT transfer.
|
|
|
- */
|
|
|
+ /* restart ssplit transfer */
|
|
|
switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
|
|
|
case USB_ENDPOINT_TYPE_CONTROL:
|
|
|
+ case USB_ENDPOINT_TYPE_BULK:
|
|
|
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);
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, false);
|
|
|
+ dwc2_chan_reenable(bus, ch_num);
|
|
|
break;
|
|
|
- case USB_ENDPOINT_TYPE_BULK:
|
|
|
case USB_ENDPOINT_TYPE_INTERRUPT:
|
|
|
- chan->do_csplit = 0;
|
|
|
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, false);
|
|
|
+ urb->errorcode = -USB_ERR_NAK;
|
|
|
+ dwc2_urb_waitup(urb);
|
|
|
break;
|
|
|
+
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -1152,46 +1255,17 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
}
|
|
|
} else if (chan_intstatus & USB_OTG_HCINT_ACK) {
|
|
|
if (chan->do_ssplit) {
|
|
|
- /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */
|
|
|
- switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
|
|
|
- case USB_ENDPOINT_TYPE_CONTROL:
|
|
|
- chan->do_csplit = 1;
|
|
|
- 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:
|
|
|
- //printf("intr ack, len:%d\r\n", urb->actual_length);
|
|
|
- chan->do_csplit = 1;
|
|
|
- chan->ssplit_frame = dwc2_get_full_frame_num(bus);
|
|
|
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+ /* start ssplit transfer */
|
|
|
+ chan->do_csplit = 1;
|
|
|
+ chan->ssplit_frame = dwc2_get_full_frame_num(bus);
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, true);
|
|
|
+ dwc2_chan_reenable(bus, ch_num);
|
|
|
}
|
|
|
} else if (chan_intstatus & USB_OTG_HCINT_NYET) {
|
|
|
if (chan->do_ssplit) {
|
|
|
- /*
|
|
|
- * NYET on CSPLIT
|
|
|
- * re-do the CSPLIT immediately on non-periodic
|
|
|
- */
|
|
|
- switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
|
|
|
- case USB_ENDPOINT_TYPE_CONTROL:
|
|
|
- chan->do_csplit = 1;
|
|
|
- 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:
|
|
|
- if ((dwc2_get_full_frame_num(bus) - chan->ssplit_frame) > 4) {
|
|
|
- chan->do_csplit = 0;
|
|
|
- } else {
|
|
|
- chan->do_csplit = 1;
|
|
|
- }
|
|
|
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+ /* restart csplit transfer */
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, true);
|
|
|
+ dwc2_chan_reenable(bus, ch_num);
|
|
|
} else {
|
|
|
urb->errorcode = -USB_ERR_NAK;
|
|
|
dwc2_urb_waitup(urb);
|
|
@@ -1227,12 +1301,11 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
if (chan_intstatus & USB_OTG_HCINT_CHH) {
|
|
|
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
|
|
|
if (chan_intstatus & USB_OTG_HCINT_XFRC) {
|
|
|
- urb->errorcode = 0;
|
|
|
-
|
|
|
uint32_t count = USB_OTG_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_XFRSIZ; /* last packet size */
|
|
|
uint32_t has_used_packets = chan->num_packets - ((USB_OTG_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) >> 19); /* how many packets have used */
|
|
|
+ uint32_t olen = (has_used_packets - 1) * USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize) + count; /* the same with urb->actual_length += chan->xferlen; */
|
|
|
+ uint8_t data_toggle = ((USB_OTG_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_DPID) >> USB_OTG_HCTSIZ_DPID_Pos);
|
|
|
|
|
|
- uint32_t olen = (has_used_packets - 1) * USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize) + count; //the same with urb->actual_length += chan->xferlen;
|
|
|
urb->actual_length += olen;
|
|
|
|
|
|
if (chan->ep0_state == DWC2_EP0_STATE_OUTDATA || urb->setup == NULL) {
|
|
@@ -1243,15 +1316,16 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- uint8_t data_toggle = ((USB_OTG_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_DPID) >> USB_OTG_HCTSIZ_DPID_Pos);
|
|
|
-
|
|
|
if (data_toggle == HC_PID_DATA0) {
|
|
|
urb->data_toggle = 0;
|
|
|
} else {
|
|
|
urb->data_toggle = 1;
|
|
|
}
|
|
|
|
|
|
- chan->do_csplit = 0;
|
|
|
+ if (chan->do_csplit) {
|
|
|
+ chan->do_csplit = 0;
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, false);
|
|
|
+ }
|
|
|
|
|
|
if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_CONTROL) {
|
|
|
if (chan->ep0_state == DWC2_EP0_STATE_SETUP) {
|
|
@@ -1273,7 +1347,9 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
dwc2_control_urb_init(bus, ch_num, urb, urb->setup, urb->transfer_buffer, urb->transfer_buffer_length);
|
|
|
}
|
|
|
} else if (chan->ep0_state == DWC2_EP0_STATE_OUTSTATUS) {
|
|
|
+ usb_dcache_invalidate((uintptr_t)urb->transfer_buffer, USB_ALIGN_UP(urb->actual_length - 8, CONFIG_USB_ALIGN_SIZE));
|
|
|
chan->ep0_state = DWC2_EP0_STATE_SETUP;
|
|
|
+ urb->errorcode = 0;
|
|
|
dwc2_urb_waitup(urb);
|
|
|
}
|
|
|
} else if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
|
@@ -1281,6 +1357,7 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
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;
|
|
|
dwc2_urb_waitup(urb);
|
|
|
}
|
|
|
}
|
|
@@ -1292,20 +1369,20 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
dwc2_urb_waitup(urb);
|
|
|
} else if (chan_intstatus & USB_OTG_HCINT_NAK) {
|
|
|
if (chan->do_ssplit) {
|
|
|
- /*
|
|
|
- * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
|
|
|
- * interrupt. Re-start the SSPLIT transfer.
|
|
|
- */
|
|
|
+ /* restart ssplit transfer */
|
|
|
switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
|
|
|
case USB_ENDPOINT_TYPE_CONTROL:
|
|
|
+ case USB_ENDPOINT_TYPE_BULK:
|
|
|
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);
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, false);
|
|
|
+ dwc2_chan_reenable(bus, ch_num);
|
|
|
break;
|
|
|
- case USB_ENDPOINT_TYPE_BULK:
|
|
|
case USB_ENDPOINT_TYPE_INTERRUPT:
|
|
|
- chan->do_csplit = 0;
|
|
|
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, false);
|
|
|
+ urb->errorcode = -USB_ERR_NAK;
|
|
|
+ dwc2_urb_waitup(urb);
|
|
|
break;
|
|
|
+
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -1315,45 +1392,17 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
|
|
|
}
|
|
|
} else if (chan_intstatus & USB_OTG_HCINT_ACK) {
|
|
|
if (chan->do_ssplit) {
|
|
|
- /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */
|
|
|
- switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
|
|
|
- case USB_ENDPOINT_TYPE_CONTROL:
|
|
|
- chan->do_csplit = 1;
|
|
|
- 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:
|
|
|
- chan->do_csplit = 1;
|
|
|
- chan->ssplit_frame = dwc2_get_full_frame_num(bus);
|
|
|
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+ /* start ssplit transfer */
|
|
|
+ chan->do_csplit = 1;
|
|
|
+ chan->ssplit_frame = dwc2_get_full_frame_num(bus);
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, true);
|
|
|
+ dwc2_chan_reenable(bus, ch_num);
|
|
|
}
|
|
|
} else if (chan_intstatus & USB_OTG_HCINT_NYET) {
|
|
|
if (chan->do_ssplit) {
|
|
|
- /*
|
|
|
- * NYET on CSPLIT
|
|
|
- * re-do the CSPLIT immediately on non-periodic
|
|
|
- */
|
|
|
- switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
|
|
|
- case USB_ENDPOINT_TYPE_CONTROL:
|
|
|
- chan->do_csplit = 1;
|
|
|
- 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:
|
|
|
- if ((dwc2_get_full_frame_num(bus) - chan->ssplit_frame) > 4) {
|
|
|
- chan->do_csplit = 0;
|
|
|
- } else {
|
|
|
- chan->do_csplit = 1;
|
|
|
- }
|
|
|
- dwc2_bulk_intr_urb_init(bus, ch_num, urb, urb->transfer_buffer + urb->actual_length, urb->transfer_buffer_length);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+ /* restart csplit transfer */
|
|
|
+ dwc2_chan_enable_csplit(bus, ch_num, true);
|
|
|
+ dwc2_chan_reenable(bus, ch_num);
|
|
|
} else {
|
|
|
urb->errorcode = -USB_ERR_NAK;
|
|
|
dwc2_urb_waitup(urb);
|