From 979891763867433a92691c9eebfb0c6bb5ff2281 Mon Sep 17 00:00:00 2001 From: ChunfengMu Date: Wed, 31 Jan 2018 02:37:34 +0800 Subject: [PATCH] =?UTF-8?q?1:=E8=A7=A3=E5=86=B3=E4=B8=BB=E6=9C=BA=E7=AB=AF?= =?UTF-8?q?=E6=9C=AA=E6=89=93=E5=BC=80=E4=B8=B2=E5=8F=A3=E6=97=B6,?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AB=AF=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?dma=E6=A8=A1=E5=BC=8F=E4=B8=8B=E6=93=8D=E4=BD=9Cvcom=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=95=B0=E6=8D=AE=E6=97=B6,dataqueue=E6=9D=A1?= =?UTF-8?q?=E7=9B=AE=E6=B3=84=E6=BC=8F=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/usb/usbdevice/class/cdc_vcom.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/drivers/usb/usbdevice/class/cdc_vcom.c b/components/drivers/usb/usbdevice/class/cdc_vcom.c index 5188d98102..e1549e49a7 100644 --- a/components/drivers/usb/usbdevice/class/cdc_vcom.c +++ b/components/drivers/usb/usbdevice/class/cdc_vcom.c @@ -260,7 +260,7 @@ static rt_err_t _ep_in_handler(ufunction_t func, rt_size_t size) RT_DEBUG_LOG(RT_DEBUG_USB, ("_ep_in_handler %d\n", size)); data = (struct vcom*)func->user_data; - if ((size != 0) && (size % CDC_MAX_PACKET_SIZE == 0)) + if ((size != 0) && ((size % EP_MAXPACKET(data->ep_in)) == 0)) { /* don't have data right now. Send a zero-length-packet to * terminate the transaction. @@ -707,6 +707,8 @@ static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_s level = rt_hw_interrupt_disable(); size += rt_ringbuffer_put_force(&data->tx_ringbuffer, (const rt_uint8_t *)&buf[size], ptr - size); rt_hw_interrupt_enable(level); + + /* no data was be ignored */ if(size == ptr) { level = rt_hw_interrupt_disable(); @@ -722,6 +724,8 @@ static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_s empty = 1; break; } + + /* ring buffer is full */ if(size == ptr) { empty = 1; @@ -735,6 +739,7 @@ static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_s } } } + if(size < baksize && !empty) { level = rt_hw_interrupt_disable(); @@ -742,12 +747,17 @@ static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_s rt_hw_interrupt_enable(level); } - if(size) { rt_event_send(&data->tx_event, CDC_TX_HAS_DATE); } } + else + { + /* recover dataqueue resources */ + rt_hw_serial_isr(&data->serial,RT_SERIAL_EVENT_TX_DMADONE); + } + return size; } static int _vcom_putc(struct rt_serial_device *serial, char c)