This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 16d0ecde8869646006a35b2d94aec399ff59d058
Author: chao an <[email protected]>
AuthorDate: Mon Oct 26 14:17:39 2026 +0800

    drivers/usbhost/cdcacm: Copy TX buffers in chunks
    
    Replace the byte-at-a-time copy from the UART TX ring to the USB bulk OUT
    buffer with memcpy() over the current contiguous ring segment.
    
    The transmit worker caps each copy by both the ring boundary and the
    remaining USB packet space, then advances the ring tail by the copied
    length.  The existing transfer submission and uart_datasent() flow are
    unchanged.
    
    This reduces loop overhead when CDC ACM writes can fill larger USB bulk
    packets from the UART transmit buffer.
    
    Signed-off-by: chao an <[email protected]>
---
 drivers/usbhost/usbhost_cdcacm.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/usbhost/usbhost_cdcacm.c b/drivers/usbhost/usbhost_cdcacm.c
index eba9bf8db16..877c18e8d20 100644
--- a/drivers/usbhost/usbhost_cdcacm.c
+++ b/drivers/usbhost/usbhost_cdcacm.c
@@ -902,8 +902,10 @@ static void usbhost_txdata_work(FAR void *arg)
   FAR struct uart_dev_s *uartdev;
   FAR struct uart_buffer_s *txbuf;
   ssize_t nwritten;
+  int txhead;
   int txndx;
   int txtail;
+  int ncopy;
   int ret;
 
   priv = (FAR struct usbhost_cdcacm_s *)arg;
@@ -938,16 +940,30 @@ static void usbhost_txdata_work(FAR void *arg)
       txndx = 0;
       while (txtail != txbuf->head && txndx < priv->pktsize)
         {
-          /* Copy the next byte */
+          txhead = txbuf->head;
+          if (txtail < txhead)
+            {
+              ncopy = txhead - txtail;
+            }
+          else
+            {
+              ncopy = txbuf->size - txtail;
+            }
+
+          if (ncopy > priv->pktsize - txndx)
+            {
+              ncopy = priv->pktsize - txndx;
+            }
 
-          priv->outbuf[txndx] = txbuf->buffer[txtail];
+          memcpy(&priv->outbuf[txndx], &txbuf->buffer[txtail], ncopy);
 
           /* Increment counters and indices */
 
-          txndx++;
-          if (++txtail >= txbuf->size)
+          txndx += ncopy;
+          txtail += ncopy;
+          if (txtail >= txbuf->size)
             {
-             txtail = 0;
+              txtail = 0;
             }
         }
 

Reply via email to