update serial drv

This commit is contained in:
Aubr.Cool 2021-04-27 13:46:11 +08:00
parent 01050e5e54
commit e72008b614
1 changed files with 15 additions and 11 deletions

View File

@ -746,19 +746,24 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
{ {
struct rt_serial_rx_fifo* rx_fifo; struct rt_serial_rx_fifo* rx_fifo;
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void*)RT_DEVICE_FLAG_INT_RX);
dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX;
rx_fifo = (struct rt_serial_rx_fifo*)serial->serial_rx; rx_fifo = (struct rt_serial_rx_fifo*)serial->serial_rx;
RT_ASSERT(rx_fifo != RT_NULL); RT_ASSERT(rx_fifo != RT_NULL);
rt_free(rx_fifo); rt_free(rx_fifo);
serial->serial_rx = RT_NULL; serial->serial_rx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX;
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void*)RT_DEVICE_FLAG_INT_RX);
} }
#ifdef RT_SERIAL_USING_DMA #ifdef RT_SERIAL_USING_DMA
else if (dev->open_flag & RT_DEVICE_FLAG_DMA_RX) else if (dev->open_flag & RT_DEVICE_FLAG_DMA_RX)
{ {
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *) RT_DEVICE_FLAG_DMA_RX);
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_RX;
if (serial->config.bufsz == 0) if (serial->config.bufsz == 0)
{ {
struct rt_serial_rx_dma* rx_dma; struct rt_serial_rx_dma* rx_dma;
@ -778,10 +783,7 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
rt_free(rx_fifo); rt_free(rx_fifo);
} }
serial->serial_rx = RT_NULL; serial->serial_rx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_RX;
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *) RT_DEVICE_FLAG_DMA_RX);
} }
#endif /* RT_SERIAL_USING_DMA */ #endif /* RT_SERIAL_USING_DMA */
@ -789,21 +791,26 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
{ {
struct rt_serial_tx_fifo* tx_fifo; struct rt_serial_tx_fifo* tx_fifo;
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void*)RT_DEVICE_FLAG_INT_TX);
dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX;
tx_fifo = (struct rt_serial_tx_fifo*)serial->serial_tx; tx_fifo = (struct rt_serial_tx_fifo*)serial->serial_tx;
RT_ASSERT(tx_fifo != RT_NULL); RT_ASSERT(tx_fifo != RT_NULL);
rt_free(tx_fifo); rt_free(tx_fifo);
serial->serial_tx = RT_NULL; serial->serial_tx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX;
/* configure low level device */ /* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void*)RT_DEVICE_FLAG_INT_TX);
} }
#ifdef RT_SERIAL_USING_DMA #ifdef RT_SERIAL_USING_DMA
else if (dev->open_flag & RT_DEVICE_FLAG_DMA_TX) else if (dev->open_flag & RT_DEVICE_FLAG_DMA_TX)
{ {
struct rt_serial_tx_dma* tx_dma; struct rt_serial_tx_dma* tx_dma;
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *) RT_DEVICE_FLAG_DMA_TX);
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_TX;
tx_dma = (struct rt_serial_tx_dma*)serial->serial_tx; tx_dma = (struct rt_serial_tx_dma*)serial->serial_tx;
RT_ASSERT(tx_dma != RT_NULL); RT_ASSERT(tx_dma != RT_NULL);
@ -811,10 +818,7 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
rt_free(tx_dma); rt_free(tx_dma);
serial->serial_tx = RT_NULL; serial->serial_tx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_TX;
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *) RT_DEVICE_FLAG_DMA_TX);
} }
#endif /* RT_SERIAL_USING_DMA */ #endif /* RT_SERIAL_USING_DMA */