From fce83488ec144851ba7e18297e955ec0ec170b49 Mon Sep 17 00:00:00 2001 From: zan319 <48862020+zan319@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:04:10 +0800 Subject: [PATCH] =?UTF-8?q?[serial=5Fv2]=20=E4=BF=AE=E5=A4=8D=E9=98=BB?= =?UTF-8?q?=E5=A1=9E=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=B8=AD=E6=96=AD=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=9A=84=E9=80=BB=E8=BE=91=E9=A1=BA=E5=BA=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=B8=8E=E5=A4=9A=E7=BA=BF=E7=A8=8B=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E7=AB=9E=E6=80=81=E6=9D=A1=E4=BB=B6=20(#7997)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/serial/serial_v2.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/components/drivers/serial/serial_v2.c b/components/drivers/serial/serial_v2.c index 2a93656ae3..1d7a556bf2 100644 --- a/components/drivers/serial/serial_v2.c +++ b/components/drivers/serial/serial_v2.c @@ -533,16 +533,19 @@ static rt_ssize_t _serial_fifo_tx_blocking_buf(struct rt_device *dev, (rt_uint8_t *)buffer + offset, size); - offset += tx_fifo->put_size; - size -= tx_fifo->put_size; /* Call the transmit interface for transmission */ serial->ops->transmit(serial, (rt_uint8_t *)buffer + offset, tx_fifo->put_size, RT_SERIAL_TX_BLOCKING); + + offset += tx_fifo->put_size; + size -= tx_fifo->put_size; /* Waiting for the transmission to complete */ rt_completion_wait(&(tx_fifo->tx_cpt), RT_WAITING_FOREVER); } + /* Finally Inactivate the tx->fifo */ + tx_fifo->activated = RT_FALSE; return length; } @@ -598,7 +601,7 @@ static rt_ssize_t _serial_fifo_tx_nonblocking(struct rt_device *dev, return length; } - /* If the activated mode is RT_FALSE, it means that serial device is transmitting, + /* If the activated mode is RT_TRUE, it means that serial device is transmitting, * where only the data in the ringbuffer and there is no need to call the transmit() API. * Note that this part of the code requires disable interrupts * to prevent multi thread reentrant */ @@ -1551,13 +1554,20 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event) * then the transmit completion callback is triggered*/ if (tx_length == 0) { - tx_fifo->activated = RT_FALSE; /* Trigger the transmit completion callback */ if (serial->parent.tx_complete != RT_NULL) serial->parent.tx_complete(&serial->parent, RT_NULL); + /* Maybe some datas left in the buffer still need to be sent in block mode, + * so tx_fifo->activated should be RT_TRUE */ if (serial->parent.open_flag & RT_SERIAL_TX_BLOCKING) + { rt_completion_done(&(tx_fifo->tx_cpt)); + } + else + { + tx_fifo->activated = RT_FALSE; + } break; }