Skip to content

Commit 1cc7c5d

Browse files
committed
add hcd_edpt_abort_xfer() API
1 parent 17576a6 commit 1cc7c5d

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
board:mimxrt1060_evk
22
board:mimxrt1064_evk
3+
board:mcb1800
34
mcu:RP2040

src/host/hcd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
171171
// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked
172172
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);
173173

174+
// Abort a queued transfer. Note: it can only abort transfer that has not been started
175+
bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr);
176+
174177
// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked
175178
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]);
176179

src/host/usbh.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,19 @@ bool tuh_edpt_xfer(tuh_xfer_t* xfer)
710710
return true;
711711
}
712712

713+
bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr) {
714+
usbh_device_t* dev = get_device(daddr);
715+
TU_VERIFY(dev);
716+
717+
uint8_t const epnum = tu_edpt_number(ep_addr);
718+
uint8_t const dir = tu_edpt_dir(ep_addr);
719+
720+
// skip if not busy
721+
if (!dev->ep_status[epnum][dir].busy) return true;
722+
723+
return hcd_edpt_abort_xfer(dev->rhport, daddr, ep_addr);
724+
}
725+
713726
//--------------------------------------------------------------------+
714727
// USBH API For Class Driver
715728
//--------------------------------------------------------------------+
@@ -741,7 +754,7 @@ void usbh_int_set(bool enabled)
741754
// Endpoint API
742755
//--------------------------------------------------------------------+
743756

744-
// TODO has some duplication code with device, refactor later
757+
// Claim an endpoint for transfer
745758
bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr)
746759
{
747760
// Note: addr0 only use tuh_control_xfer
@@ -757,7 +770,7 @@ bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr)
757770
return true;
758771
}
759772

760-
// TODO has some duplication code with device, refactor later
773+
// Release an claimed endpoint due to failed transfer attempt
761774
bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr)
762775
{
763776
// Note: addr0 only use tuh_control_xfer
@@ -773,7 +786,7 @@ bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr)
773786
return true;
774787
}
775788

776-
// TODO has some duplication code with device, refactor later
789+
// Submit an transfer
777790
bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes,
778791
tuh_xfer_cb_t complete_cb, uintptr_t user_data)
779792
{
@@ -840,14 +853,13 @@ bool tuh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep)
840853
return hcd_edpt_open(usbh_get_rhport(dev_addr), dev_addr, desc_ep);
841854
}
842855

843-
bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
844-
{
845-
uint8_t const epnum = tu_edpt_number(ep_addr);
846-
uint8_t const dir = tu_edpt_dir(ep_addr);
847-
856+
bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) {
848857
usbh_device_t* dev = get_device(dev_addr);
849858
TU_VERIFY(dev);
850859

860+
uint8_t const epnum = tu_edpt_number(ep_addr);
861+
uint8_t const dir = tu_edpt_dir(ep_addr);
862+
851863
return dev->ep_status[epnum][dir].busy;
852864
}
853865

src/host/usbh.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ bool tuh_control_xfer(tuh_xfer_t* xfer);
172172
// - sync : blocking if complete callback is NULL.
173173
bool tuh_edpt_xfer(tuh_xfer_t* xfer);
174174

175-
// Open an non-control endpoint
176-
bool tuh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep);
175+
// Open a non-control endpoint
176+
bool tuh_edpt_open(uint8_t daddr, tusb_desc_endpoint_t const * desc_ep);
177+
178+
// Abort a queued transfer. Note: it can only abort transfer that has not been started
179+
bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr);
177180

178181
// Set Configuration (control transfer)
179182
// config_num = 0 will un-configure device. Note: config_num = config_descriptor_index + 1

src/portable/ehci/ehci.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,24 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
510510
return true;
511511
}
512512

513+
bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) {
514+
(void) rhport;
515+
(void) dev_addr;
516+
(void) ep_addr;
517+
518+
return false;
519+
520+
// uint8_t const epnum = tu_edpt_number(ep_addr);
521+
// ehci_qhd_t* qhd;
522+
//
523+
// // TODO ISO not supported
524+
// if (epnum == 0) {
525+
// qhd = qhd_control(dev_addr);
526+
// }else {
527+
// qhd = qhd_get_from_addr(dev_addr, ep_addr);
528+
// }
529+
}
530+
513531
bool hcd_edpt_clear_stall(uint8_t daddr, uint8_t ep_addr)
514532
{
515533
ehci_qhd_t *qhd = qhd_get_from_addr(daddr, ep_addr);

0 commit comments

Comments
 (0)