@@ -90,6 +90,8 @@ static int serial_fops_open(struct dfs_file *fd)
9090
9191 if ((fd -> flags & O_ACCMODE ) != O_WRONLY )
9292 rt_device_set_rx_indicate (device , serial_fops_rx_ind );
93+
94+ rt_device_close (device );
9395 ret = rt_device_open (device , flags | RT_SERIAL_RX_BLOCKING | RT_SERIAL_TX_BLOCKING );
9496 if (ret == RT_EOK )
9597 {
@@ -933,7 +935,6 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
933935 RT_DEVICE_CTRL_CONFIG ,
934936 (void * )RT_SERIAL_TX_NON_BLOCKING );
935937
936-
937938__exit :
938939 return control_result ;
939940}
@@ -1186,15 +1187,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
11861187 RT_ASSERT (dev != RT_NULL );
11871188 serial = (struct rt_serial_device * )dev ;
11881189
1189- /* Check that the device has been turned on */
1190- if ((dev -> open_flag ) & (15 << 12 ))
1191- {
1192- LOG_D ("(%s) serial device has already been opened, it will run in its original configuration" , dev -> parent .name );
1193- return RT_EOK ;
1194- }
1195-
1196- LOG_D ("open serial device: 0x%08x with open flag: 0x%04x" ,
1197- dev , oflag );
1190+ LOG_D ("open serial device: 0x%08x with open flag: 0x%04x" , dev , oflag );
11981191
11991192 /* By default, the receive mode of a serial devide is RT_SERIAL_RX_NON_BLOCKING */
12001193 if ((oflag & RT_SERIAL_RX_BLOCKING ) == RT_SERIAL_RX_BLOCKING )
@@ -1458,7 +1451,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
14581451 }
14591452 else
14601453 {
1461- * (rt_uint16_t * )args = RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM ;
1454+ * (rt_uint16_t * )args = RT_DEVICE_FLAG_RDWR | RT_SERIAL_RX_BLOCKING | RT_SERIAL_TX_BLOCKING | RT_DEVICE_FLAG_STREAM ;
14621455 }
14631456 break ;
14641457
0 commit comments