Skip to content

Commit 5e5c40c

Browse files
zeonchewkartben
authored andcommitted
drivers: udc_ambiq: added support for double endpoint buffer
implements option to enable double endpoint buffer to improve throughtput for non-control endpoints. Signed-off-by: Chew Zeh Yang <[email protected]>
1 parent 46cdb84 commit 5e5c40c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

drivers/usb/udc/Kconfig.ambiq

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,20 @@ config UDC_AMBIQ_PIO_MODE
5656
Select this option when cache coherency handling is to be avoided.
5757
endchoice
5858

59+
config UDC_AMBIQ_DEB_ENABLE
60+
hex "EP Double Buffer Enable"
61+
default 0x0000
62+
depends on SOC_SERIES_APOLLO5X
63+
help
64+
Double Endpoint Buffer acceleration (DEB) is doubles an EP's FIFO size so
65+
that USB transfer could continue to happen while waiting for DMA/CPU to
66+
load/unload data from the EP FIFO. This hex value is a bitmap of endpoints
67+
for DEB to be enabled. BIT0-4 represents OUT_EP 1-5, while BIT16-20
68+
represents IN_EP 1-5. Take note that this feature is limited by total EP
69+
FIFO size. Proper calculation should be done before enabling DEB such that
70+
the total usage of FIFO for all endpoint doesn't exceed the FIFO available
71+
on SoC. The list of Soc with its FIFO size is listed below. The FIFO size
72+
here includes 128 bytes required by control endpoints.
73+
- Apollo510: (4096 Bytes FIFO)
74+
5975
endif # UDC_AMBIQ

drivers/usb/udc/udc_ambiq.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,29 @@ static int init_apollo5x(const struct udc_ambiq_data *priv)
565565
}
566566
#endif
567567

568+
#if CONFIG_UDC_AMBIQ_DEB_ENABLE
569+
static void init_double_buffers(const struct udc_ambiq_data *priv)
570+
{
571+
uint32_t mask;
572+
573+
mask = CONFIG_UDC_AMBIQ_DEB_ENABLE & 0xFFFF;
574+
while (mask) {
575+
uint32_t ep = find_lsb_set(mask);
576+
577+
am_hal_usb_enable_ep_double_buffer(priv->usb_handle, ep, AM_HAL_USB_OUT_DIR, true);
578+
mask &= ~(1U << (ep - 1));
579+
}
580+
581+
mask = (CONFIG_UDC_AMBIQ_DEB_ENABLE >> 16) & 0xFFFF;
582+
while (mask) {
583+
uint32_t ep = find_lsb_set(mask);
584+
585+
am_hal_usb_enable_ep_double_buffer(priv->usb_handle, ep, AM_HAL_USB_IN_DIR, true);
586+
mask &= ~(1U << (ep - 1));
587+
}
588+
}
589+
#endif
590+
568591
static int udc_ambiq_init(const struct device *dev)
569592
{
570593
struct udc_ambiq_data *priv = udc_get_private(dev);
@@ -599,6 +622,10 @@ static int udc_ambiq_init(const struct device *dev)
599622
}
600623
#endif
601624

625+
#if CONFIG_UDC_AMBIQ_DEB_ENABLE
626+
init_double_buffers(priv);
627+
#endif
628+
602629
/* Set USB Speed */
603630
am_hal_usb_set_dev_speed(priv->usb_handle, priv->usb_speed);
604631
/* Enable USB interrupt */

0 commit comments

Comments
 (0)