From 5ac5d92cbb6b00f50c9f91c2f7de038419453398 Mon Sep 17 00:00:00 2001 From: chenjh Date: Wed, 16 Jun 2021 16:55:33 +0800 Subject: [serial] 优化发送非阻塞时,serial_close未执行rt_completion_done的问题。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/drivers/serial_v2.h | 2 -- components/drivers/serial/SConscript | 1 + components/drivers/serial/serial_v2.c | 14 +++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'components') 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); -- cgit v1.3.1