|
|
@@ -2,6 +2,7 @@
|
|
|
* The MIT License (MIT)
|
|
|
*
|
|
|
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
|
|
+ * Copyright (c) 2021 Ha Thach (tinyusb.org) for Double Buffered
|
|
|
*
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
@@ -43,42 +44,38 @@ static inline void _hw_endpoint_lock_update(struct hw_endpoint *ep, int delta) {
|
|
|
// sense to have worker and IRQ on same core, however I think using critsec is about equivalent.
|
|
|
}
|
|
|
|
|
|
-#if TUSB_OPT_HOST_ENABLED
|
|
|
-static inline void _hw_endpoint_update_last_buf(struct hw_endpoint *ep)
|
|
|
-{
|
|
|
- ep->last_buf = (ep->len + ep->transfer_size == ep->total_len);
|
|
|
-}
|
|
|
-#endif
|
|
|
+static void _hw_endpoint_xfer_sync(struct hw_endpoint *ep);
|
|
|
+static void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep);
|
|
|
+
|
|
|
+//--------------------------------------------------------------------+
|
|
|
+//
|
|
|
+//--------------------------------------------------------------------+
|
|
|
|
|
|
void rp2040_usb_init(void)
|
|
|
{
|
|
|
- // Reset usb controller
|
|
|
- reset_block(RESETS_RESET_USBCTRL_BITS);
|
|
|
- unreset_block_wait(RESETS_RESET_USBCTRL_BITS);
|
|
|
+ // Reset usb controller
|
|
|
+ reset_block(RESETS_RESET_USBCTRL_BITS);
|
|
|
+ unreset_block_wait(RESETS_RESET_USBCTRL_BITS);
|
|
|
|
|
|
- // Clear any previous state just in case
|
|
|
- memset(usb_hw, 0, sizeof(*usb_hw));
|
|
|
- memset(usb_dpram, 0, sizeof(*usb_dpram));
|
|
|
+ // Clear any previous state just in case
|
|
|
+ memset(usb_hw, 0, sizeof(*usb_hw));
|
|
|
+ memset(usb_dpram, 0, sizeof(*usb_dpram));
|
|
|
|
|
|
- // Mux the controller to the onboard usb phy
|
|
|
- usb_hw->muxing = USB_USB_MUXING_TO_PHY_BITS | USB_USB_MUXING_SOFTCON_BITS;
|
|
|
+ // Mux the controller to the onboard usb phy
|
|
|
+ usb_hw->muxing = USB_USB_MUXING_TO_PHY_BITS | USB_USB_MUXING_SOFTCON_BITS;
|
|
|
|
|
|
- // Force VBUS detect so the device thinks it is plugged into a host
|
|
|
- // TODO support VBUs detect
|
|
|
- usb_hw->pwr = USB_USB_PWR_VBUS_DETECT_BITS | USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN_BITS;
|
|
|
+ // Force VBUS detect so the device thinks it is plugged into a host
|
|
|
+ // TODO support VBUs detect
|
|
|
+ usb_hw->pwr = USB_USB_PWR_VBUS_DETECT_BITS | USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN_BITS;
|
|
|
}
|
|
|
|
|
|
void hw_endpoint_reset_transfer(struct hw_endpoint *ep)
|
|
|
{
|
|
|
- ep->stalled = false;
|
|
|
- ep->active = false;
|
|
|
-#if TUSB_OPT_HOST_ENABLED
|
|
|
- ep->sent_setup = false;
|
|
|
-#endif
|
|
|
- ep->total_len = 0;
|
|
|
- ep->len = 0;
|
|
|
- ep->transfer_size = 0;
|
|
|
- ep->user_buf = 0;
|
|
|
+ ep->stalled = false;
|
|
|
+ ep->active = false;
|
|
|
+ ep->remaining_len = 0;
|
|
|
+ ep->xferred_len = 0;
|
|
|
+ ep->user_buf = 0;
|
|
|
}
|
|
|
|
|
|
void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask) {
|
|
|
@@ -111,215 +108,223 @@ void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_m
|
|
|
*ep->buffer_control = value;
|
|
|
}
|
|
|
|
|
|
-void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep)
|
|
|
+// prepare buffer, return buffer control
|
|
|
+static uint32_t prepare_ep_buffer(struct hw_endpoint *ep, uint8_t buf_id)
|
|
|
{
|
|
|
- // Prepare buffer control register value
|
|
|
- uint32_t val = ep->transfer_size | USB_BUF_CTRL_AVAIL;
|
|
|
-
|
|
|
- if (!ep->rx)
|
|
|
- {
|
|
|
- // Copy data from user buffer to hw buffer
|
|
|
- memcpy(ep->hw_data_buf, &ep->user_buf[ep->len], ep->transfer_size);
|
|
|
- // Mark as full
|
|
|
- val |= USB_BUF_CTRL_FULL;
|
|
|
- }
|
|
|
+ uint16_t const buflen = tu_min16(ep->remaining_len, ep->wMaxPacketSize);
|
|
|
+ ep->remaining_len -= buflen;
|
|
|
|
|
|
- // PID
|
|
|
- val |= ep->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID;
|
|
|
+ uint32_t buf_ctrl = buflen | USB_BUF_CTRL_AVAIL;
|
|
|
|
|
|
-#if TUSB_OPT_DEVICE_ENABLED
|
|
|
- ep->next_pid ^= 1u;
|
|
|
+ // PID
|
|
|
+ buf_ctrl |= ep->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID;
|
|
|
+ ep->next_pid ^= 1u;
|
|
|
|
|
|
-#else
|
|
|
- // For Host (also device but since we dictate the endpoint size, following scenario does not occur)
|
|
|
- // Next PID depends on the number of packet in case wMaxPacketSize < 64 (e.g Interrupt Endpoint 8, or 12)
|
|
|
- // Special case with control status stage where PID is always DATA1
|
|
|
- if ( ep->transfer_size == 0 )
|
|
|
- {
|
|
|
- // ZLP also toggle data
|
|
|
- ep->next_pid ^= 1u;
|
|
|
- }else
|
|
|
- {
|
|
|
- uint32_t packet_count = 1 + ((ep->transfer_size - 1) / ep->wMaxPacketSize);
|
|
|
+ if ( !ep->rx )
|
|
|
+ {
|
|
|
+ // Copy data from user buffer to hw buffer
|
|
|
+ memcpy(ep->hw_data_buf + buf_id*64, ep->user_buf, buflen);
|
|
|
+ ep->user_buf += buflen;
|
|
|
|
|
|
- if ( packet_count & 0x01 )
|
|
|
- {
|
|
|
- ep->next_pid ^= 1u;
|
|
|
- }
|
|
|
- }
|
|
|
-#endif
|
|
|
+ // Mark as full
|
|
|
+ buf_ctrl |= USB_BUF_CTRL_FULL;
|
|
|
+ }
|
|
|
|
|
|
+ // Is this the last buffer? Only really matters for host mode. Will trigger
|
|
|
+ // the trans complete irq but also stop it polling. We only really care about
|
|
|
+ // trans complete for setup packets being sent
|
|
|
+ if (ep->remaining_len == 0)
|
|
|
+ {
|
|
|
+ buf_ctrl |= USB_BUF_CTRL_LAST;
|
|
|
+ }
|
|
|
|
|
|
-#if TUSB_OPT_HOST_ENABLED
|
|
|
- // Is this the last buffer? Only really matters for host mode. Will trigger
|
|
|
- // the trans complete irq but also stop it polling. We only really care about
|
|
|
- // trans complete for setup packets being sent
|
|
|
- if (ep->last_buf)
|
|
|
- {
|
|
|
- pico_trace("Last buf (%d bytes left)\n", ep->transfer_size);
|
|
|
- val |= USB_BUF_CTRL_LAST;
|
|
|
- }
|
|
|
-#endif
|
|
|
+ if (buf_id) buf_ctrl = buf_ctrl << 16;
|
|
|
|
|
|
- // Finally, write to buffer_control which will trigger the transfer
|
|
|
- // the next time the controller polls this dpram address
|
|
|
- _hw_endpoint_buffer_control_set_value32(ep, val);
|
|
|
- pico_trace("buffer control (0x%p) <- 0x%x\n", ep->buffer_control, val);
|
|
|
- //print_bufctrl16(val);
|
|
|
+ return buf_ctrl;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void _hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t total_len)
|
|
|
+// Prepare buffer control register value
|
|
|
+static void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep)
|
|
|
{
|
|
|
- _hw_endpoint_lock_update(ep, 1);
|
|
|
- pico_trace("Start transfer of total len %d on ep %d %s\n", total_len, tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
|
|
|
- if (ep->active)
|
|
|
- {
|
|
|
- // TODO: Is this acceptable for interrupt packets?
|
|
|
- pico_warn("WARN: starting new transfer on already active ep %d %s\n", tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
|
|
|
+ uint32_t ep_ctrl = *ep->endpoint_control;
|
|
|
|
|
|
- hw_endpoint_reset_transfer(ep);
|
|
|
- }
|
|
|
+ // always compute and start with buffer 0
|
|
|
+ uint32_t buf_ctrl = prepare_ep_buffer(ep, 0) | USB_BUF_CTRL_SEL;
|
|
|
|
|
|
- // Fill in info now that we're kicking off the hw
|
|
|
- ep->total_len = total_len;
|
|
|
- ep->len = 0;
|
|
|
+ // For now: skip double buffered for Device mode, OUT endpoint since
|
|
|
+ // host could send < 64 bytes and cause short packet on buffer0
|
|
|
+ // NOTE this could happen to Host mode IN endpoint
|
|
|
+ bool const force_single = !(usb_hw->main_ctrl & USB_MAIN_CTRL_HOST_NDEVICE_BITS) && !tu_edpt_dir(ep->ep_addr);
|
|
|
|
|
|
- // Limit by packet size but not less 64 (i.e low speed 8 bytes EP0)
|
|
|
- ep->transfer_size = tu_min16(total_len, tu_max16(64, ep->wMaxPacketSize));
|
|
|
+ if(ep->remaining_len && !force_single)
|
|
|
+ {
|
|
|
+ // Use buffer 1 (double buffered) if there is still data
|
|
|
+ // TODO: Isochronous for buffer1 bit-field is different than CBI (control bulk, interrupt)
|
|
|
|
|
|
- ep->active = true;
|
|
|
- ep->user_buf = buffer;
|
|
|
-#if TUSB_OPT_HOST_ENABLED
|
|
|
- // Recalculate if this is the last buffer
|
|
|
- _hw_endpoint_update_last_buf(ep);
|
|
|
- ep->buf_sel = 0;
|
|
|
-#endif
|
|
|
+ buf_ctrl |= prepare_ep_buffer(ep, 1);
|
|
|
|
|
|
- _hw_endpoint_start_next_buffer(ep);
|
|
|
- _hw_endpoint_lock_update(ep, -1);
|
|
|
+ // Set endpoint control double buffered bit if needed
|
|
|
+ ep_ctrl &= ~EP_CTRL_INTERRUPT_PER_BUFFER;
|
|
|
+ ep_ctrl |= EP_CTRL_DOUBLE_BUFFERED_BITS | EP_CTRL_INTERRUPT_PER_DOUBLE_BUFFER;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ // Single buffered since 1 is enough
|
|
|
+ ep_ctrl &= ~(EP_CTRL_DOUBLE_BUFFERED_BITS | EP_CTRL_INTERRUPT_PER_DOUBLE_BUFFER);
|
|
|
+ ep_ctrl |= EP_CTRL_INTERRUPT_PER_BUFFER;
|
|
|
+ }
|
|
|
+
|
|
|
+ *ep->endpoint_control = ep_ctrl;
|
|
|
+
|
|
|
+ TU_LOG(3, "Prepare Buffer Control:\r\n");
|
|
|
+ print_bufctrl32(buf_ctrl);
|
|
|
+
|
|
|
+ // Finally, write to buffer_control which will trigger the transfer
|
|
|
+ // the next time the controller polls this dpram address
|
|
|
+ _hw_endpoint_buffer_control_set_value32(ep, buf_ctrl);
|
|
|
}
|
|
|
|
|
|
-void _hw_endpoint_xfer_sync(struct hw_endpoint *ep)
|
|
|
+void hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t total_len)
|
|
|
{
|
|
|
- // Update hw endpoint struct with info from hardware
|
|
|
- // after a buff status interrupt
|
|
|
+ _hw_endpoint_lock_update(ep, 1);
|
|
|
|
|
|
- uint32_t buf_ctrl = _hw_endpoint_buffer_control_get_value32(ep);
|
|
|
+ if ( ep->active )
|
|
|
+ {
|
|
|
+ // TODO: Is this acceptable for interrupt packets?
|
|
|
+ TU_LOG(1, "WARN: starting new transfer on already active ep %d %s\n", tu_edpt_number(ep->ep_addr),
|
|
|
+ ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
|
|
|
|
|
|
-#if TUSB_OPT_HOST_ENABLED
|
|
|
- // RP2040-E4
|
|
|
- // tag::host_buf_sel_fix[]
|
|
|
- // TODO need changes to support double buffering
|
|
|
- if (ep->buf_sel == 1)
|
|
|
- {
|
|
|
- // Host can erroneously write status to top half of buf_ctrl register
|
|
|
- buf_ctrl = buf_ctrl >> 16;
|
|
|
+ hw_endpoint_reset_transfer(ep);
|
|
|
+ }
|
|
|
|
|
|
- // update buf1 -> buf0 to prevent panic with "already available"
|
|
|
- *ep->buffer_control = buf_ctrl;
|
|
|
- }
|
|
|
- // Flip buf sel for host
|
|
|
- ep->buf_sel ^= 1u;
|
|
|
- // end::host_buf_sel_fix[]
|
|
|
-#endif
|
|
|
+ // Fill in info now that we're kicking off the hw
|
|
|
+ ep->remaining_len = total_len;
|
|
|
+ ep->xferred_len = 0;
|
|
|
+ ep->active = true;
|
|
|
+ ep->user_buf = buffer;
|
|
|
|
|
|
- // Get tranferred bytes after adjusted buf sel
|
|
|
- uint16_t const transferred_bytes = buf_ctrl & USB_BUF_CTRL_LEN_MASK;
|
|
|
+ _hw_endpoint_start_next_buffer(ep);
|
|
|
+ _hw_endpoint_lock_update(ep, -1);
|
|
|
+}
|
|
|
|
|
|
- // We are continuing a transfer here. If we are TX, we have successfullly
|
|
|
- // sent some data can increase the length we have sent
|
|
|
- if (!ep->rx)
|
|
|
- {
|
|
|
- assert(!(buf_ctrl & USB_BUF_CTRL_FULL));
|
|
|
- pico_trace("tx %d bytes (buf_ctrl 0x%08x)\n", transferred_bytes, buf_ctrl);
|
|
|
- ep->len += transferred_bytes;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // If we are OUT we have recieved some data, so can increase the length
|
|
|
- // we have recieved AFTER we have copied it to the user buffer at the appropriate
|
|
|
- // offset
|
|
|
- pico_trace("rx %d bytes (buf_ctrl 0x%08x)\n", transferred_bytes, buf_ctrl);
|
|
|
- assert(buf_ctrl & USB_BUF_CTRL_FULL);
|
|
|
- memcpy(&ep->user_buf[ep->len], ep->hw_data_buf, transferred_bytes);
|
|
|
- ep->len += transferred_bytes;
|
|
|
- }
|
|
|
+// sync endpoint buffer and return transferred bytes
|
|
|
+static uint16_t sync_ep_buffer(struct hw_endpoint *ep, uint8_t buf_id)
|
|
|
+{
|
|
|
+ uint32_t buf_ctrl = _hw_endpoint_buffer_control_get_value32(ep);
|
|
|
+ if (buf_id) buf_ctrl = buf_ctrl >> 16;
|
|
|
|
|
|
- // Sometimes the host will send less data than we expect...
|
|
|
- // If this is a short out transfer update the total length of the transfer
|
|
|
- // to be the current length
|
|
|
- if ((ep->rx) && (transferred_bytes < ep->wMaxPacketSize))
|
|
|
- {
|
|
|
- pico_trace("Short rx transfer\n");
|
|
|
- // Reduce total length as this is last packet
|
|
|
- ep->total_len = ep->len;
|
|
|
- }
|
|
|
+ uint16_t xferred_bytes = buf_ctrl & USB_BUF_CTRL_LEN_MASK;
|
|
|
+
|
|
|
+ if ( !ep->rx )
|
|
|
+ {
|
|
|
+ // We are continuing a transfer here. If we are TX, we have successfully
|
|
|
+ // sent some data can increase the length we have sent
|
|
|
+ assert(!(buf_ctrl & USB_BUF_CTRL_FULL));
|
|
|
+
|
|
|
+ ep->xferred_len += xferred_bytes;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ // If we have received some data, so can increase the length
|
|
|
+ // we have received AFTER we have copied it to the user buffer at the appropriate offset
|
|
|
+ assert(buf_ctrl & USB_BUF_CTRL_FULL);
|
|
|
+
|
|
|
+ memcpy(ep->user_buf, ep->hw_data_buf + buf_id*64, xferred_bytes);
|
|
|
+ ep->xferred_len += xferred_bytes;
|
|
|
+ ep->user_buf += xferred_bytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Short packet
|
|
|
+ if (xferred_bytes < ep->wMaxPacketSize)
|
|
|
+ {
|
|
|
+ pico_trace("Short rx transfer on buffer %d with %u bytes\n", buf_id, xferred_bytes);
|
|
|
+ // Reduce total length as this is last packet
|
|
|
+ ep->remaining_len = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return xferred_bytes;
|
|
|
}
|
|
|
|
|
|
-// Returns true if transfer is complete
|
|
|
-bool _hw_endpoint_xfer_continue(struct hw_endpoint *ep)
|
|
|
+static void _hw_endpoint_xfer_sync (struct hw_endpoint *ep)
|
|
|
{
|
|
|
- _hw_endpoint_lock_update(ep, 1);
|
|
|
- // Part way through a transfer
|
|
|
- if (!ep->active)
|
|
|
- {
|
|
|
- panic("Can't continue xfer on inactive ep %d %s", tu_edpt_number(ep->ep_addr), ep_dir_string);
|
|
|
- }
|
|
|
+ // Update hw endpoint struct with info from hardware
|
|
|
+ // after a buff status interrupt
|
|
|
|
|
|
- // Update EP struct from hardware state
|
|
|
- _hw_endpoint_xfer_sync(ep);
|
|
|
-
|
|
|
- // Now we have synced our state with the hardware. Is there more data to transfer?
|
|
|
- // Limit by packet size but not less 64 (i.e low speed 8 bytes EP0)
|
|
|
- uint16_t remaining_bytes = ep->total_len - ep->len;
|
|
|
- ep->transfer_size = tu_min16(remaining_bytes, tu_max16(64, ep->wMaxPacketSize));
|
|
|
-#if TUSB_OPT_HOST_ENABLED
|
|
|
- _hw_endpoint_update_last_buf(ep);
|
|
|
-#endif
|
|
|
+ uint32_t buf_ctrl = _hw_endpoint_buffer_control_get_value32(ep);
|
|
|
+ TU_LOG(3, "_hw_endpoint_xfer_sync:\r\n");
|
|
|
+ print_bufctrl32(buf_ctrl);
|
|
|
|
|
|
- // Can happen because of programmer error so check for it
|
|
|
- if (ep->len > ep->total_len)
|
|
|
- {
|
|
|
- panic("Transferred more data than expected");
|
|
|
- }
|
|
|
+ // always sync buffer 0
|
|
|
+ uint16_t buf0_bytes = sync_ep_buffer(ep, 0);
|
|
|
|
|
|
- // If we are done then notify tinyusb
|
|
|
- if (ep->len == ep->total_len)
|
|
|
+ // sync buffer 1 if double buffered
|
|
|
+ if ( (*ep->endpoint_control) & EP_CTRL_DOUBLE_BUFFERED_BITS )
|
|
|
+ {
|
|
|
+ if (buf0_bytes == ep->wMaxPacketSize)
|
|
|
{
|
|
|
- pico_trace("Completed transfer of %d bytes on ep %d %s\n",
|
|
|
- ep->len, tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
|
|
|
- // Notify caller we are done so it can notify the tinyusb stack
|
|
|
- _hw_endpoint_lock_update(ep, -1);
|
|
|
- return true;
|
|
|
- }
|
|
|
- else
|
|
|
+ // sync buffer 1 if not short packet
|
|
|
+ sync_ep_buffer(ep, 1);
|
|
|
+ }else
|
|
|
{
|
|
|
- _hw_endpoint_start_next_buffer(ep);
|
|
|
- }
|
|
|
+ // short packet on buffer 0
|
|
|
+ // TODO couldn't figure out how to handle this case which happen with net_lwip_webserver example
|
|
|
+ // At this time (currently trigger per 2 buffer), the buffer1 is probably filled with data from
|
|
|
+ // the next transfer (not current one). For now we disable double buffered for device OUT
|
|
|
+ // NOTE this could happen to Host IN
|
|
|
+#if 0
|
|
|
+ uint8_t const ep_num = tu_edpt_number(ep->ep_addr);
|
|
|
+ uint8_t const dir = (uint8_t) tu_edpt_dir(ep->ep_addr);
|
|
|
+ uint8_t const ep_id = 2*ep_num + (dir ? 0 : 1);
|
|
|
|
|
|
- _hw_endpoint_lock_update(ep, -1);
|
|
|
- // More work to do
|
|
|
- return false;
|
|
|
-}
|
|
|
+ // abort queued transfer on buffer 1
|
|
|
+ usb_hw->abort |= TU_BIT(ep_id);
|
|
|
|
|
|
-void _hw_endpoint_xfer(struct hw_endpoint *ep, uint8_t *buffer, uint16_t total_len, bool start)
|
|
|
-{
|
|
|
- // Trace
|
|
|
- pico_trace("hw_endpoint_xfer ep %d %s", tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
|
|
|
- pico_trace(" total_len %d, start=%d\n", total_len, start);
|
|
|
+ while ( !(usb_hw->abort_done & TU_BIT(ep_id)) ) {}
|
|
|
|
|
|
- assert(ep->configured);
|
|
|
+ uint32_t ep_ctrl = *ep->endpoint_control;
|
|
|
+ ep_ctrl &= ~(EP_CTRL_DOUBLE_BUFFERED_BITS | EP_CTRL_INTERRUPT_PER_DOUBLE_BUFFER);
|
|
|
+ ep_ctrl |= EP_CTRL_INTERRUPT_PER_BUFFER;
|
|
|
|
|
|
+ _hw_endpoint_buffer_control_set_value32(ep, 0);
|
|
|
|
|
|
- if (start)
|
|
|
- {
|
|
|
- _hw_endpoint_xfer_start(ep, buffer, total_len);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _hw_endpoint_xfer_continue(ep);
|
|
|
+ usb_hw->abort &= ~TU_BIT(ep_id);
|
|
|
+
|
|
|
+ TU_LOG(3, "----SHORT PACKET buffer0 on EP %02X:\r\n", ep->ep_addr);
|
|
|
+ print_bufctrl32(buf_ctrl);
|
|
|
+#endif
|
|
|
}
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Returns true if transfer is complete
|
|
|
+bool hw_endpoint_xfer_continue(struct hw_endpoint *ep)
|
|
|
+{
|
|
|
+ _hw_endpoint_lock_update(ep, 1);
|
|
|
+ // Part way through a transfer
|
|
|
+ if (!ep->active)
|
|
|
+ {
|
|
|
+ panic("Can't continue xfer on inactive ep %d %s", tu_edpt_number(ep->ep_addr), ep_dir_string);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update EP struct from hardware state
|
|
|
+ _hw_endpoint_xfer_sync(ep);
|
|
|
+
|
|
|
+ // Now we have synced our state with the hardware. Is there more data to transfer?
|
|
|
+ // If we are done then notify tinyusb
|
|
|
+ if (ep->remaining_len == 0)
|
|
|
+ {
|
|
|
+ pico_trace("Completed transfer of %d bytes on ep %d %s\n",
|
|
|
+ ep->xferred_len, tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
|
|
|
+ // Notify caller we are done so it can notify the tinyusb stack
|
|
|
+ _hw_endpoint_lock_update(ep, -1);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _hw_endpoint_start_next_buffer(ep);
|
|
|
+ }
|
|
|
+
|
|
|
+ _hw_endpoint_lock_update(ep, -1);
|
|
|
+ // More work to do
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
#endif
|