提交 748f6afd 编写于 作者: armink_ztl's avatar armink_ztl 提交者: guo

[DeviceDriver][serialv2] Support configure when serial is open.

上级 250de80e
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#define DBG_TAG "UART" #define DBG_TAG "Serial"
#define DBG_LVL DBG_INFO #define DBG_LVL DBG_INFO
#include <rtdbg.h> #include <rtdbg.h>
...@@ -254,7 +254,7 @@ static rt_size_t rt_serial_update_read_index(struct rt_ringbuffer *rb, ...@@ -254,7 +254,7 @@ static rt_size_t rt_serial_update_read_index(struct rt_ringbuffer *rb,
} }
static rt_size_t rt_serial_update_write_index(struct rt_ringbuffer *rb, static rt_size_t rt_serial_update_write_index(struct rt_ringbuffer *rb,
rt_uint16_t write_index) rt_uint16_t write_size)
{ {
rt_uint16_t size; rt_uint16_t size;
RT_ASSERT(rb != RT_NULL); RT_ASSERT(rb != RT_NULL);
...@@ -262,27 +262,28 @@ static rt_size_t rt_serial_update_write_index(struct rt_ringbuffer *rb, ...@@ -262,27 +262,28 @@ static rt_size_t rt_serial_update_write_index(struct rt_ringbuffer *rb,
/* whether has enough space */ /* whether has enough space */
size = rt_ringbuffer_space_len(rb); size = rt_ringbuffer_space_len(rb);
/* no space */ /* no space, drop some data */
if (size == 0) if (size < write_size)
return 0; {
write_size = size;
/* drop some data */ #if !defined(RT_USING_ULOG) || defined(ULOG_USING_ISR_LOG)
if (size < write_index) LOG_W("The serial buffer (len %d) is overflow.", rb->buffer_size);
write_index = size; #endif
}
if (rb->buffer_size - rb->write_index > write_index) if (rb->buffer_size - rb->write_index > write_size)
{ {
/* this should not cause overflow because there is enough space for /* this should not cause overflow because there is enough space for
* length of data in current mirror */ * length of data in current mirror */
rb->write_index += write_index; rb->write_index += write_size;
return write_index; return write_size;
} }
/* we are going into the other side of the mirror */ /* we are going into the other side of the mirror */
rb->write_mirror = ~rb->write_mirror; rb->write_mirror = ~rb->write_mirror;
rb->write_index = write_index - (rb->buffer_size - rb->write_index); rb->write_index = write_size - (rb->buffer_size - rb->write_index);
return write_index; return write_size;
} }
...@@ -463,6 +464,12 @@ static rt_size_t _serial_fifo_tx_blocking_nbuf(struct rt_device *dev, ...@@ -463,6 +464,12 @@ static rt_size_t _serial_fifo_tx_blocking_nbuf(struct rt_device *dev,
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);
if (rt_thread_self() == RT_NULL || (serial->parent.open_flag & RT_DEVICE_FLAG_STREAM))
{
/* using poll tx when the scheduler not startup or in stream mode */
return _serial_poll_tx(dev, pos, buffer, size);
}
/* When serial transmit in tx_blocking mode, /* When serial transmit in tx_blocking mode,
* if the activated mode is RT_TRUE, it will return directly */ * if the activated mode is RT_TRUE, it will return directly */
if (tx_fifo->activated == RT_TRUE) return 0; if (tx_fifo->activated == RT_TRUE) return 0;
...@@ -1121,15 +1128,15 @@ static rt_err_t rt_serial_control(struct rt_device *dev, ...@@ -1121,15 +1128,15 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
if (args != RT_NULL) if (args != RT_NULL)
{ {
struct serial_configure *pconfig = (struct serial_configure *) args; struct serial_configure *pconfig = (struct serial_configure *) args;
if (serial->parent.ref_count) if (((pconfig->rx_bufsz != serial->config.rx_bufsz) || (pconfig->tx_bufsz != serial->config.tx_bufsz))
&& serial->parent.ref_count)
{ {
/*can not change buffer size*/ /*can not change buffer size*/
return -RT_EBUSY; return -RT_EBUSY;
} }
/* set serial configure */ /* set serial configure */
serial->config = *pconfig; serial->config = *pconfig;
serial->ops->configure(serial, serial->ops->configure(serial, (struct serial_configure *) args);
(struct serial_configure *) args);
} }
break; break;
...@@ -1477,13 +1484,18 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event) ...@@ -1477,13 +1484,18 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
struct rt_serial_rx_fifo *rx_fifo; struct rt_serial_rx_fifo *rx_fifo;
rt_size_t rx_length = 0; rt_size_t rx_length = 0;
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
rt_base_t level;
RT_ASSERT(rx_fifo != RT_NULL); RT_ASSERT(rx_fifo != RT_NULL);
/* If the event is RT_SERIAL_EVENT_RX_IND, rx_length is equal to 0 */ /* If the event is RT_SERIAL_EVENT_RX_IND, rx_length is equal to 0 */
rx_length = (event & (~0xff)) >> 8; rx_length = (event & (~0xff)) >> 8;
if (rx_length) if (rx_length)
{ /* RT_SERIAL_EVENT_RX_DMADONE MODE */
level = rt_hw_interrupt_disable();
rt_serial_update_write_index(&(rx_fifo->rb), rx_length); rt_serial_update_write_index(&(rx_fifo->rb), rx_length);
rt_hw_interrupt_enable(level);
}
/* Get the length of the data from the ringbuffer */ /* Get the length of the data from the ringbuffer */
rx_length = rt_ringbuffer_data_len(&rx_fifo->rb); rx_length = rt_ringbuffer_data_len(&rx_fifo->rb);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册