Skip to content

Commit 9554283

Browse files
authored
Merge pull request hathach#2175 from hathach/hcd-abort-xfer
Add HCD abort xfer API
2 parents 0b38941 + fda92fd commit 9554283

File tree

15 files changed

+312
-171
lines changed

15 files changed

+312
-171
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

hw/bsp/rp2040/board.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@
5454
// default to pin on Adafruit Feather rp2040 USB Host or Tester if defined
5555
//--------------------------------------------------------------------+
5656

57-
// #define USE_ADAFRUIT_RP2040_TESTER
58-
#ifdef USE_ADAFRUIT_RP2040_TESTER
59-
#define PICO_DEFAULT_PIO_USB_DP_PIN 20
60-
#define PICO_DEFAULT_PIO_USB_VBUSEN_PIN 22
57+
// #define USE_ADAFRUIT_FEATHER_RP2040_USBHOST
58+
#ifdef USE_ADAFRUIT_FEATHER_RP2040_USBHOST
59+
#define PICO_DEFAULT_PIO_USB_DP_PIN 16
60+
#define PICO_DEFAULT_PIO_USB_VBUSEN_PIN 18
6161
#endif
6262

6363
#ifndef PICO_DEFAULT_PIO_USB_DP_PIN
64-
#define PICO_DEFAULT_PIO_USB_DP_PIN 16
64+
#define PICO_DEFAULT_PIO_USB_DP_PIN 20
6565
#endif
6666

6767
// VBUS enable pin and its active state
6868
#ifndef PICO_DEFAULT_PIO_USB_VBUSEN_PIN
69-
#define PICO_DEFAULT_PIO_USB_VBUSEN_PIN 18
69+
#define PICO_DEFAULT_PIO_USB_VBUSEN_PIN 22
7070
#endif
7171

7272
// VBUS enable state

src/common/tusb_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#define U32_TO_U8S_LE(_u32) TU_U32_BYTE0(_u32), TU_U32_BYTE1(_u32), TU_U32_BYTE2(_u32), TU_U32_BYTE3(_u32)
5454

5555
#define TU_BIT(n) (1UL << (n))
56+
57+
// Generate a mask with bit from high (31) to low (0) set, e.g TU_GENMASK(3, 0) = 0b1111
5658
#define TU_GENMASK(h, l) ( (UINT32_MAX << (l)) & (UINT32_MAX >> (31 - (h))) )
5759

5860
//--------------------------------------------------------------------+

src/host/hcd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ 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+
// Return true if a queued transfer is aborted, false if there is no transfer to abort
176+
bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr);
177+
174178
// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked
175179
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]);
176180

src/host/usbh.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,25 @@ 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+
TU_VERIFY(dev->ep_status[epnum][dir].busy);
722+
723+
bool const ret = hcd_edpt_abort_xfer(dev->rhport, daddr, ep_addr);
724+
if (ret) {
725+
// mark as ready if transfer is aborted
726+
dev->ep_status[epnum][dir].busy = false;
727+
}
728+
729+
return ret;
730+
}
731+
713732
//--------------------------------------------------------------------+
714733
// USBH API For Class Driver
715734
//--------------------------------------------------------------------+
@@ -741,7 +760,7 @@ void usbh_int_set(bool enabled)
741760
// Endpoint API
742761
//--------------------------------------------------------------------+
743762

744-
// TODO has some duplication code with device, refactor later
763+
// Claim an endpoint for transfer
745764
bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr)
746765
{
747766
// Note: addr0 only use tuh_control_xfer
@@ -757,7 +776,7 @@ bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr)
757776
return true;
758777
}
759778

760-
// TODO has some duplication code with device, refactor later
779+
// Release an claimed endpoint due to failed transfer attempt
761780
bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr)
762781
{
763782
// Note: addr0 only use tuh_control_xfer
@@ -773,7 +792,7 @@ bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr)
773792
return true;
774793
}
775794

776-
// TODO has some duplication code with device, refactor later
795+
// Submit an transfer
777796
bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes,
778797
tuh_xfer_cb_t complete_cb, uintptr_t user_data)
779798
{
@@ -840,14 +859,13 @@ bool tuh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep)
840859
return hcd_edpt_open(usbh_get_rhport(dev_addr), dev_addr, desc_ep);
841860
}
842861

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-
862+
bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) {
848863
usbh_device_t* dev = get_device(dev_addr);
849864
TU_VERIFY(dev);
850865

866+
uint8_t const epnum = tu_edpt_number(ep_addr);
867+
uint8_t const dir = tu_edpt_dir(ep_addr);
868+
851869
return dev->ep_status[epnum][dir].busy;
852870
}
853871

src/host/usbh.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,12 @@ 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+
// Return true if a queued transfer is aborted, false if there is no transfer to abort
180+
bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr);
177181

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

0 commit comments

Comments
 (0)