mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-16 01:05:15 +08:00
fix[usb]: support VCOM polling receive with Serial V2
Signed-off-by: Jaeyeong Lee <lee@jaeyeong.cc>
This commit is contained in:
1 parent
8a3ca7bfa3
commit
ceef6e0ccd
1 file changed
+31
-9
@@ -337,6 +337,7 @@ static rt_err_t _ep_in_handler(ufunction_t func, rt_size_t size)
|
||||
static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size)
|
||||
{
|
||||
rt_base_t level;
|
||||
rt_bool_t notify_rx = RT_FALSE;
|
||||
struct vcom *data;
|
||||
#ifdef RT_USING_SERIAL_V2
|
||||
struct rt_serial_rx_fifo *rx_fifo;
|
||||
@@ -355,18 +356,30 @@ static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size)
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
#ifdef RT_USING_SERIAL_V2
|
||||
rx_fifo = (struct rt_serial_rx_fifo *)data->serial.serial_rx;
|
||||
if (rx_fifo != RT_NULL)
|
||||
if (data->serial.config.rx_bufsz == 0)
|
||||
{
|
||||
rt_ringbuffer_put(&rx_fifo->rb, data->ep_out->buffer, size);
|
||||
rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
rx_fifo = (struct rt_serial_rx_fifo *)data->serial.serial_rx;
|
||||
if (rx_fifo != RT_NULL)
|
||||
{
|
||||
rt_ringbuffer_put(&rx_fifo->rb, data->ep_out->buffer, size);
|
||||
notify_rx = RT_TRUE;
|
||||
}
|
||||
}
|
||||
#else
|
||||
rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size);
|
||||
notify_rx = RT_TRUE;
|
||||
#endif
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
/* notify receive data */
|
||||
rt_hw_serial_isr(&data->serial,RT_SERIAL_EVENT_RX_IND);
|
||||
if (notify_rx)
|
||||
{
|
||||
rt_hw_serial_isr(&data->serial, RT_SERIAL_EVENT_RX_IND);
|
||||
}
|
||||
}
|
||||
|
||||
data->ep_out->request.buffer = data->ep_out->buffer;
|
||||
@@ -732,20 +745,29 @@ static int _vcom_getc(struct rt_serial_device *serial)
|
||||
|
||||
func = (struct ufunction*)serial->parent.user_data;
|
||||
data = (struct vcom*)func->user_data;
|
||||
RT_UNUSED(data);
|
||||
|
||||
result = -1;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
#ifdef RT_USING_SERIAL_V2
|
||||
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
|
||||
if(rx_fifo != RT_NULL && rt_ringbuffer_getchar(&rx_fifo->rb, &ch) != 0)
|
||||
if (serial->config.rx_bufsz == 0)
|
||||
{
|
||||
result = ch;
|
||||
if (rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0)
|
||||
{
|
||||
result = ch;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
|
||||
if (rx_fifo != RT_NULL && rt_ringbuffer_getchar(&rx_fifo->rb, &ch) != 0)
|
||||
{
|
||||
result = ch;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if(rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0)
|
||||
if (rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0)
|
||||
{
|
||||
result = ch;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user