From f913bfa8b93ce5cd8ae06b14ad9ae180574ed5be Mon Sep 17 00:00:00 2001 From: "shenyang.wang" Date: Thu, 15 Aug 2024 15:42:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B2=E5=8F=A3=E4=BD=BF=E7=94=A8DMA?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E6=95=B0=E6=8D=AE=E6=97=B6=EF=BC=8C=E5=A6=82?= =?UTF-8?q?=E6=9E=9Cdma=E6=95=B0=E6=8D=AE=E6=8E=A5=E6=94=B6=E5=8F=91?= =?UTF-8?q?=E7=94=9F=E8=A6=86=E7=9B=96=E5=86=99=E5=85=A5=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=EF=BC=8Crt=5Fserial=5Fupdate=5Fwrite=5Findex=E7=9A=84?= =?UTF-8?q?=E4=B8=A2=E5=BC=83=E7=AD=96=E7=95=A5=E4=B8=8D=E5=90=88=E9=80=82?= =?UTF-8?q?=EF=BC=8C=E5=9B=A0=E4=B8=BA=E6=95=B0=E6=8D=AE=E5=B9=B6=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=A2=AB=E5=AE=9E=E9=99=85=E7=9A=84=E4=B8=A2=E5=BC=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/serial/serial_v2.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/components/drivers/serial/serial_v2.c b/components/drivers/serial/serial_v2.c index d7576dbed8..3a41f11caf 100644 --- a/components/drivers/serial/serial_v2.c +++ b/components/drivers/serial/serial_v2.c @@ -263,23 +263,18 @@ static rt_ssize_t rt_serial_update_write_index(struct rt_ringbuffer *rb, rt_uint16_t size; RT_ASSERT(rb != RT_NULL); - /* whether has enough space */ + /* get available space */ size = rt_ringbuffer_space_len(rb); - /* no space, drop some data */ - if (size < write_size) - { - write_size = size; -#if !defined(RT_USING_ULOG) || defined(ULOG_USING_ISR_LOG) - LOG_W("The serial buffer (len %d) is overflow.", rb->buffer_size); -#endif - } - if (rb->buffer_size - rb->write_index > write_size) { /* this should not cause overflow because there is enough space for * length of data in current mirror */ rb->write_index += write_size; + if (write_size > size) + { + rb->read_index = rb->write_index; + } return write_size; } @@ -287,6 +282,14 @@ static rt_ssize_t rt_serial_update_write_index(struct rt_ringbuffer *rb, rb->write_mirror = ~rb->write_mirror; rb->write_index = write_size - (rb->buffer_size - rb->write_index); + if (write_size > size) + { + /* available space is insufficient,it will overwrite the existing data + * in the ring buffer.*/ + if (rb->write_index <= rb->read_index) + rb->read_mirror = ~rb->read_mirror; + rb->read_index = rb->write_index; + } return write_size; } -- Gitee