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 df8faace52bb93ec017e9f68353f3c0f8bdabf00 Author: chao an <[email protected]> AuthorDate: Mon Oct 26 14:17:39 2026 +0800 drivers/usbdev/pl2303: Copy UART buffers in chunks Replace the byte-at-a-time copies between USB requests and the UART circular buffers with contiguous memcpy() operations. The transmit path copies up to the request limit or the TX ring boundary before advancing the tail. The receive path copies up to the available RX ring space while preserving the existing one-empty-slot full/empty rule. This keeps the same buffer accounting and wraparound behavior while reducing per-byte overhead on the PL2303 USB serial data path. Signed-off-by: chao an <[email protected]> --- drivers/usbdev/pl2303.c | 56 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index dc710201342..5b51cbbae47 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -559,12 +559,30 @@ static uint16_t usbclass_fillrequest(FAR struct pl2303_dev_s *priv, while (xmit->head != xmit->tail && nbytes < reqlen) { - *reqbuf++ = xmit->buffer[xmit->tail]; - nbytes++; + uint16_t ncopy; + + if (xmit->tail < xmit->head) + { + ncopy = xmit->head - xmit->tail; + } + else + { + ncopy = xmit->size - xmit->tail; + } + + if (ncopy > reqlen - nbytes) + { + ncopy = reqlen - nbytes; + } + + memcpy(reqbuf, &xmit->buffer[xmit->tail], ncopy); + reqbuf += ncopy; + nbytes += ncopy; /* Increment the tail pointer */ - if (++(xmit->tail) >= xmit->size) + xmit->tail += ncopy; + if (xmit->tail >= xmit->size) { xmit->tail = 0; } @@ -738,17 +756,41 @@ static inline int usbclass_recvpacket(FAR struct pl2303_dev_s *priv, while (nexthead != recv->tail && nbytes < reqlen) { - /* Copy one byte to the head of the circular RX buffer */ + uint16_t ncopy; + + if (currhead < recv->tail) + { + ncopy = recv->tail - currhead - 1; + } + else + { + ncopy = recv->size - currhead; + if (recv->tail == 0) + { + ncopy--; + } + } - recv->buffer[currhead] = *reqbuf++; + if (ncopy > reqlen - nbytes) + { + ncopy = reqlen - nbytes; + } + + memcpy(&recv->buffer[currhead], reqbuf, ncopy); + reqbuf += ncopy; /* Update counts and indices */ - currhead = nexthead; - nbytes++; + currhead += ncopy; + nbytes += ncopy; /* Increment the head index and check for wrap around */ + if (currhead >= recv->size) + { + currhead = 0; + } + nexthead = currhead + 1; if (nexthead >= recv->size) {
