summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorchenjh <[email protected]>2021-06-16 16:55:33 +0800
committerchenjh <[email protected]>2021-06-16 16:55:33 +0800
commit5ac5d92cbb6b00f50c9f91c2f7de038419453398 (patch)
treeabbe54ca25b3ecd7e480e4e2243fc3847adc5a15 /components/drivers
parentfac3c5cda1c5a48c8a8d8c5c753e3a3886ac509e (diff)
[serial] 优化发送非阻塞时,serial_close未执行rt_completion_done的问题。
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/include/drivers/serial_v2.h2
-rw-r--r--components/drivers/serial/SConscript1
-rw-r--r--components/drivers/serial/serial_v2.c14
3 files changed, 12 insertions, 5 deletions
diff --git a/components/drivers/include/drivers/serial_v2.h b/components/drivers/include/drivers/serial_v2.h
index 51306a4bb4..3ba46bdcdd 100644
--- a/components/drivers/include/drivers/serial_v2.h
+++ b/components/drivers/include/drivers/serial_v2.h
@@ -118,8 +118,6 @@ struct rt_serial_rx_fifo
{
struct rt_ringbuffer rb;
- rt_uint16_t rx_index;
-
struct rt_completion rx_cpt;
rt_uint16_t rx_cpt_index;
diff --git a/components/drivers/serial/SConscript b/components/drivers/serial/SConscript
index f3f69991f5..81d791803a 100644
--- a/components/drivers/serial/SConscript
+++ b/components/drivers/serial/SConscript
@@ -2,6 +2,7 @@ from building import *
cwd = GetCurrentDir()
CPPPATH = [cwd + '/../include']
+group = []
if GetDepend(['RT_USING_SERIAL']):
if GetDepend(['RT_USING_SERIAL_V2']):
src = Glob('serial_v2.c')
diff --git a/components/drivers/serial/serial_v2.c b/components/drivers/serial/serial_v2.c
index 1019b73e67..8670a99aa8 100644
--- a/components/drivers/serial/serial_v2.c
+++ b/components/drivers/serial/serial_v2.c
@@ -726,7 +726,6 @@ static rt_err_t rt_serial_rx_enable(struct rt_device *dev,
RT_ASSERT(rx_fifo != RT_NULL);
rt_ringbuffer_init(&(rx_fifo->rb), rx_fifo->buffer, serial->config.rx_bufsz);
- rx_fifo->rx_index = serial->config.rx_bufsz;
serial->serial_rx = rx_fifo;
dev->read = _serial_fifo_rx;
@@ -813,6 +812,9 @@ static rt_err_t rt_serial_tx_disable(struct rt_device *dev,
dev->write = RT_NULL;
if (serial->serial_tx == RT_NULL) return RT_EOK;
+ tx_fifo = (struct rt_serial_tx_fifo *)serial->serial_tx;
+ RT_ASSERT(tx_fifo != RT_NULL);
+
do
{
if (tx_oflag == RT_SERIAL_TX_NON_BLOCKING)
@@ -825,14 +827,13 @@ static rt_err_t rt_serial_tx_disable(struct rt_device *dev,
break;
}
+ rt_completion_done(&(tx_fifo->tx_cpt));
dev->open_flag &= ~ RT_SERIAL_TX_BLOCKING;
serial->ops->control(serial,
RT_DEVICE_CTRL_CLR_INT,
(void *)RT_SERIAL_TX_BLOCKING);
} while (0);
- tx_fifo = (struct rt_serial_tx_fifo *)serial->serial_tx;
- RT_ASSERT(tx_fifo != RT_NULL);
rt_free(tx_fifo);
serial->serial_tx = RT_NULL;
@@ -876,6 +877,13 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
RT_ASSERT(dev != RT_NULL);
serial = (struct rt_serial_device *)dev;
+ /* Check that the device has been turned on */
+ if ((dev->open_flag) & (15 << 12))
+ {
+ LOG_D("(%s) serial device has already been opened, it will run in its original configuration", dev->parent.name);
+ return RT_EOK;
+ }
+
LOG_D("open serial device: 0x%08x with open flag: 0x%04x",
dev, oflag);