Skip to content

Commit ec9eaad

Browse files
RCSNRbb666
authored andcommitted
[fix] components: serial_v2: preserve RT_DEVICE_FLAG_STREAM when reopening serial device
- The serial_fops_open function closes and reopens the serial device,but the RT_DEVICE_FLAG_STREAM flag was not preserved across the close/open cycle. This change saves the STREAM flag before close and restores it during reopen to ensure consistent behavior. Signed-off-by: Runcheng Lu <runcheng.lu@hpmicro.com>
1 parent ad205d2 commit ec9eaad

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎components/drivers/serial/dev_serial_v2.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,17 @@ static int serial_fops_open(struct dfs_file *fd)
9292
if ((fd->flags & O_ACCMODE) != O_WRONLY)
9393
rt_device_set_rx_indicate(device, serial_fops_rx_ind);
9494

95+
flags |= RT_SERIAL_RX_BLOCKING | RT_SERIAL_TX_BLOCKING;
96+
97+
/* preserve RT_DEVICE_FLAG_STREAM if it was set before close */
98+
if (device->open_flag & RT_DEVICE_FLAG_STREAM)
99+
{
100+
flags |= RT_DEVICE_FLAG_STREAM;
101+
}
102+
95103
rt_device_close(device);
96-
ret = rt_device_open(device, flags | RT_SERIAL_RX_BLOCKING | RT_SERIAL_TX_BLOCKING);
104+
ret = rt_device_open(device, flags);
105+
97106
if (ret == RT_EOK)
98107
{
99108
serial = (struct rt_serial_device *)device;

0 commit comments

Comments
 (0)