Skip to content

Commit 76e0cbb

Browse files
committed
drivers: udc_ambiq: added support double endpoint buffer
implements option to enable double endpoint buffer to improve throughtput for the endpoints. Signed-off-by: Chew Zeh Yang <[email protected]>
1 parent 1bf7bf3 commit 76e0cbb

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

drivers/usb/udc/Kconfig.ambiq

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,21 @@ config UDC_AMBIQ_ISR_PARAM_COUNT
7272
default 5 if SOC_SERIES_APOLLO5X
7373
default 3
7474

75+
config UDC_AMBIQ_DEB_ENABLE
76+
hex "EP Double Buffer Enable"
77+
default 0x0000
78+
depends on SOC_SERIES_APOLLO5X
79+
help
80+
Double Endpoint Buffer acceleration (DEB) is doubles an EP's FIFO size
81+
so that USB transfer could continue to happen while waiting for DMA/CPU to
82+
load/unload data from the EP FIFO.
83+
This hex value is a bitmap of endpoints for DEB to be enabled. BIT0-4
84+
represents OUT_EP 1-5, while BIT16-20 represents IN_EP 1-8.
85+
Take note that this feature is limited by total EP FIFO size. Proper
86+
calculation should be done before enabling DEB such that the total usage
87+
of FIFO for all endpoint doesn't exceed the FIFO available on SoC.
88+
The list of Soc with its FIFO size is listed below. The FIFO size here
89+
includes 128 bytes required by control endpoints.
90+
- Apollo510: (4096 Bytes FIFO)
91+
7592
endif # UDC_AMBIQ

drivers/usb/udc/udc_ambiq.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,36 @@ static int init_apollo5x(const struct udc_ambiq_data *priv)
579579
}
580580
#endif
581581

582+
#if CONFIG_UDC_AMBIQ_DEB_ENABLE
583+
static void init_double_buffers(const struct udc_ambiq_data *priv)
584+
{
585+
uint8_t idx;
586+
uint32_t mask;
587+
588+
idx = 1;
589+
mask = CONFIG_UDC_AMBIQ_DEB_ENABLE & 0xFFFF;
590+
while (mask) {
591+
if (mask & 0x1) {
592+
am_hal_usb_enable_ep_double_buffer(priv->usb_handle, idx,
593+
AM_HAL_USB_OUT_DIR, true);
594+
}
595+
idx++;
596+
mask >>= 1;
597+
}
598+
599+
idx = 1;
600+
mask = (CONFIG_UDC_AMBIQ_DEB_ENABLE >> 16) & 0xFFFF;
601+
while (mask) {
602+
if (mask & 0x1) {
603+
am_hal_usb_enable_ep_double_buffer(priv->usb_handle, idx, AM_HAL_USB_IN_DIR,
604+
true);
605+
}
606+
idx++;
607+
mask >>= 1;
608+
}
609+
}
610+
#endif
611+
582612
static int udc_ambiq_init(const struct device *dev)
583613
{
584614
struct udc_ambiq_data *priv = udc_get_private(dev);
@@ -613,6 +643,10 @@ static int udc_ambiq_init(const struct device *dev)
613643
}
614644
#endif
615645

646+
#if CONFIG_UDC_AMBIQ_DEB_ENABLE
647+
init_double_buffers(priv);
648+
#endif
649+
616650
/* Set USB Speed */
617651
am_hal_usb_set_dev_speed(priv->usb_handle, priv->usb_speed);
618652
/* Enable USB interrupt */

0 commit comments

Comments
 (0)