summaryrefslogtreecommitdiff
path: root/src/portable
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2025-11-19 22:05:07 +0100
committerHiFiPhile <[email protected]>2025-11-19 22:05:07 +0100
commit85adf694e659bde41b34e2f585cb2db552279064 (patch)
tree6445badf0b427556fd47fb3d7b682bb8b439039e /src/portable
parent2f0a35f21af4c09154d6b4b5b118325af8990e51 (diff)
parent790c7a0d7a6099e88a0bf6bbc341504c8bdaa974 (diff)
Merge remote-tracking branch 'tinyusb/master' into copilot/fix-dcd-edpt-xfer-issue
Signed-off-by: HiFiPhile <[email protected]>
Diffstat (limited to 'src/portable')
-rw-r--r--src/portable/bridgetek/ft9xx/dcd_ft9xx.c15
-rw-r--r--src/portable/chipidea/ci_fs/dcd_ci_fs.c67
-rw-r--r--src/portable/chipidea/ci_hs/dcd_ci_hs.c196
-rw-r--r--src/portable/dialog/da146xx/dcd_da146xx.c16
-rw-r--r--src/portable/microchip/pic/dcd_pic.c16
-rw-r--r--src/portable/microchip/pic32mz/dcd_pic32mz.c13
-rw-r--r--src/portable/microchip/samd/dcd_samd.c11
-rw-r--r--src/portable/microchip/samg/dcd_samg.c15
-rw-r--r--src/portable/microchip/samx7x/dcd_samx7x.c17
-rw-r--r--src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c297
-rw-r--r--src/portable/nordic/nrf5x/dcd_nrf5x.c20
-rw-r--r--src/portable/nxp/khci/dcd_khci.c66
-rw-r--r--src/portable/nxp/lpc17_40/dcd_lpc17_40.c15
-rw-r--r--src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c16
-rw-r--r--src/portable/raspberrypi/pio_usb/dcd_pio_usb.c14
-rw-r--r--src/portable/renesas/rusb2/dcd_rusb2.c16
-rw-r--r--src/portable/sunxi/dcd_sunxi_musb.c16
-rw-r--r--src/portable/synopsys/dwc2/dcd_dwc2.c135
-rw-r--r--src/portable/synopsys/dwc2/dwc2_common.h4
-rw-r--r--src/portable/synopsys/dwc2/dwc2_type.h10
-rw-r--r--src/portable/synopsys/dwc2/hcd_dwc2.c215
-rw-r--r--src/portable/ti/msp430x5xx/dcd_msp430x5xx.c16
-rw-r--r--src/portable/valentyusb/eptri/dcd_eptri.c15
-rw-r--r--src/portable/wch/dcd_ch32_usbfs.c12
-rw-r--r--src/portable/wch/dcd_ch32_usbhs.c27
25 files changed, 806 insertions, 454 deletions
diff --git a/src/portable/bridgetek/ft9xx/dcd_ft9xx.c b/src/portable/bridgetek/ft9xx/dcd_ft9xx.c
index 76a54e62e..89477b9ac 100644
--- a/src/portable/bridgetek/ft9xx/dcd_ft9xx.c
+++ b/src/portable/bridgetek/ft9xx/dcd_ft9xx.c
@@ -806,6 +806,20 @@ void dcd_edpt_close_all(uint8_t rhport)
_ft9xx_reset_edpts();
}
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
+}
+
+
// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
@@ -1202,5 +1216,4 @@ void ft9xx_usbd_pm_ISR(void)
}
}
}
-
#endif
diff --git a/src/portable/chipidea/ci_fs/dcd_ci_fs.c b/src/portable/chipidea/ci_fs/dcd_ci_fs.c
index 558d64b57..312a98299 100644
--- a/src/portable/chipidea/ci_fs/dcd_ci_fs.c
+++ b/src/portable/chipidea/ci_fs/dcd_ci_fs.c
@@ -344,24 +344,21 @@ void dcd_sof_enable(uint8_t rhport, bool en)
//--------------------------------------------------------------------+
// Endpoint API
//--------------------------------------------------------------------+
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
-
- const unsigned ep_addr = ep_desc->bEndpointAddress;
- const unsigned epn = tu_edpt_number(ep_addr);
- const unsigned dir = tu_edpt_dir(ep_addr);
- const unsigned xfer = ep_desc->bmAttributes.xfer;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- const unsigned odd = ep->odd;
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
+static bool edpt_open(uint8_t rhport, uint8_t ep_addr, uint16_t max_packet_size, tusb_xfer_type_t xfer) {
+ (void)rhport;
+ const unsigned epn = tu_edpt_number(ep_addr);
+ const unsigned dir = tu_edpt_dir(ep_addr);
+ endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
+ const unsigned odd = ep->odd;
+ buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
/* No support for control transfer */
TU_ASSERT(epn && (xfer != TUSB_XFER_CONTROL));
- ep->max_packet_size = tu_edpt_packet_size(ep_desc);
+ ep->max_packet_size = max_packet_size;
+
unsigned val = USB_ENDPT_EPCTLDIS_MASK;
- val |= (xfer != TUSB_XFER_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK: 0;
+ val |= (xfer != TUSB_XFER_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK : 0;
val |= dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
CI_REG->EP[epn].CTL |= val;
@@ -375,8 +372,27 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
return true;
}
-void dcd_edpt_close_all(uint8_t rhport)
-{
+bool dcd_edpt_open(uint8_t rhport, const tusb_desc_endpoint_t *ep_desc) {
+ return edpt_open(rhport, ep_desc->bEndpointAddress, tu_edpt_packet_size(ep_desc), ep_desc->bmAttributes.xfer);
+}
+
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ return edpt_open(rhport, ep_addr, largest_packet_size, TUSB_XFER_ISOCHRONOUS);
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *ep_desc) {
+ const unsigned epn = tu_edpt_number(ep_desc->bEndpointAddress);
+ const unsigned dir = tu_edpt_dir(ep_desc->bEndpointAddress);
+ endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
+
+ dcd_int_disable(rhport);
+ ep->max_packet_size = tu_edpt_packet_size(ep_desc);
+ dcd_int_enable(rhport);
+
+ return true;
+}
+
+void dcd_edpt_close_all(uint8_t rhport) {
dcd_int_disable(rhport);
for (unsigned i = 1; i < 16; ++i) {
@@ -399,26 +415,6 @@ void dcd_edpt_close_all(uint8_t rhport)
}
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- const unsigned epn = tu_edpt_number(ep_addr);
- const unsigned dir = tu_edpt_dir(ep_addr);
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
- const unsigned msk = dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
-
- dcd_int_disable(rhport);
-
- CI_REG->EP[epn].CTL &= ~msk;
- ep->max_packet_size = 0;
- ep->length = 0;
- ep->remaining = 0;
- bd[0].head = 0;
- bd[1].head = 0;
-
- dcd_int_enable(rhport);
-}
-
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
(void) is_isr;
@@ -565,5 +561,4 @@ void dcd_int_handler(uint8_t rhport)
process_tokdne(rhport);
}
}
-
#endif
diff --git a/src/portable/chipidea/ci_hs/dcd_ci_hs.c b/src/portable/chipidea/ci_hs/dcd_ci_hs.c
index 808c293a5..c6d405e98 100644
--- a/src/portable/chipidea/ci_hs/dcd_ci_hs.c
+++ b/src/portable/chipidea/ci_hs/dcd_ci_hs.c
@@ -65,15 +65,18 @@ bool dcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) {
// ENDPTCTRL
enum {
+ ENDPTCTRL_TYPE_POS = 2, // Endpoint type is 2-bit field
+};
+
+enum {
ENDPTCTRL_STALL = TU_BIT(0),
ENDPTCTRL_TOGGLE_INHIBIT = TU_BIT(5), // used for test only
ENDPTCTRL_TOGGLE_RESET = TU_BIT(6),
- ENDPTCTRL_ENABLE = TU_BIT(7)
+ ENDPTCTRL_ENABLE = TU_BIT(7),
};
-enum {
- ENDPTCTRL_TYPE_POS = 2, // Endpoint type is 2-bit field
-};
+#define ENDPTCTRL_TYPE(_type) ((_type) << ENDPTCTRL_TYPE_POS)
+ #define ENDPTCTRL_RESET_MASK (ENDPTCTRL_TYPE(TUSB_XFER_BULK) | (ENDPTCTRL_TYPE(TUSB_XFER_BULK) << 16u))
// USBSTS, USBINTR
enum {
@@ -170,9 +173,7 @@ static dcd_data_t _dcd_data;
// Prototypes and Helper Functions
//--------------------------------------------------------------------+
-TU_ATTR_ALWAYS_INLINE
-static inline uint8_t ci_ep_count(ci_hs_regs_t const* dcd_reg)
-{
+TU_ATTR_ALWAYS_INLINE static inline uint8_t ci_ep_count(const ci_hs_regs_t *dcd_reg) {
return dcd_reg->DCCPARAMS & DCCPARAMS_DEN_MASK;
}
@@ -191,9 +192,8 @@ static void bus_reset(uint8_t rhport)
// type (e.g. bulk). Leaving an un-configured endpoint control will cause undefined behavior
// for the data PID tracking on the active endpoint.
uint8_t const ep_count = ci_ep_count(dcd_reg);
- for( uint8_t i=1; i < ep_count; i++)
- {
- dcd_reg->ENDPTCTRL[i] = (TUSB_XFER_BULK << ENDPTCTRL_TYPE_POS) | (TUSB_XFER_BULK << (16+ENDPTCTRL_TYPE_POS));
+ for (uint8_t i = 1; i < ep_count; i++) {
+ dcd_reg->ENDPTCTRL[i] = ENDPTCTRL_RESET_MASK;
}
//------------- Clear All Registers -------------//
@@ -315,26 +315,25 @@ void dcd_sof_enable(uint8_t rhport, bool en)
// HELPER
//--------------------------------------------------------------------+
-static void qtd_init(dcd_qtd_t* p_qtd, void * data_ptr, uint16_t total_bytes)
-{
- dcd_dcache_clean_invalidate((uint32_t*) tu_align((uint32_t) data_ptr, 4), total_bytes);
+static void qtd_init(dcd_qtd_t *p_qtd, void *data_ptr, uint16_t total_bytes) {
+ dcd_dcache_clean_invalidate((uint32_t *)tu_align((uint32_t)data_ptr, 4), total_bytes);
tu_memclr(p_qtd, sizeof(dcd_qtd_t));
- p_qtd->next = QTD_NEXT_INVALID;
- p_qtd->active = 1;
- p_qtd->total_bytes = p_qtd->expected_bytes = total_bytes;
- p_qtd->int_on_complete = true;
+ p_qtd->next = QTD_NEXT_INVALID;
+ p_qtd->active = 1;
+ p_qtd->total_bytes = p_qtd->expected_bytes = total_bytes;
+ p_qtd->int_on_complete = true;
- if (data_ptr != NULL)
- {
- p_qtd->buffer[0] = (uint32_t) data_ptr;
+ if (data_ptr != NULL) {
+ p_qtd->buffer[0] = (uint32_t)data_ptr;
- uint32_t const bufend = p_qtd->buffer[0] + total_bytes;
- for(uint8_t i=1; i<5; i++)
- {
- uint32_t const next_page = tu_align4k( p_qtd->buffer[i-1] ) + 4096;
- if ( bufend <= next_page ) break;
+ const uint32_t bufend = p_qtd->buffer[0] + total_bytes;
+ for (uint8_t i = 1; i < 5; i++) {
+ const uint32_t next_page = tu_align4k(p_qtd->buffer[i - 1]) + 4096;
+ if (bufend <= next_page) {
+ break;
+ }
p_qtd->buffer[i] = next_page;
@@ -346,6 +345,35 @@ static void qtd_init(dcd_qtd_t* p_qtd, void * data_ptr, uint16_t total_bytes)
//--------------------------------------------------------------------+
// DCD Endpoint Port
//--------------------------------------------------------------------+
+TU_ATTR_ALWAYS_INLINE static inline void ep_ctrl_write(volatile uint32_t *epctrl, uint8_t dir, uint32_t value) {
+ if (dir == TUSB_DIR_OUT) {
+ *epctrl = (*epctrl & 0xFFFF0000u) | value;
+ } else {
+ *epctrl = (*epctrl & 0x0000FFFFu) | (value << 16);
+ }
+}
+
+TU_ATTR_ALWAYS_INLINE static inline void ep_ctrl_mask(volatile uint32_t *epctrl, uint8_t dir, uint32_t and_mask,
+ uint32_t or_mask) {
+ uint32_t value = *epctrl;
+ if (and_mask != 0) {
+ value &= (dir == TUSB_DIR_OUT) ? and_mask : (and_mask << 16u);
+ }
+ if (or_mask != 0) {
+ value |= (dir == TUSB_DIR_OUT) ? or_mask : (or_mask << 16u);
+ }
+
+ *epctrl = value;
+}
+
+TU_ATTR_ALWAYS_INLINE static inline void ep_ctrl_set(volatile uint32_t *epctrl, uint8_t dir, uint32_t mask) {
+ ep_ctrl_mask(epctrl, dir, 0, mask);
+}
+
+TU_ATTR_ALWAYS_INLINE static inline void ep_ctrl_clear(volatile uint32_t *epctrl, uint8_t dir, uint32_t mask) {
+ ep_ctrl_mask(epctrl, dir, ~mask, 0);
+}
+
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
{
uint8_t const epnum = tu_edpt_number(ep_addr);
@@ -366,80 +394,91 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
// data toggle also need to be reset
ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport);
dcd_reg->ENDPTCTRL[epnum] |= ENDPTCTRL_TOGGLE_RESET << ( dir ? 16 : 0 );
- dcd_reg->ENDPTCTRL[epnum] &= ~(ENDPTCTRL_STALL << ( dir ? 16 : 0));
+ dcd_reg->ENDPTCTRL[epnum] &= ~(ENDPTCTRL_STALL << (dir ? 16 : 0));
}
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
-
- ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport);
-
- // Must not exceed max endpoint number
- TU_ASSERT(epnum < ci_ep_count(dcd_reg));
-
- //------------- Prepare Queue Head -------------//
- dcd_qhd_t * p_qhd = &_dcd_data.qhd[epnum][dir];
+static void qhd_init(dcd_qhd_t *p_qhd, uint16_t max_packet_size, uint8_t iso_mult) {
tu_memclr(p_qhd, sizeof(dcd_qhd_t));
-
p_qhd->zero_length_termination = 1;
- p_qhd->max_packet_size = tu_edpt_packet_size(p_endpoint_desc);
- if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS)
- {
- p_qhd->iso_mult = 1;
- }
-
+ p_qhd->max_packet_size = max_packet_size;
+ p_qhd->iso_mult = iso_mult;
p_qhd->qtd_overlay.next = QTD_NEXT_INVALID;
-
dcd_dcache_clean_invalidate(&_dcd_data, sizeof(dcd_data_t));
+}
- // Enable EP Control
- uint32_t const epctrl = (p_endpoint_desc->bmAttributes.xfer << ENDPTCTRL_TYPE_POS) | ENDPTCTRL_ENABLE | ENDPTCTRL_TOGGLE_RESET;
+bool dcd_edpt_open(uint8_t rhport, const tusb_desc_endpoint_t *endpoint_desc) {
+ ci_hs_regs_t *dcd_reg = CI_HS_REG(rhport);
+ const uint8_t epnum = tu_edpt_number(endpoint_desc->bEndpointAddress);
+ const uint8_t dir = tu_edpt_dir(endpoint_desc->bEndpointAddress);
+ const uint8_t xfer_type = endpoint_desc->bmAttributes.xfer;
+ TU_ASSERT(epnum < ci_ep_count(dcd_reg));
- if ( dir == TUSB_DIR_OUT )
- {
- dcd_reg->ENDPTCTRL[epnum] = (dcd_reg->ENDPTCTRL[epnum] & 0xFFFF0000u) | epctrl;
- }else
- {
- dcd_reg->ENDPTCTRL[epnum] = (dcd_reg->ENDPTCTRL[epnum] & 0x0000FFFFu) | (epctrl << 16);
- }
+ dcd_qhd_t *p_qhd = &_dcd_data.qhd[epnum][dir];
+ qhd_init(p_qhd, tu_edpt_packet_size(endpoint_desc), 0u);
+
+ // EP Control
+ const uint32_t epctrl = ENDPTCTRL_TYPE(xfer_type) | ENDPTCTRL_ENABLE | ENDPTCTRL_TOGGLE_RESET;
+ ep_ctrl_write(&dcd_reg->ENDPTCTRL[epnum], dir, epctrl);
return true;
}
-void dcd_edpt_close_all (uint8_t rhport)
-{
- ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport);
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
- // Disable all non-control endpoints
- uint8_t const ep_count = ci_ep_count(dcd_reg);
- for (uint8_t epnum = 1; epnum < ep_count; epnum++)
- {
- _dcd_data.qhd[epnum][TUSB_DIR_OUT].qtd_overlay.halted = 1;
- _dcd_data.qhd[epnum][TUSB_DIR_IN ].qtd_overlay.halted = 1;
+ ci_hs_regs_t *dcd_reg = CI_HS_REG(rhport);
+ const uint8_t epnum = tu_edpt_number(ep_addr);
+ const uint8_t dir = tu_edpt_dir(ep_addr);
+ TU_ASSERT(epnum < ci_ep_count(dcd_reg));
- dcd_reg->ENDPTFLUSH = TU_BIT(epnum) | TU_BIT(epnum+16);
- dcd_reg->ENDPTCTRL[epnum] = (TUSB_XFER_BULK << ENDPTCTRL_TYPE_POS) | (TUSB_XFER_BULK << (16+ENDPTCTRL_TYPE_POS));
- }
+ // EP Control: set type but not enabled yet
+ const uint32_t epctrl = ENDPTCTRL_TYPE(TUSB_XFER_ISOCHRONOUS) | ENDPTCTRL_TOGGLE_RESET;
+ ep_ctrl_write(&dcd_reg->ENDPTCTRL[epnum], dir, epctrl);
+
+ return true;
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ const uint8_t epnum = tu_edpt_number(desc_ep->bEndpointAddress);
+ const uint8_t dir = tu_edpt_dir(desc_ep->bEndpointAddress);
+ ci_hs_regs_t *dcd_reg = CI_HS_REG(rhport);
+ TU_ASSERT(epnum < ci_ep_count(dcd_reg));
- ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport);
+ dcd_qhd_t *p_qhd = &_dcd_data.qhd[epnum][dir];
+ volatile uint32_t *endptctrl = &dcd_reg->ENDPTCTRL[epnum];
- _dcd_data.qhd[epnum][dir].qtd_overlay.halted = 1;
+ // _dcd_data.qhd[epnum][dir].qtd_overlay.halted = 1;
+ // dcd_dcache_clean_invalidate(&_dcd_data, sizeof(dcd_data_t));
// Flush EP
- uint32_t const flush_mask = TU_BIT(epnum + (dir ? 16 : 0));
- dcd_reg->ENDPTFLUSH = flush_mask;
- while(dcd_reg->ENDPTFLUSH & flush_mask);
+ const uint32_t flush_mask = TU_BIT(epnum + (dir ? 16 : 0));
+ dcd_reg->ENDPTFLUSH = flush_mask;
+ while (dcd_reg->ENDPTFLUSH & flush_mask) {}
+
+ // disable to change max packet size
+ ep_ctrl_clear(endptctrl, dir, ENDPTCTRL_ENABLE);
- // Clear EP enable
- dcd_reg->ENDPTCTRL[epnum] &=~(ENDPTCTRL_ENABLE << (dir ? 16 : 0));
+ qhd_init(p_qhd, tu_edpt_packet_size(desc_ep), 1u);
+
+ ep_ctrl_set(endptctrl, dir, ENDPTCTRL_ENABLE);
+
+ return true;
+}
+
+void dcd_edpt_close_all(uint8_t rhport) {
+ ci_hs_regs_t *dcd_reg = CI_HS_REG(rhport);
+
+ // Disable all non-control endpoints
+ uint8_t const ep_count = ci_ep_count(dcd_reg);
+ for (uint8_t epnum = 1; epnum < ep_count; epnum++) {
+ _dcd_data.qhd[epnum][TUSB_DIR_OUT].qtd_overlay.halted = 1;
+ _dcd_data.qhd[epnum][TUSB_DIR_IN].qtd_overlay.halted = 1;
+
+ dcd_reg->ENDPTFLUSH = TU_BIT(epnum) | TU_BIT(epnum + 16);
+ dcd_reg->ENDPTCTRL[epnum] = ENDPTCTRL_RESET_MASK;
+ }
}
static void qhd_start_xfer(uint8_t rhport, uint8_t epnum, uint8_t dir)
@@ -680,5 +719,4 @@ void dcd_int_handler(uint8_t rhport)
dcd_event_sof(rhport, frame, true);
}
}
-
#endif
diff --git a/src/portable/dialog/da146xx/dcd_da146xx.c b/src/portable/dialog/da146xx/dcd_da146xx.c
index 5beb62b4d..a283c8362 100644
--- a/src/portable/dialog/da146xx/dcd_da146xx.c
+++ b/src/portable/dialog/da146xx/dcd_da146xx.c
@@ -1025,6 +1025,21 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
tu_memclr(xfer, sizeof(*xfer));
}
+#if 0
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void) rhport;
+ (void) ep_addr;
+ (void) largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep) {
+ (void) rhport;
+ (void) desc_ep;
+ return false;
+}
+#endif
+
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
(void) is_isr;
@@ -1219,5 +1234,4 @@ void dcd_int_handler(uint8_t rhport)
handle_alt_ev();
}
}
-
#endif
diff --git a/src/portable/microchip/pic/dcd_pic.c b/src/portable/microchip/pic/dcd_pic.c
index 3114295de..fedede8ab 100644
--- a/src/portable/microchip/pic/dcd_pic.c
+++ b/src/portable/microchip/pic/dcd_pic.c
@@ -687,6 +687,21 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
if (ie) intr_enable(rhport);
}
+#if 0
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void) rhport;
+ (void) ep_addr;
+ (void) largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep) {
+ (void) rhport;
+ (void) desc_ep;
+ return false;
+}
+#endif
+
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
(void) is_isr;
@@ -867,5 +882,4 @@ void dcd_int_handler(uint8_t rhport)
intr_clear(rhport);
}
-
#endif
diff --git a/src/portable/microchip/pic32mz/dcd_pic32mz.c b/src/portable/microchip/pic32mz/dcd_pic32mz.c
index a903c3ae2..94ecf1455 100644
--- a/src/portable/microchip/pic32mz/dcd_pic32mz.c
+++ b/src/portable/microchip/pic32mz/dcd_pic32mz.c
@@ -438,12 +438,20 @@ void dcd_edpt_close_all (uint8_t rhport)
}
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
(void) rhport;
(void) ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
}
+
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
(void) is_isr;
@@ -745,5 +753,4 @@ void dcd_int_handler(uint8_t rhport)
}
}
}
-
#endif
diff --git a/src/portable/microchip/samd/dcd_samd.c b/src/portable/microchip/samd/dcd_samd.c
index 8293273e5..cdfb00e3c 100644
--- a/src/portable/microchip/samd/dcd_samd.c
+++ b/src/portable/microchip/samd/dcd_samd.c
@@ -245,11 +245,17 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
return true;
}
-void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr) {
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
(void) rhport;
(void) ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
- // TODO: implement if necessary?
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
}
void dcd_edpt_close_all (uint8_t rhport)
@@ -428,5 +434,4 @@ void dcd_int_handler (uint8_t rhport)
// Handle complete transfer
maybe_transfer_complete();
}
-
#endif
diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c
index c6c7f15d1..149eee794 100644
--- a/src/portable/microchip/samg/dcd_samg.c
+++ b/src/portable/microchip/samg/dcd_samg.c
@@ -270,9 +270,17 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
return true;
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
- (void) rhport; (void) ep_addr;
- // TODO implement dcd_edpt_close()
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
}
void dcd_edpt_close_all (uint8_t rhport)
@@ -496,5 +504,4 @@ void dcd_int_handler(uint8_t rhport)
}
}
}
-
#endif
diff --git a/src/portable/microchip/samx7x/dcd_samx7x.c b/src/portable/microchip/samx7x/dcd_samx7x.c
index 57c0fcb4d..4d54f9057 100644
--- a/src/portable/microchip/samx7x/dcd_samx7x.c
+++ b/src/portable/microchip/samx7x/dcd_samx7x.c
@@ -559,15 +559,17 @@ void dcd_edpt_close_all (uint8_t rhport)
// TODO implement dcd_edpt_close_all()
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
(void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_addr);
+ (void) ep_addr;
+ (void) largest_packet_size;
+ return false;
+}
- // Disable endpoint interrupt
- USB_REG->DEVIDR = 1 << (DEVIDR_PEP_0_Pos + epnum);
- // Disable EP
- USB_REG->DEVEPT &=~(1 << (DEVEPT_EPEN0_Pos + epnum));
+bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep) {
+ (void) rhport;
+ (void) desc_ep;
+ return false;
}
static void dcd_transmit_packet(xfer_ctl_t * xfer, uint8_t ep_ix)
@@ -775,5 +777,4 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
USB_REG->DEVEPTIDR[epnum] = DEVEPTIDR_CTRL_STALLRQC;
USB_REG->DEVEPTIER[epnum] = HSTPIPIER_RSTDTS;
}
-
#endif
diff --git a/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c b/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
index 929cb40c4..6f88e0a24 100644
--- a/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
+++ b/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
@@ -26,7 +26,7 @@
#include "tusb_option.h"
-#if CFG_TUD_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_MM32F327X )
+#if CFG_TUD_ENABLED && (CFG_TUSB_MCU == OPT_MCU_MM32F327X)
#include "reg_usb_otg_fs.h"
#include "mm32_device.h"
@@ -43,56 +43,53 @@ enum {
TOK_PID_SETUP = 0xDu,
};
-typedef struct TU_ATTR_PACKED
-{
+typedef struct TU_ATTR_PACKED {
union {
uint32_t head;
struct {
union {
struct {
- uint16_t : 2;
- uint16_t tok_pid : 4;
- uint16_t data : 1;
- uint16_t own : 1;
- uint16_t : 8;
+ uint16_t : 2;
+ uint16_t tok_pid : 4;
+ uint16_t data : 1;
+ uint16_t own : 1;
+ uint16_t : 8;
};
struct {
- uint16_t : 2;
- uint16_t bdt_stall: 1;
- uint16_t dts : 1;
- uint16_t ninc : 1;
- uint16_t keep : 1;
- uint16_t : 10;
+ uint16_t : 2;
+ uint16_t bdt_stall : 1;
+ uint16_t dts : 1;
+ uint16_t ninc : 1;
+ uint16_t keep : 1;
+ uint16_t : 10;
};
};
- uint16_t bc : 10;
- uint16_t : 6;
+ uint16_t bc : 10;
+ uint16_t : 6;
};
};
uint8_t *addr;
-}buffer_descriptor_t;
+} buffer_descriptor_t;
-TU_VERIFY_STATIC( sizeof(buffer_descriptor_t) == 8, "size is not correct" );
+TU_VERIFY_STATIC(sizeof(buffer_descriptor_t) == 8, "size is not correct");
-typedef struct TU_ATTR_PACKED
-{
+typedef struct TU_ATTR_PACKED {
union {
uint32_t state;
struct {
- uint32_t max_packet_size :11;
+ uint32_t max_packet_size : 11;
uint32_t : 5;
uint32_t odd : 1;
- uint32_t :15;
+ uint32_t : 15;
};
};
uint16_t length;
uint16_t remaining;
-}endpoint_state_t;
+} endpoint_state_t;
-TU_VERIFY_STATIC( sizeof(endpoint_state_t) == 8, "size is not correct" );
+TU_VERIFY_STATIC(sizeof(endpoint_state_t) == 8, "size is not correct");
-typedef struct
-{
+typedef struct {
union {
/* [#EP][OUT,IN][EVEN,ODD] */
buffer_descriptor_t bdt[16][2][2];
@@ -104,7 +101,7 @@ typedef struct
};
uint8_t setup_packet[8];
uint8_t addr;
-}dcd_data_t;
+} dcd_data_t;
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
@@ -112,10 +109,9 @@ typedef struct
// BDT(Buffer Descriptor Table) must be 256-byte aligned
CFG_TUD_MEM_SECTION TU_ATTR_ALIGNED(512) static dcd_data_t _dcd;
-TU_VERIFY_STATIC( sizeof(_dcd.bdt) == 512, "size is not correct" );
+TU_VERIFY_STATIC(sizeof(_dcd.bdt) == 512, "size is not correct");
-static void prepare_next_setup_packet(uint8_t rhport)
-{
+static void prepare_next_setup_packet(uint8_t rhport) {
const unsigned out_odd = _dcd.endpoint[0][0].odd;
const unsigned in_odd = _dcd.endpoint[0][1].odd;
if (_dcd.bdt[0][0][out_odd].own) {
@@ -126,12 +122,10 @@ static void prepare_next_setup_packet(uint8_t rhport)
_dcd.bdt[0][0][out_odd ^ 1].data = 1;
_dcd.bdt[0][1][in_odd].data = 1;
_dcd.bdt[0][1][in_odd ^ 1].data = 0;
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_OUT),
- _dcd.setup_packet, sizeof(_dcd.setup_packet), false);
+ dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_OUT), _dcd.setup_packet, sizeof(_dcd.setup_packet), false);
}
-static void process_stall(uint8_t rhport)
-{
+static void process_stall(uint8_t rhport) {
if (USB_OTG_FS->EP_CTL[0] & USB_ENDPT_EPSTALL_MASK) {
/* clear stall condition of the control pipe */
prepare_next_setup_packet(rhport);
@@ -139,13 +133,12 @@ static void process_stall(uint8_t rhport)
}
}
-static void process_tokdne(uint8_t rhport)
-{
- const unsigned s = USB_OTG_FS->STAT;
- USB_OTG_FS->INT_STAT = USB_ISTAT_TOKDNE_MASK; /* fetch the next token if received */
- buffer_descriptor_t *bd = (buffer_descriptor_t *)&_dcd.bda[s];
- endpoint_state_t *ep = &_dcd.endpoint_unified[s >> 3];
- unsigned odd = (s & USB_STAT_ODD_MASK) ? 1 : 0;
+static void process_tokdne(uint8_t rhport) {
+ const unsigned s = USB_OTG_FS->STAT;
+ USB_OTG_FS->INT_STAT = USB_ISTAT_TOKDNE_MASK; /* fetch the next token if received */
+ buffer_descriptor_t *bd = (buffer_descriptor_t *)&_dcd.bda[s];
+ endpoint_state_t *ep = &_dcd.endpoint_unified[s >> 3];
+ unsigned odd = (s & USB_STAT_ODD_MASK) ? 1 : 0;
/* fetch pid before discarded by the next steps */
const unsigned pid = bd->tok_pid;
@@ -155,7 +148,7 @@ static void process_tokdne(uint8_t rhport)
bd->ninc = 0;
bd->keep = 0;
/* update the odd variable to prepare for the next transfer */
- ep->odd = odd ^ 1;
+ ep->odd = odd ^ 1;
if (pid == TOK_PID_SETUP) {
dcd_event_setup_received(rhport, bd->addr, true);
USB_OTG_FS->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
@@ -165,25 +158,24 @@ static void process_tokdne(uint8_t rhport)
TU_LOG1("TKDNE %x\r\n", s);
}
- const unsigned bc = bd->bc;
+ const unsigned bc = bd->bc;
const unsigned remaining = ep->remaining - bc;
if (remaining && bc == ep->max_packet_size) {
/* continue the transferring consecutive data */
- ep->remaining = remaining;
+ ep->remaining = remaining;
const int next_remaining = remaining - ep->max_packet_size;
if (next_remaining > 0) {
/* prepare to the after next transfer */
bd->addr += ep->max_packet_size * 2;
- bd->bc = next_remaining > ep->max_packet_size ? ep->max_packet_size: next_remaining;
+ bd->bc = next_remaining > ep->max_packet_size ? ep->max_packet_size : next_remaining;
__DSB();
- bd->own = 1; /* the own bit must set after addr */
+ bd->own = 1; /* the own bit must set after addr */
}
return;
}
const unsigned length = ep->length;
- dcd_event_xfer_complete(rhport,
- ((s & USB_STAT_TX_MASK) << 4) | (s >> USB_STAT_ENDP_SHIFT),
- length - remaining, XFER_RESULT_SUCCESS, true);
+ dcd_event_xfer_complete(rhport, ((s & USB_STAT_TX_MASK) << 4) | (s >> USB_STAT_ENDP_SHIFT), length - remaining,
+ XFER_RESULT_SUCCESS, true);
if (0 == (s & USB_STAT_ENDP_MASK) && 0 == length) {
/* After completion a ZLP of control transfer,
* it prepares for the next steup transfer. */
@@ -191,24 +183,23 @@ static void process_tokdne(uint8_t rhport)
/* When the transfer was the SetAddress,
* the device address should be updated here. */
USB_OTG_FS->ADDR = _dcd.addr;
- _dcd.addr = 0;
+ _dcd.addr = 0;
}
prepare_next_setup_packet(rhport);
}
}
-static void process_bus_reset(uint8_t rhport)
-{
- USB_OTG_FS->CTL |= USB_CTL_ODDRST_MASK;
- USB_OTG_FS->ADDR = 0;
- USB_OTG_FS->INT_ENB = (USB_OTG_FS->INT_ENB & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
+static void process_bus_reset(uint8_t rhport) {
+ USB_OTG_FS->CTL |= USB_CTL_ODDRST_MASK;
+ USB_OTG_FS->ADDR = 0;
+ USB_OTG_FS->INT_ENB = (USB_OTG_FS->INT_ENB & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
USB_OTG_FS->EP_CTL[0] = USB_ENDPT_EPHSHK_MASK | USB_ENDPT_EPRXEN_MASK | USB_ENDPT_EPTXEN_MASK;
for (unsigned i = 1; i < 16; ++i) {
USB_OTG_FS->EP_CTL[i] = 0;
}
buffer_descriptor_t *bd = _dcd.bdt[0][0];
- for (unsigned i = 0; i < sizeof(_dcd.bdt)/sizeof(*bd); ++i, ++bd) {
+ for (unsigned i = 0; i < sizeof(_dcd.bdt) / sizeof(*bd); ++i, ++bd) {
bd->head = 0;
}
const endpoint_state_t ep0 = {
@@ -226,31 +217,29 @@ static void process_bus_reset(uint8_t rhport)
dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true);
}
-static void process_bus_inactive(uint8_t rhport)
-{
- (void) rhport;
+static void process_bus_inactive(uint8_t rhport) {
+ (void)rhport;
const unsigned inten = USB_OTG_FS->INT_ENB;
- USB_OTG_FS->INT_ENB = (inten & ~USB_INTEN_SLEEPEN_MASK) | USB_INTEN_RESUMEEN_MASK;
+ USB_OTG_FS->INT_ENB = (inten & ~USB_INTEN_SLEEPEN_MASK) | USB_INTEN_RESUMEEN_MASK;
dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
}
-static void process_bus_active(uint8_t rhport)
-{
- (void) rhport;
+static void process_bus_active(uint8_t rhport) {
+ (void)rhport;
const unsigned inten = USB_OTG_FS->INT_ENB;
- USB_OTG_FS->INT_ENB = (inten & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
+ USB_OTG_FS->INT_ENB = (inten & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
}
/*------------------------------------------------------------------*/
/* Device API
*------------------------------------------------------------------*/
-bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
- (void) rhport;
- (void) rh_init;
+bool dcd_init(uint8_t rhport, const tusb_rhport_init_t *rh_init) {
+ (void)rhport;
+ (void)rh_init;
tu_memclr(&_dcd, sizeof(_dcd));
- USB_OTG_FS->BDT_PAGE_01 = (uint8_t)((uintptr_t)_dcd.bdt >> 8);
+ USB_OTG_FS->BDT_PAGE_01 = (uint8_t)((uintptr_t)_dcd.bdt >> 8);
USB_OTG_FS->BDT_PAGE_02 = (uint8_t)((uintptr_t)_dcd.bdt >> 16);
USB_OTG_FS->BDT_PAGE_03 = (uint8_t)((uintptr_t)_dcd.bdt >> 24);
@@ -259,27 +248,24 @@ bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
return true;
}
#define USB_DEVICE_INTERRUPT_PRIORITY (3U)
-void dcd_int_enable(uint8_t rhport)
-{
+void dcd_int_enable(uint8_t rhport) {
uint8_t irqNumber;
irqNumber = USB_FS_IRQn;
- (void) rhport;
- USB_OTG_FS->INT_ENB = USB_INTEN_USBRSTEN_MASK | USB_INTEN_TOKDNEEN_MASK |
- USB_INTEN_SLEEPEN_MASK | USB_INTEN_ERROREN_MASK | USB_INTEN_STALLEN_MASK;
+ (void)rhport;
+ USB_OTG_FS->INT_ENB = USB_INTEN_USBRSTEN_MASK | USB_INTEN_TOKDNEEN_MASK | USB_INTEN_SLEEPEN_MASK |
+ USB_INTEN_ERROREN_MASK | USB_INTEN_STALLEN_MASK;
NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
NVIC_EnableIRQ(USB_FS_IRQn);
}
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
+void dcd_int_disable(uint8_t rhport) {
+ (void)rhport;
NVIC_DisableIRQ(USB_FS_IRQn);
USB_OTG_FS->INT_ENB = 0;
}
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
+void dcd_set_address(uint8_t rhport, uint8_t dev_addr) {
+ (void)rhport;
_dcd.addr = dev_addr & 0x7F;
/* Response with status first before changing device address */
dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0, false);
@@ -296,31 +282,29 @@ extern u32 SystemCoreClock;
#pragma GCC diagnostic pop
#endif
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
+void dcd_remote_wakeup(uint8_t rhport) {
+ (void)rhport;
unsigned cnt = SystemCoreClock / 100;
USB_OTG_FS->CTL |= USB_CTL_RESUME_MASK;
- while (cnt--) __NOP();
+ while (cnt--) {
+ __NOP();
+ }
USB_OTG_FS->CTL &= ~USB_CTL_RESUME_MASK;
}
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- USB_OTG_FS->CTL |= USB_CTL_USBENSOFEN_MASK;
+void dcd_connect(uint8_t rhport) {
+ (void)rhport;
+ USB_OTG_FS->CTL |= USB_CTL_USBENSOFEN_MASK;
}
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- USB_OTG_FS->CTL = 0;
+void dcd_disconnect(uint8_t rhport) {
+ (void)rhport;
+ USB_OTG_FS->CTL = 0;
}
-void dcd_sof_enable(uint8_t rhport, bool en)
-{
- (void) rhport;
- (void) en;
+void dcd_sof_enable(uint8_t rhport, bool en) {
+ (void)rhport;
+ (void)en;
// TODO implement later
}
@@ -328,24 +312,23 @@ void dcd_sof_enable(uint8_t rhport, bool en)
//--------------------------------------------------------------------+
// Endpoint API
//--------------------------------------------------------------------+
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
+bool dcd_edpt_open(uint8_t rhport, const tusb_desc_endpoint_t *ep_desc) {
+ (void)rhport;
- const unsigned ep_addr = ep_desc->bEndpointAddress;
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- const unsigned xfer = ep_desc->bmAttributes.xfer;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- const unsigned odd = ep->odd;
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][0];
+ const unsigned ep_addr = ep_desc->bEndpointAddress;
+ const unsigned epn = ep_addr & 0xFu;
+ const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
+ const unsigned xfer = ep_desc->bmAttributes.xfer;
+ endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
+ const unsigned odd = ep->odd;
+ buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][0];
/* No support for control transfer */
TU_ASSERT(epn && (xfer != TUSB_XFER_CONTROL));
ep->max_packet_size = tu_edpt_packet_size(ep_desc);
- unsigned val = USB_ENDPT_EPCTLDIS_MASK;
- val |= (xfer != TUSB_XFER_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK: 0;
+ unsigned val = USB_ENDPT_EPCTLDIS_MASK;
+ val |= (xfer != TUSB_XFER_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK : 0;
val |= dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
USB_OTG_FS->EP_CTL[epn] |= val;
@@ -359,21 +342,19 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
return true;
}
-void dcd_edpt_close_all (uint8_t rhport)
-{
- (void) rhport;
+void dcd_edpt_close_all(uint8_t rhport) {
+ (void)rhport;
// TODO implement dcd_edpt_close_all()
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
+void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
+ (void)rhport;
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][0];
- const unsigned msk = dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
+ const unsigned epn = ep_addr & 0xFu;
+ const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
+ endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
+ buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][0];
+ const unsigned msk = dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
USB_OTG_FS->EP_CTL[epn] &= ~msk;
ep->max_packet_size = 0;
ep->length = 0;
@@ -381,15 +362,29 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
bd->head = 0;
}
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
-{
+ #if 0
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
+}
+ #endif
+
+bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes, bool is_isr) {
(void) is_isr;
- (void) rhport;
+ (void)rhport;
NVIC_DisableIRQ(USB_FS_IRQn);
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][ep->odd];
+ const unsigned epn = ep_addr & 0xFu;
+ const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
+ endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
+ buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][ep->odd];
if (bd->own) {
TU_LOG1("DCD XFER fail %x %d %lx %lx\r\n", ep_addr, total_bytes, ep->state, bd->head);
@@ -400,42 +395,40 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t t
const unsigned mps = ep->max_packet_size;
if (total_bytes > mps) {
- buffer_descriptor_t *next = ep->odd ? bd - 1: bd + 1;
+ buffer_descriptor_t *next = ep->odd ? bd - 1 : bd + 1;
/* When total_bytes is greater than the max packet size,
* it prepares to the next transfer to avoid NAK in advance. */
- next->bc = total_bytes >= 2 * mps ? mps: total_bytes - mps;
+ next->bc = total_bytes >= 2 * mps ? mps : total_bytes - mps;
next->addr = buffer + mps;
next->own = 1;
}
- bd->bc = total_bytes >= mps ? mps: total_bytes;
- bd->addr = buffer;
+ bd->bc = total_bytes >= mps ? mps : total_bytes;
+ bd->addr = buffer;
__DSB();
- bd->own = 1; /* the own bit must set after addr */
+ bd->own = 1; /* the own bit must set after addr */
NVIC_EnableIRQ(USB_FS_IRQn);
return true;
}
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
+void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
+ (void)rhport;
const unsigned epn = ep_addr & 0xFu;
if (0 == epn) {
- USB_OTG_FS->EP_CTL[epn] |= USB_ENDPT_EPSTALL_MASK;
+ USB_OTG_FS->EP_CTL[epn] |= USB_ENDPT_EPSTALL_MASK;
} else {
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
- bd[0].bdt_stall = 1;
- bd[1].bdt_stall = 1;
+ const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
+ buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
+ bd[0].bdt_stall = 1;
+ bd[1].bdt_stall = 1;
}
}
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- const unsigned odd = _dcd.endpoint[epn][dir].odd;
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
+void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
+ (void)rhport;
+ const unsigned epn = ep_addr & 0xFu;
+ const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
+ const unsigned odd = _dcd.endpoint[epn][dir].odd;
+ buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
bd[odd ^ 1].own = 0;
bd[odd ^ 1].data = 1;
@@ -448,19 +441,18 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
//--------------------------------------------------------------------+
// ISR
//--------------------------------------------------------------------+
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
+void dcd_int_handler(uint8_t rhport) {
+ (void)rhport;
- uint32_t is = USB_OTG_FS->INT_STAT;
- uint32_t msk = USB_OTG_FS->INT_ENB;
+ uint32_t is = USB_OTG_FS->INT_STAT;
+ uint32_t msk = USB_OTG_FS->INT_ENB;
USB_OTG_FS->INT_STAT = is & ~msk;
is &= msk;
if (is & USB_ISTAT_ERROR_MASK) {
/* TODO: */
- uint32_t es = USB_OTG_FS->ERR_STAT;
+ uint32_t es = USB_OTG_FS->ERR_STAT;
USB_OTG_FS->ERR_STAT = es;
- USB_OTG_FS->INT_STAT = is; /* discard any pending events */
+ USB_OTG_FS->INT_STAT = is; /* discard any pending events */
return;
}
@@ -494,5 +486,4 @@ void dcd_int_handler(uint8_t rhport)
return;
}
}
-
#endif
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c
index 89dff4995..82b6db5fd 100644
--- a/src/portable/nordic/nrf5x/dcd_nrf5x.c
+++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c
@@ -426,9 +426,24 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
__DSB();
}
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr) {
- (void) is_isr;
+#if 0
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
+}
+#endif
+
+bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes, bool is_isr) {
(void) rhport;
+ (void) is_isr;
uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
@@ -1063,5 +1078,4 @@ void tusb_hal_nrf_power_event(uint32_t event) {
break;
}
}
-
#endif
diff --git a/src/portable/nxp/khci/dcd_khci.c b/src/portable/nxp/khci/dcd_khci.c
index 8941ca766..ad27b8528 100644
--- a/src/portable/nxp/khci/dcd_khci.c
+++ b/src/portable/nxp/khci/dcd_khci.c
@@ -355,24 +355,21 @@ void dcd_sof_enable(uint8_t rhport, bool en)
//--------------------------------------------------------------------+
// Endpoint API
//--------------------------------------------------------------------+
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
+static bool edpt_open(uint8_t rhport, uint8_t ep_addr, uint16_t max_packet_size, tusb_xfer_type_t xfer) {
+ (void)rhport;
- const unsigned ep_addr = ep_desc->bEndpointAddress;
- const unsigned epn = tu_edpt_number(ep_addr);
- const unsigned dir = tu_edpt_dir(ep_addr);
- const unsigned xfer = ep_desc->bmAttributes.xfer;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- const unsigned odd = ep->odd;
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
+ const unsigned epn = tu_edpt_number(ep_addr);
+ const unsigned dir = tu_edpt_dir(ep_addr);
+ endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
+ const unsigned odd = ep->odd;
+ buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
/* No support for control transfer */
TU_ASSERT(epn && (xfer != TUSB_XFER_CONTROL));
- ep->max_packet_size = tu_edpt_packet_size(ep_desc);
- unsigned val = USB_ENDPT_EPCTLDIS_MASK;
- val |= (xfer != TUSB_XFER_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK: 0;
+ ep->max_packet_size = max_packet_size;
+ unsigned val = USB_ENDPT_EPCTLDIS_MASK;
+ val |= (xfer != TUSB_XFER_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK : 0;
val |= dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
KHCI->ENDPOINT[epn].ENDPT |= val;
@@ -386,6 +383,26 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
return true;
}
+bool dcd_edpt_open(uint8_t rhport, const tusb_desc_endpoint_t *ep_desc) {
+ return edpt_open(rhport, ep_desc->bEndpointAddress, tu_edpt_packet_size(ep_desc), ep_desc->bmAttributes.xfer);
+}
+
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ return edpt_open(rhport, ep_addr, largest_packet_size, TUSB_XFER_ISOCHRONOUS);
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *ep_desc) {
+ const unsigned epn = tu_edpt_number(ep_desc->bEndpointAddress);
+ const unsigned dir = tu_edpt_dir(ep_desc->bEndpointAddress);
+ endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
+
+ dcd_int_disable(rhport);
+ ep->max_packet_size = tu_edpt_packet_size(ep_desc);
+ dcd_int_enable(rhport);
+
+ return true;
+}
+
void dcd_edpt_close_all(uint8_t rhport)
{
(void) rhport;
@@ -408,30 +425,10 @@ void dcd_edpt_close_all(uint8_t rhport)
}
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- const unsigned epn = tu_edpt_number(ep_addr);
- const unsigned dir = tu_edpt_dir(ep_addr);
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
- const unsigned msk = dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
- const unsigned ie = NVIC_GetEnableIRQ(USB0_IRQn);
- NVIC_DisableIRQ(USB0_IRQn);
- KHCI->ENDPOINT[epn].ENDPT &= ~msk;
- ep->max_packet_size = 0;
- ep->length = 0;
- ep->remaining = 0;
- bd[0].head = 0;
- bd[1].head = 0;
- if (ie) NVIC_EnableIRQ(USB0_IRQn);
-}
-
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
- (void) is_isr;
(void) rhport;
+ (void) is_isr;
const unsigned epn = tu_edpt_number(ep_addr);
const unsigned dir = tu_edpt_dir(ep_addr);
endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
@@ -578,5 +575,4 @@ void dcd_int_handler(uint8_t rhport)
process_tokdne(rhport);
}
}
-
#endif
diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
index 364cf8de4..349229c8d 100644
--- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
+++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
@@ -337,9 +337,17 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
return true;
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
- (void) rhport; (void) ep_addr;
- // TODO implement dcd_edpt_close()
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
}
void dcd_edpt_close_all (uint8_t rhport)
@@ -601,5 +609,4 @@ void dcd_int_handler(uint8_t rhport)
TU_BREAKPOINT();
}
}
-
#endif
diff --git a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c
index 143b0277c..5f4a441dc 100644
--- a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c
+++ b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c
@@ -432,6 +432,21 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
_dcd.ep[ep_id][0].cmd_sts.disable = _dcd.ep[ep_id][1].cmd_sts.disable = 1;
}
+#if 0
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
+}
+#endif
+
static void prepare_ep_xfer(uint8_t rhport, uint8_t ep_id, uint16_t buf_offset, uint16_t total_bytes) {
uint16_t nbytes;
ep_cmd_sts_t* ep_cs = get_ep_cs(ep_id);
@@ -632,5 +647,4 @@ void dcd_int_handler(uint8_t rhport)
// Endpoint transfer complete interrupt
process_xfer_isr(rhport, int_status);
}
-
#endif
diff --git a/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c b/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
index 5e3dd7faf..78df2b6a6 100644
--- a/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
+++ b/src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
@@ -113,6 +113,19 @@ void dcd_edpt_close_all (uint8_t rhport)
(void) rhport;
}
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
+}
+
// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
@@ -208,5 +221,4 @@ void __no_inline_not_in_flash_func(pio_usb_device_irq_handler)(uint8_t root_id)
// clear all
rport->ints &= ~ints;
}
-
#endif
diff --git a/src/portable/renesas/rusb2/dcd_rusb2.c b/src/portable/renesas/rusb2/dcd_rusb2.c
index 6ac1c5ee4..7caf5d68a 100644
--- a/src/portable/renesas/rusb2/dcd_rusb2.c
+++ b/src/portable/renesas/rusb2/dcd_rusb2.c
@@ -859,6 +859,21 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
_dcd.ep[dir][epn] = 0;
}
+#if 0
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
+}
+#endif
+
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
(void) is_isr;
@@ -1030,5 +1045,4 @@ void dcd_int_handler(uint8_t rhport)
}
}
}
-
#endif
diff --git a/src/portable/sunxi/dcd_sunxi_musb.c b/src/portable/sunxi/dcd_sunxi_musb.c
index 46d05e3e6..d43ea1dc3 100644
--- a/src/portable/sunxi/dcd_sunxi_musb.c
+++ b/src/portable/sunxi/dcd_sunxi_musb.c
@@ -1082,6 +1082,21 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
musb_int_unmask();
}
+ #if 0
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
+}
+ #endif
+
// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr)
{
@@ -1212,5 +1227,4 @@ void dcd_int_handler(uint8_t rhport)
rxis &= ~TU_BIT(num);
}
}
-
#endif
diff --git a/src/portable/synopsys/dwc2/dcd_dwc2.c b/src/portable/synopsys/dwc2/dcd_dwc2.c
index 22a25fe40..e99cd29c6 100644
--- a/src/portable/synopsys/dwc2/dcd_dwc2.c
+++ b/src/portable/synopsys/dwc2/dcd_dwc2.c
@@ -51,6 +51,7 @@ typedef struct {
uint16_t total_len;
uint16_t max_size;
uint8_t interval;
+ uint8_t iso_retry; // ISO retry counter
} xfer_ctl_t;
// This variable is modified from ISR context, so it must be protected by critical section
@@ -261,7 +262,13 @@ static void edpt_activate(uint8_t rhport, const tusb_desc_endpoint_t* p_endpoint
xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir);
xfer->max_size = tu_edpt_packet_size(p_endpoint_desc);
- xfer->interval = p_endpoint_desc->bInterval;
+
+ const dwc2_dsts_t dsts = {.value = dwc2->dsts};
+ if (dsts.enum_speed == DCFG_SPEED_HIGH) {
+ xfer->interval = 1 << (p_endpoint_desc->bInterval - 1);
+ } else {
+ xfer->interval = p_endpoint_desc->bInterval;
+ }
// Endpoint control
dwc2_depctl_t depctl = {.value = 0};
@@ -332,6 +339,40 @@ static void edpt_disable(uint8_t rhport, uint8_t ep_addr, bool stall) {
}
}
+static uint16_t epin_write_tx_fifo(uint8_t rhport, uint8_t epnum) {
+ dwc2_regs_t* dwc2 = DWC2_REG(rhport);
+ dwc2_dep_t* const epin = &dwc2->ep[0][epnum];
+ xfer_ctl_t* const xfer = XFER_CTL_BASE(epnum, TUSB_DIR_IN);
+
+ dwc2_ep_tsize_t tsiz = {.value = epin->tsiz};
+ const uint16_t remain_packets = tsiz.packet_count;
+
+ uint16_t total_bytes_written = 0;
+ // Process every single packet (only whole packets can be written to fifo)
+ for (uint16_t i = 0; i < remain_packets; i++) {
+ tsiz.value = epin->tsiz;
+ const uint16_t remain_bytes = (uint16_t) tsiz.xfer_size;
+ const uint16_t xact_bytes = tu_min16(remain_bytes, xfer->max_size);
+
+ // Check if dtxfsts has enough space available
+ if (xact_bytes > ((epin->dtxfsts & DTXFSTS_INEPTFSAV_Msk) << 2)) {
+ break;
+ }
+
+ // Push packet to Tx-FIFO
+ if (xfer->ff) {
+ volatile uint32_t* tx_fifo = dwc2->fifo[epnum];
+ tu_fifo_read_n_const_addr_full_words(xfer->ff, (void*)(uintptr_t)tx_fifo, xact_bytes);
+ total_bytes_written += xact_bytes;
+ } else {
+ dfifo_write_packet(dwc2, epnum, xfer->buffer, xact_bytes);
+ xfer->buffer += xact_bytes;
+ total_bytes_written += xact_bytes;
+ }
+ }
+ return total_bytes_written;
+}
+
// Since this function returns void, it is not possible to return a boolean success message
// We must make sure that this function is not called when the EP is disabled
// Must be called from critical section
@@ -345,7 +386,7 @@ static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uin
// EP0 is limited to one packet per xfer
if (epnum == 0) {
- total_bytes = tu_min16(_dcd_data.ep0_pending[dir], xfer->max_size);
+ total_bytes = tu_min16(_dcd_data.ep0_pending[dir], CFG_TUD_ENDPOINT0_SIZE);
_dcd_data.ep0_pending[dir] -= total_bytes;
num_packets = 1;
} else {
@@ -366,7 +407,7 @@ static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uin
dwc2_depctl_t depctl = {.value = dep->ctl};
depctl.clear_nak = 1;
depctl.enable = 1;
- if (depctl.type == DEPCTL_EPTYPE_ISOCHRONOUS && xfer->interval == 1) {
+ if (depctl.type == DEPCTL_EPTYPE_ISOCHRONOUS) {
const dwc2_dsts_t dsts = {.value = dwc2->dsts};
const uint32_t odd_now = dsts.frame_number & 1u;
if (odd_now != 0) {
@@ -383,12 +424,21 @@ static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uin
}
dep->diepdma = (uintptr_t) xfer->buffer;
dep->diepctl = depctl.value; // enable endpoint
+ // Advance buffer pointer for EP0
+ if (epnum == 0) {
+ xfer->buffer += total_bytes;
+ }
} else {
dep->diepctl = depctl.value; // enable endpoint
- // Enable tx fifo empty interrupt only if there is data. Note must after depctl enable
if (dir == TUSB_DIR_IN && total_bytes != 0) {
- dwc2->diepempmsk |= (1u << epnum); //-V629
+ const uint16_t xferred_bytes = epin_write_tx_fifo(rhport, epnum);
+
+ // Enable TXFE interrupt if there are still data to be sent
+ // EP0 only sends one packet at a time, so no need to check for EP0
+ if ((epnum != 0) && (xfer->total_len - xferred_bytes > 0)) {
+ dwc2->diepempmsk |= (1u << epnum);
+ }
}
}
}
@@ -601,6 +651,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t to
xfer->buffer = buffer;
xfer->ff = NULL;
xfer->total_len = total_bytes;
+ xfer->iso_retry = xfer->interval; // Reset ISO retry counter to interval value
// EP0 can only handle one packet
if (epnum == 0) {
@@ -639,6 +690,7 @@ bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t* ff, uint16_t
xfer->buffer = NULL;
xfer->ff = ff;
xfer->total_len = total_bytes;
+ xfer->iso_retry = xfer->interval; // Reset ISO retry counter to interval value
// Schedule packets to be sent within interrupt
// TODO xfer fifo may only available for slave mode
@@ -741,7 +793,7 @@ static void handle_bus_reset(uint8_t rhport) {
dwc2->epout[0].doeptsiz |= (3 << DOEPTSIZ_STUPCNT_Pos);
}
- dwc2->gintmsk |= GINTMSK_OEPINT | GINTMSK_IEPINT;
+ dwc2->gintmsk |= GINTMSK_OEPINT | GINTMSK_IEPINT | GINTMSK_IISOIXFRM;
}
static void handle_enum_done(uint8_t rhport) {
@@ -838,11 +890,9 @@ static void handle_rxflvl_irq(uint8_t rhport) {
const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz};
xfer->total_len -= tsiz.xfer_size;
if (epnum == 0) {
- xfer->total_len -= _dcd_data.ep0_pending[TUSB_DIR_OUT];
_dcd_data.ep0_pending[TUSB_DIR_OUT] = 0;
}
}
-
break;
}
@@ -902,32 +952,10 @@ static void handle_epin_slave(uint8_t rhport, uint8_t epnum, dwc2_diepint_t diep
// - 64 bytes or
// - Half/Empty of TX FIFO size (configured by GAHBCFG.TXFELVL)
if (diepint_bm.txfifo_empty && tu_bit_test(dwc2->diepempmsk, epnum)) {
- dwc2_ep_tsize_t tsiz = {.value = epin->tsiz};
- const uint16_t remain_packets = tsiz.packet_count;
-
- // Process every single packet (only whole packets can be written to fifo)
- for (uint16_t i = 0; i < remain_packets; i++) {
- tsiz.value = epin->tsiz;
- const uint16_t remain_bytes = (uint16_t) tsiz.xfer_size;
- const uint16_t xact_bytes = tu_min16(remain_bytes, xfer->max_size);
-
- // Check if dtxfsts has enough space available
- if (xact_bytes > ((epin->dtxfsts & DTXFSTS_INEPTFSAV_Msk) << 2)) {
- break;
- }
-
- // Push packet to Tx-FIFO
- if (xfer->ff != NULL) {
- volatile uint32_t* tx_fifo = dwc2->fifo[epnum];
- tu_fifo_read_n_const_addr_full_words(xfer->ff, (void*)(uintptr_t)tx_fifo, xact_bytes);
- } else {
- dfifo_write_packet(dwc2, epnum, xfer->buffer, xact_bytes);
- xfer->buffer += xact_bytes;
- }
- }
+ epin_write_tx_fifo(rhport, epnum);
// Turn off TXFE if all bytes are written.
- tsiz.value = epin->tsiz;
+ dwc2_ep_tsize_t tsiz = {.value = epin->tsiz};
if (tsiz.xfer_size == 0) {
dwc2->diepempmsk &= ~(1u << epnum);
}
@@ -1040,6 +1068,43 @@ static void handle_ep_irq(uint8_t rhport, uint8_t dir) {
}
}
+static void handle_incomplete_iso_in(uint8_t rhport) {
+ dwc2_regs_t *dwc2 = DWC2_REG(rhport);
+ const dwc2_dsts_t dsts = {.value = dwc2->dsts};
+ const uint32_t odd_now = dsts.frame_number & 1u;
+
+ // Loop over all IN endpoints
+ const uint8_t ep_count = dwc2_ep_count(dwc2);
+ for (uint8_t epnum = 0; epnum < ep_count; epnum++) {
+ dwc2_dep_t *epin = &dwc2->epin[epnum];
+ dwc2_depctl_t depctl = {.value = epin->diepctl};
+ // Read DSTS and DIEPCTLn for all isochronous endpoints. If the current EP is enabled and the read value of
+ // DSTS.SOFFN is the targeted uframe number for this EP, then this EP has an incomplete transfer.
+ if (depctl.enable && depctl.type == DEPCTL_EPTYPE_ISOCHRONOUS && depctl.dpid_iso_odd == odd_now) {
+ xfer_ctl_t *xfer = XFER_CTL_BASE(epnum, TUSB_DIR_IN);
+ if (xfer->iso_retry > 0) {
+ xfer->iso_retry--;
+ // Restart ISO transfe: re-write TSIZ and CTL
+ dwc2_ep_tsize_t deptsiz = {.value = 0};
+ deptsiz.xfer_size = xfer->total_len;
+ deptsiz.packet_count = tu_div_ceil(xfer->total_len, xfer->max_size);
+ epin->tsiz = deptsiz.value;
+
+ if (odd_now) {
+ depctl.set_data0_iso_even = 1;
+ } else {
+ depctl.set_data1_iso_odd = 1;
+ }
+ epin->diepctl = depctl.value;
+ } else {
+ // too many retries, give up
+ edpt_disable(rhport, epnum | TUSB_DIR_IN_MASK, false);
+ dcd_event_xfer_complete(rhport, epnum | TUSB_DIR_IN_MASK, 0, XFER_RESULT_FAILED, true);
+ }
+ }
+ }
+}
+
/* Interrupt Hierarchy
DIEPINT DIEPINT
\ /
@@ -1139,6 +1204,12 @@ void dcd_int_handler(uint8_t rhport) {
// IEPINT bit read-only, clear using DIEPINTn
handle_ep_irq(rhport, TUSB_DIR_IN);
}
+
+ // Incomplete isochronous IN transfer interrupt handling.
+ if (gintsts & GINTSTS_IISOIXFR) {
+ dwc2->gintsts = GINTSTS_IISOIXFR;
+ handle_incomplete_iso_in(rhport);
+ }
}
#if CFG_TUD_TEST_MODE
diff --git a/src/portable/synopsys/dwc2/dwc2_common.h b/src/portable/synopsys/dwc2/dwc2_common.h
index dc204f578..428304ba9 100644
--- a/src/portable/synopsys/dwc2/dwc2_common.h
+++ b/src/portable/synopsys/dwc2/dwc2_common.h
@@ -94,13 +94,13 @@ void dwc2_core_handle_common_irq(uint8_t rhport, bool in_isr);
TU_ATTR_ALWAYS_INLINE static inline void dfifo_flush_tx(dwc2_regs_t* dwc2, uint8_t fnum) {
// flush TX fifo and wait for it cleared
dwc2->grstctl = GRSTCTL_TXFFLSH | (fnum << GRSTCTL_TXFNUM_Pos);
- while (dwc2->grstctl & GRSTCTL_TXFFLSH_Msk) {}
+ while (0 != (dwc2->grstctl & GRSTCTL_TXFFLSH_Msk)) {}
}
TU_ATTR_ALWAYS_INLINE static inline void dfifo_flush_rx(dwc2_regs_t* dwc2) {
// flush RX fifo and wait for it cleared
dwc2->grstctl = GRSTCTL_RXFFLSH;
- while (dwc2->grstctl & GRSTCTL_RXFFLSH_Msk) {}
+ while (0 != (dwc2->grstctl & GRSTCTL_RXFFLSH_Msk)) {}
}
void dfifo_read_packet(dwc2_regs_t* dwc2, uint8_t* dst, uint16_t len);
diff --git a/src/portable/synopsys/dwc2/dwc2_type.h b/src/portable/synopsys/dwc2/dwc2_type.h
index adcc579e3..7693ce02a 100644
--- a/src/portable/synopsys/dwc2/dwc2_type.h
+++ b/src/portable/synopsys/dwc2/dwc2_type.h
@@ -92,6 +92,16 @@ enum {
};
enum {
+ GUSBCFG_PHYSEL_HIGHSPEED = 0,
+ GUSBCFG_PHYSEL_FULLSPEED = 1,
+};
+
+enum {
+ GUSBCFG_PHYHS_UTMI = 0,
+ GUSBCFG_PHYHS_ULPI = 1,
+};
+
+enum {
GHWCFG2_OPMODE_HNP_SRP = 0,
GHWCFG2_OPMODE_SRP = 1,
GHWCFG2_OPMODE_NON_HNP_NON_SRP = 2,
diff --git a/src/portable/synopsys/dwc2/hcd_dwc2.c b/src/portable/synopsys/dwc2/hcd_dwc2.c
index e4ab16d9d..b92448685 100644
--- a/src/portable/synopsys/dwc2/hcd_dwc2.c
+++ b/src/portable/synopsys/dwc2/hcd_dwc2.c
@@ -32,19 +32,19 @@
#error DWC2 require either CFG_TUH_DWC2_SLAVE_ENABLE or CFG_TUH_DWC2_DMA_ENABLE to be enabled
#endif
-// Debug level for DWC2
-#define DWC2_DEBUG 2
-
#include "host/hcd.h"
#include "host/usbh.h"
#include "dwc2_common.h"
-// Max number of endpoints application can open, can be larger than DWC2_CHANNEL_COUNT_MAX
-#ifndef CFG_TUH_DWC2_ENDPOINT_MAX
-#define CFG_TUH_DWC2_ENDPOINT_MAX 16
-#endif
+ // Debug level for DWC2
+ #define DWC2_DEBUG 2
-#define DWC2_CHANNEL_COUNT_MAX 16 // absolute max channel count
+ // Max number of endpoints application can open, can be larger than DWC2_CHANNEL_COUNT_MAX
+ #ifndef CFG_TUH_DWC2_ENDPOINT_MAX
+ #define CFG_TUH_DWC2_ENDPOINT_MAX 16u
+ #endif
+
+ #define DWC2_CHANNEL_COUNT_MAX 16u // absolute max channel count
TU_VERIFY_STATIC(CFG_TUH_DWC2_ENDPOINT_MAX <= 255, "currently only use 8-bit for index");
enum {
@@ -79,7 +79,8 @@ typedef struct {
uint32_t speed : 2;
uint32_t next_pid : 2; // PID for next transfer
uint32_t next_do_ping : 1; // Do PING for next transfer if possible (highspeed OUT)
- // uint32_t : 9;
+ uint32_t closing : 1; // endpoint is closing
+ // uint32_t : 8;
};
uint32_t uframe_countdown; // micro-frame count down to transfer for periodic, only need 18-bit
@@ -96,6 +97,7 @@ typedef struct {
uint8_t err_count : 3;
uint8_t period_split_nyet_count : 3;
uint8_t halted_nyet : 1;
+ uint8_t closing : 1; // closing channel
};
uint8_t result;
@@ -195,8 +197,21 @@ TU_ATTR_ALWAYS_INLINE static inline void channel_dealloc(dwc2_regs_t* dwc2, uint
}
TU_ATTR_ALWAYS_INLINE static inline bool channel_disable(const dwc2_regs_t* dwc2, dwc2_channel_t* channel) {
- // disable also require request queue
- TU_ASSERT(req_queue_avail(dwc2, channel_is_periodic(channel->hcchar)));
+ const bool is_period = channel_is_periodic(channel->hcchar);
+ if (dma_host_enabled(dwc2)) {
+ // In buffer DMA or external DMA mode:
+ // - Channel disable must not be programmed for non-split periodic channels. At the end of the next uframe/frame (in
+ // the worst case), the controller generates a channel halted and disables the channel automatically.
+ // - For split enabled channels (both non-periodic and periodic), channel disable must not be programmed randomly.
+ // However, channel disable can be programmed for specific scenarios such as NAK and FrmOvrn.
+ if (is_period && (channel->hcsplt & HCSPLT_SPLITEN)) {
+ return true;
+ }
+ } else {
+ while (0 == req_queue_avail(dwc2, is_period)) {
+ // blocking wait for request queue available
+ }
+ }
channel->hcintmsk |= HCINT_HALTED;
channel->hcchar |= HCCHAR_CHDIS | HCCHAR_CHENA; // must set both CHDIS and CHENA
return true;
@@ -204,7 +219,9 @@ TU_ATTR_ALWAYS_INLINE static inline bool channel_disable(const dwc2_regs_t* dwc2
// attempt to send IN token to receive data
TU_ATTR_ALWAYS_INLINE static inline bool channel_send_in_token(const dwc2_regs_t* dwc2, dwc2_channel_t* channel) {
- TU_ASSERT(req_queue_avail(dwc2, channel_is_periodic(channel->hcchar)));
+ while (0 == req_queue_avail(dwc2, channel_is_periodic(channel->hcchar))) {
+ // blocking wait for request queue available
+ }
channel->hcchar |= HCCHAR_CHENA;
return true;
}
@@ -237,13 +254,37 @@ TU_ATTR_ALWAYS_INLINE static inline uint8_t edpt_alloc(void) {
return TUSB_INDEX_INVALID_8;
}
-// Find a endpoint that is opened previously with hcd_edpt_open()
+TU_ATTR_ALWAYS_INLINE static inline void edpt_dealloc(hcd_endpoint_t *edpt) {
+ edpt->hcchar_bm.enable = 0;
+}
+
+// close an opened endpoint
+static void edpt_close(dwc2_regs_t *dwc2, uint8_t ep_id) {
+ hcd_endpoint_t *edpt = &_hcd_data.edpt[ep_id];
+ edpt->closing = 1; // mark endpoint as closing
+
+ // disable active channel belong to this endpoint
+ for (uint8_t ch_id = 0; ch_id < DWC2_CHANNEL_COUNT_MAX; ch_id++) {
+ hcd_xfer_t *xfer = &_hcd_data.xfer[ch_id];
+ if (xfer->allocated && xfer->ep_id == ep_id) {
+ dwc2_channel_t *channel = &dwc2->channel[ch_id];
+ xfer->closing = 1;
+ channel_disable(dwc2, channel);
+ return; // only 1 active channel per endpoint
+ }
+ }
+
+ edpt_dealloc(edpt); // no active channel, safe to de-alloc now
+}
+
+// Find an endpoint that is opened previously with hcd_edpt_open()
// Note: EP0 is bidirectional
TU_ATTR_ALWAYS_INLINE static inline uint8_t edpt_find_opened(uint8_t dev_addr, uint8_t ep_num, uint8_t ep_dir) {
for (uint8_t i = 0; i < (uint8_t)CFG_TUH_DWC2_ENDPOINT_MAX; i++) {
- const dwc2_channel_char_t* hcchar_bm = &_hcd_data.edpt[i].hcchar_bm;
- if (hcchar_bm->enable && hcchar_bm->dev_addr == dev_addr &&
- hcchar_bm->ep_num == ep_num && (ep_num == 0 || hcchar_bm->ep_dir == ep_dir)) {
+ const hcd_endpoint_t *edpt = &_hcd_data.edpt[i];
+ const dwc2_channel_char_t hcchar_bm = edpt->hcchar_bm;
+ if (hcchar_bm.enable && hcchar_bm.dev_addr == dev_addr && hcchar_bm.ep_num == ep_num &&
+ (ep_num == 0 || hcchar_bm.ep_dir == ep_dir)) {
return i;
}
}
@@ -259,8 +300,8 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t cal_packet_count(uint16_t len, uint
}
TU_ATTR_ALWAYS_INLINE static inline uint8_t cal_next_pid(uint8_t pid, uint8_t packet_count) {
- if (packet_count & 0x01) {
- return pid ^ 0x02; // toggle DATA0 and DATA1
+ if (packet_count & 0x01u) {
+ return pid ^ 0x02u; // toggle DATA0 and DATA1
} else {
return pid;
}
@@ -456,11 +497,11 @@ tusb_speed_t hcd_port_speed_get(uint8_t rhport) {
// HCD closes all opened endpoints belong to this device
void hcd_device_close(uint8_t rhport, uint8_t dev_addr) {
- (void) rhport;
- for (uint8_t i = 0; i < (uint8_t) CFG_TUH_DWC2_ENDPOINT_MAX; i++) {
- hcd_endpoint_t* edpt = &_hcd_data.edpt[i];
+ dwc2_regs_t* dwc2 = DWC2_REG(rhport);
+ for (uint8_t ep_id = 0; ep_id < CFG_TUH_DWC2_ENDPOINT_MAX; ep_id++) {
+ const hcd_endpoint_t *edpt = &_hcd_data.edpt[ep_id];
if (edpt->hcchar_bm.enable && edpt->hcchar_bm.dev_addr == dev_addr) {
- tu_memclr(edpt, sizeof(hcd_endpoint_t));
+ edpt_close(dwc2, ep_id);
}
}
}
@@ -503,25 +544,39 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t*
edpt->speed = bus_info.speed;
edpt->next_pid = HCTSIZ_PID_DATA0;
- if (desc_ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) {
- edpt->uframe_interval = 1 << (desc_ep->bInterval - 1);
- if (bus_info.speed == TUSB_SPEED_FULL) {
- edpt->uframe_interval <<= 3;
- }
- } else if (desc_ep->bmAttributes.xfer == TUSB_XFER_INTERRUPT) {
- if (bus_info.speed == TUSB_SPEED_HIGH) {
+ switch (desc_ep->bmAttributes.xfer) {
+ case TUSB_XFER_ISOCHRONOUS:
edpt->uframe_interval = 1 << (desc_ep->bInterval - 1);
- } else {
- edpt->uframe_interval = desc_ep->bInterval << 3;
- }
+ if (bus_info.speed == TUSB_SPEED_FULL) {
+ edpt->uframe_interval <<= 3;
+ }
+ break;
+
+ case TUSB_XFER_INTERRUPT:
+ if (bus_info.speed == TUSB_SPEED_HIGH) {
+ edpt->uframe_interval = 1 << (desc_ep->bInterval - 1);
+ } else {
+ edpt->uframe_interval = desc_ep->bInterval << 3;
+ }
+ break;
+
+ default:
+ break;
}
return true;
}
bool hcd_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) {
- (void) rhport; (void) daddr; (void) ep_addr;
- return false; // TODO not implemented yet
+ dwc2_regs_t *dwc2 = DWC2_REG(rhport);
+ const uint8_t ep_num = tu_edpt_number(ep_addr);
+ const uint8_t ep_dir = tu_edpt_dir(ep_addr);
+ const uint8_t ep_id = edpt_find_opened(daddr, ep_num, ep_dir);
+ TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX);
+
+ edpt_close(dwc2, ep_id);
+
+ return true;
}
// clean up channel after part of transfer is done but the whole urb is not complete
@@ -590,8 +645,7 @@ static bool channel_xfer_start(dwc2_regs_t* dwc2, uint8_t ch_id) {
channel->hcint = 0xFFFFFFFFU; // clear all channel interrupts
if (dma_host_enabled(dwc2)) {
- uint32_t hcintmsk = HCINT_HALTED;
- channel->hcintmsk = hcintmsk;
+ channel->hcintmsk = HCINT_HALTED;
dwc2->haintmsk |= TU_BIT(ch_id);
channel->hcdma = (uint32_t) edpt->buffer;
@@ -646,7 +700,6 @@ static bool edpt_xfer_kickoff(dwc2_regs_t* dwc2, uint8_t ep_id) {
return channel_xfer_start(dwc2, ch_id);
}
-// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) {
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
const uint8_t ep_num = tu_edpt_number(ep_addr);
@@ -654,7 +707,8 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir);
TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX);
- hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id];
+ hcd_endpoint_t *edpt = &_hcd_data.edpt[ep_id];
+ TU_VERIFY(edpt->closing == 0); // skip if endpoint is closing
edpt->buffer = buffer;
edpt->buflen = buflen;
@@ -754,7 +808,7 @@ static void channel_xfer_in_retry(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hci
edpt->next_pid = hctsiz.pid; // save PID
edpt->uframe_countdown = edpt->uframe_interval - ucount;
// enable SOF interrupt if not already enabled
- if (!(dwc2->gintmsk & GINTMSK_SOFM)) {
+ if (0 == (dwc2->gintmsk & GINTMSK_SOFM)) {
dwc2->gintsts = GINTSTS_SOF;
dwc2->gintmsk |= GINTMSK_SOFM;
}
@@ -801,7 +855,7 @@ static void handle_rxflvl_irq(uint8_t rhport) {
TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX,);
hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id];
- if (byte_count) {
+ if (byte_count > 0) {
dfifo_read_packet(dwc2, edpt->buffer + xfer->xferred_bytes, byte_count);
xfer->xferred_bytes += byte_count;
xfer->fifo_bytes = byte_count;
@@ -837,8 +891,8 @@ static bool handle_txfifo_empty(dwc2_regs_t* dwc2, bool is_periodic) {
dwc2_channel_t* channel = &dwc2->channel[ch_id];
const dwc2_channel_char_t hcchar = {.value = channel->hcchar};
// skip writing to FIFO if channel is expecting halted.
- if (!(channel->hcintmsk & HCINT_HALTED) && (hcchar.ep_dir == TUSB_DIR_OUT)) {
- hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id];
+ if (0 == (channel->hcintmsk & HCINT_HALTED) && (hcchar.ep_dir == TUSB_DIR_OUT)) {
+ hcd_xfer_t *xfer = &_hcd_data.xfer[ch_id];
TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX);
hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id];
const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz};
@@ -899,6 +953,8 @@ static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t h
} else if (hcint & HCINT_XACT_ERR) {
xfer->err_count++;
channel->hcintmsk |= HCINT_ACK;
+ } else {
+ // nothing to do
}
channel_disable(dwc2, channel);
@@ -910,7 +966,7 @@ static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t h
channel_disable(dwc2, channel);
} else if (hcint & HCINT_NAK) {
// NAK received, disable channel to flush all posted request and try again
- if (hcsplt.split_en) {
+ if (hcsplt.split_en == 1u) {
hcsplt.split_compl = 0; // restart with start-split
channel->hcsplt = hcsplt.value;
}
@@ -919,8 +975,8 @@ static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t h
} else if (hcint & HCINT_ACK) {
xfer->err_count = 0;
- if (hcsplt.split_en) {
- if (!hcsplt.split_compl) {
+ if (hcsplt.split_en == 1u) {
+ if (hcsplt.split_compl == 0) {
// start split is ACK --> do complete split
channel->hcintmsk |= HCINT_NYET;
hcsplt.split_compl = 1;
@@ -932,7 +988,7 @@ static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t h
} else {
// ACK with data
const uint16_t remain_packets = hctsiz.packet_count;
- if (remain_packets) {
+ if (remain_packets > 0) {
// still more packet to receive, also reset to start split
hcsplt.split_compl = 0;
channel->hcsplt = hcsplt.value;
@@ -945,6 +1001,8 @@ static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t h
is_done = true;
} else if (xfer->err_count == HCD_XFER_ERROR_MAX) {
xfer->result = XFER_RESULT_FAILED;
+ is_done = true;
+ } else if (xfer->closing == 1) {
is_done = true;
} else {
// got here due to NAK or NYET
@@ -953,6 +1011,8 @@ static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t h
} else if (hcint & HCINT_DATATOGGLE_ERR) {
xfer->err_count = 0;
TU_ASSERT(false);
+ } else {
+ // nothing to do
}
return is_done;
}
@@ -977,7 +1037,7 @@ static bool handle_channel_out_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t
channel_disable(dwc2, channel);
} else if (hcint & HCINT_NYET) {
xfer->err_count = 0;
- if (hcsplt.split_en) {
+ if (hcsplt.split_en == 1u) {
// retry complete split
hcsplt.split_compl = 1;
channel->hcsplt = hcsplt.value;
@@ -1005,6 +1065,8 @@ static bool handle_channel_out_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t
is_done = true;
} else if (xfer->err_count == HCD_XFER_ERROR_MAX) {
xfer->result = XFER_RESULT_FAILED;
+ is_done = true;
+ } else if (xfer->closing == 1) {
is_done = true;
} else {
// Got here due to NAK or NYET
@@ -1013,8 +1075,8 @@ static bool handle_channel_out_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t
} else if (hcint & HCINT_ACK) {
xfer->err_count = 0;
channel->hcintmsk &= ~HCINT_ACK;
- if (hcsplt.split_en) {
- if (!hcsplt.split_compl) {
+ if (hcsplt.split_en == 1u) {
+ if (hcsplt.split_compl == 0) {
// ACK for start split --> do complete split
hcsplt.split_compl = 1;
channel->hcsplt = hcsplt.value;
@@ -1026,6 +1088,8 @@ static bool handle_channel_out_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t
channel->hctsiz &= ~HCTSIZ_DOPING; // HC already cleared PING bit, but we clear anyway
channel->hcchar |= HCCHAR_CHENA;
}
+ } else {
+ // nothing to do
}
if (is_done) {
@@ -1122,6 +1186,10 @@ static bool handle_channel_in_dma(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hci
// retry start-split in next binterval
channel_xfer_in_retry(dwc2, ch_id, hcint);
}
+
+ if (xfer->closing == 1) {
+ is_done = true;
+ }
}
return is_done;
@@ -1182,6 +1250,10 @@ static bool handle_channel_out_dma(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hc
channel->hcchar |= HCCHAR_CHENA;
}
}
+
+ if (xfer->closing == 1) {
+ is_done = true;
+ }
} else if (hcint & HCINT_ACK) {
xfer->err_count = 0;
channel->hcintmsk &= ~HCINT_ACK;
@@ -1226,12 +1298,17 @@ static void handle_channel_irq(uint8_t rhport, bool in_isr) {
} else {
is_done = handle_channel_in_slave(dwc2, ch_id, hcint);
}
- #endif
+ #endif
}
if (is_done) {
- const uint8_t ep_addr = tu_edpt_addr(hcchar.ep_num, hcchar.ep_dir);
- hcd_event_xfer_complete(hcchar.dev_addr, ep_addr, xfer->xferred_bytes, (xfer_result_t)xfer->result, in_isr);
+ if (xfer->closing == 1) {
+ hcd_endpoint_t *edpt = &_hcd_data.edpt[xfer->ep_id];
+ edpt_dealloc(edpt);
+ } else {
+ const uint8_t ep_addr = tu_edpt_addr(hcchar.ep_num, hcchar.ep_dir);
+ hcd_event_xfer_complete(hcchar.dev_addr, ep_addr, xfer->xferred_bytes, (xfer_result_t)xfer->result, in_isr);
+ }
channel_dealloc(dwc2, ch_id);
}
}
@@ -1250,16 +1327,18 @@ static bool handle_sof_irq(uint8_t rhport, bool in_isr) {
const uint32_t ucount = (hprt_speed_get(dwc2) == TUSB_SPEED_HIGH ? 1 : 8);
for(uint8_t ep_id = 0; ep_id < CFG_TUH_DWC2_ENDPOINT_MAX; ep_id++) {
- hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id];
- if (edpt->hcchar_bm.enable && channel_is_periodic(edpt->hcchar) && edpt->uframe_countdown > 0) {
- edpt->uframe_countdown -= tu_min32(ucount, edpt->uframe_countdown);
- if (edpt->uframe_countdown == 0) {
- if (!edpt_xfer_kickoff(dwc2, ep_id)) {
- edpt->uframe_countdown = ucount; // failed to start, try again next frame
+ hcd_endpoint_t *edpt = &_hcd_data.edpt[ep_id];
+ if (edpt->closing == 0) {
+ if (edpt->hcchar_bm.enable && channel_is_periodic(edpt->hcchar) && edpt->uframe_countdown > 0) {
+ edpt->uframe_countdown -= tu_min32(ucount, edpt->uframe_countdown);
+ if (edpt->uframe_countdown == 0) {
+ if (!edpt_xfer_kickoff(dwc2, ep_id)) {
+ edpt->uframe_countdown = ucount; // failed to start, try again next frame
+ }
}
- }
- more_isr = true;
+ more_isr = true;
+ }
}
}
@@ -1271,9 +1350,9 @@ static void port0_enable(dwc2_regs_t* dwc2, tusb_speed_t speed) {
uint32_t hcfg = dwc2->hcfg & ~HCFG_FSLS_PHYCLK_SEL;
const dwc2_gusbcfg_t gusbcfg = {.value = dwc2->gusbcfg};
- uint32_t phy_clock;
+ uint32_t phy_clock;
- if (gusbcfg.phy_sel) {
+ if (gusbcfg.phy_sel == GUSBCFG_PHYSEL_FULLSPEED) {
phy_clock = 48; // dedicated FS is 48Mhz
if (speed == TUSB_SPEED_LOW) {
hcfg |= HCFG_FSLS_PHYCLK_SEL_6MHZ;
@@ -1281,7 +1360,7 @@ static void port0_enable(dwc2_regs_t* dwc2, tusb_speed_t speed) {
hcfg |= HCFG_FSLS_PHYCLK_SEL_48MHZ;
}
} else {
- if (gusbcfg.ulpi_utmi_sel) {
+ if (gusbcfg.ulpi_utmi_sel == GUSBCFG_PHYHS_ULPI) {
phy_clock = 60; // ULPI 8-bit is 60Mhz
} else {
// UTMI+ 16-bit is 30Mhz, 8-bit is 60Mhz
@@ -1320,20 +1399,20 @@ static void handle_hprt_irq(uint8_t rhport, bool in_isr) {
const dwc2_hprt_t hprt_bm = {.value = dwc2->hprt};
uint32_t hprt = hprt_bm.value & ~HPRT_W1_MASK;
- if (hprt_bm.conn_detected) {
+ if (hprt_bm.conn_detected == 1u) {
// Port Connect Detect
hprt |= HPRT_CONN_DETECT;
- if (hprt_bm.conn_status) {
+ if (hprt_bm.conn_status == 1u) {
hcd_event_device_attach(rhport, in_isr);
}
}
- if (hprt_bm.enable_change) {
+ if (hprt_bm.enable_change == 1u) {
// Port enable change
hprt |= HPRT_ENABLE_CHANGE;
- if (hprt_bm.enable) {
+ if (hprt_bm.enable == 1u) {
// Port enable
const tusb_speed_t speed = hprt_speed_get(dwc2);
port0_enable(dwc2, speed);
@@ -1392,7 +1471,7 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
// Device disconnected
dwc2->gintsts = GINTSTS_DISCINT;
- if (!(dwc2->hprt & HPRT_CONN_STATUS)) {
+ if (0 == (dwc2->hprt & HPRT_CONN_STATUS)) {
hcd_event_device_remove(rhport, in_isr);
}
}
diff --git a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
index 10c7d78c5..5f4b139d8 100644
--- a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
+++ b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
@@ -333,11 +333,20 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
return true;
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
- (void) rhport; (void) ep_addr;
- // TODO implement dcd_edpt_close()
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
}
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
+}
+
+
void dcd_edpt_close_all (uint8_t rhport)
{
(void) rhport;
@@ -823,5 +832,4 @@ void dcd_int_handler(uint8_t rhport)
}
}
-
#endif
diff --git a/src/portable/valentyusb/eptri/dcd_eptri.c b/src/portable/valentyusb/eptri/dcd_eptri.c
index 760f3c90a..1b555b3b7 100644
--- a/src/portable/valentyusb/eptri/dcd_eptri.c
+++ b/src/portable/valentyusb/eptri/dcd_eptri.c
@@ -438,9 +438,17 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
return true;
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
- (void) rhport; (void) ep_addr;
- // TODO implement dcd_edpt_close()
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void)rhport;
+ (void)ep_addr;
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
}
void dcd_edpt_close_all (uint8_t rhport)
@@ -660,5 +668,4 @@ void dcd_int_handler(uint8_t rhport)
}
}
}
-
#endif
diff --git a/src/portable/wch/dcd_ch32_usbfs.c b/src/portable/wch/dcd_ch32_usbfs.c
index eb2ebd868..5cd25e33e 100644
--- a/src/portable/wch/dcd_ch32_usbfs.c
+++ b/src/portable/wch/dcd_ch32_usbfs.c
@@ -283,10 +283,17 @@ void dcd_edpt_close_all(uint8_t rhport) {
// TODO optional
}
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
(void) rhport;
(void) ep_addr;
- // TODO optional
+ (void)largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, const tusb_desc_endpoint_t *desc_ep) {
+ (void)rhport;
+ (void)desc_ep;
+ return false;
}
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes, bool is_isr) {
@@ -345,5 +352,4 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
}
}
}
-
#endif
diff --git a/src/portable/wch/dcd_ch32_usbhs.c b/src/portable/wch/dcd_ch32_usbhs.c
index a18eb3e81..11734de37 100644
--- a/src/portable/wch/dcd_ch32_usbhs.c
+++ b/src/portable/wch/dcd_ch32_usbhs.c
@@ -27,13 +27,14 @@
#include "tusb_option.h"
-#if CFG_TUD_ENABLED && defined(TUP_USBIP_WCH_USBHS) && defined(CFG_TUD_WCH_USBIP_USBHS) && CFG_TUD_WCH_USBIP_USBHS
-#include "ch32_usbhs_reg.h"
+#if CFG_TUD_ENABLED && defined(TUP_USBIP_WCH_USBHS) && defined(CFG_TUD_WCH_USBIP_USBHS) && \
+ (CFG_TUD_WCH_USBIP_USBHS == 1)
+ #include "ch32_usbhs_reg.h"
-#include "device/dcd.h"
+ #include "device/dcd.h"
-// Max number of bi-directional endpoints including EP0
-#define EP_MAX 16
+ // Max number of bi-directional endpoints including EP0
+ #define EP_MAX 16
typedef struct {
uint8_t* buffer;
@@ -288,6 +289,21 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
}
}
+ #if 0
+bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
+ (void) rhport;
+ (void) ep_addr;
+ (void) largest_packet_size;
+ return false;
+}
+
+bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep) {
+ (void) rhport;
+ (void) desc_ep;
+ return false;
+}
+ #endif
+
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
(void) rhport;
@@ -420,5 +436,4 @@ void dcd_int_handler(uint8_t rhport) {
USBHSD->INT_FG = USBHS_SUSPEND_FLAG; /* Clear flag */
}
}
-
#endif