Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
52931759
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
52931759
编写于
2月 03, 2019
作者:
W
weety
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed data loss issue when USB CDC serial works in dma transmission mode.
上级
48aa2975
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
48 deletion
+48
-48
components/drivers/usb/usbdevice/class/cdc_vcom.c
components/drivers/usb/usbdevice/class/cdc_vcom.c
+48
-48
未找到文件。
components/drivers/usb/usbdevice/class/cdc_vcom.c
浏览文件 @
52931759
...
...
@@ -63,6 +63,7 @@ static struct ucdc_line_coding line_coding;
#define CDC_BULKIN_MAXSIZE (CDC_TX_BUFSIZE / 8)
#define CDC_TX_HAS_DATE 0x01
#define CDC_TX_HAS_SPACE 0x02
struct
vcom
{
...
...
@@ -693,23 +694,48 @@ static int _vcom_getc(struct rt_serial_device *serial)
return
result
;
}
static
rt_size_t
_vcom_tx
(
struct
rt_serial_device
*
serial
,
rt_uint8_t
*
buf
,
rt_size_t
size
,
int
direction
)
static
rt_size_t
_vcom_rb_block_put
(
struct
vcom
*
data
,
const
rt_uint8_t
*
buf
,
rt_size_t
size
)
{
rt_uint32_t
level
;
rt_size_t
put_len
=
0
;
rt_size_t
w_ptr
=
0
;
rt_uint32_t
res
;
rt_size_t
remain_size
=
size
;
while
(
remain_size
)
{
level
=
rt_hw_interrupt_disable
();
put_len
=
rt_ringbuffer_put
(
&
data
->
tx_ringbuffer
,
(
const
rt_uint8_t
*
)
&
buf
[
w_ptr
],
remain_size
);
rt_hw_interrupt_enable
(
level
);
w_ptr
+=
put_len
;
remain_size
-=
put_len
;
if
(
put_len
==
0
)
{
rt_event_recv
(
&
data
->
tx_event
,
CDC_TX_HAS_SPACE
,
RT_EVENT_FLAG_OR
|
RT_EVENT_FLAG_CLEAR
,
VCOM_TX_TIMEOUT
,
&
res
);
}
else
{
rt_event_send
(
&
data
->
tx_event
,
CDC_TX_HAS_DATE
);
}
}
return
size
;
}
static
rt_size_t
_vcom_tx
(
struct
rt_serial_device
*
serial
,
rt_uint8_t
*
buf
,
rt_size_t
size
,
int
direction
)
{
struct
ufunction
*
func
;
struct
vcom
*
data
;
rt_uint32_t
baksize
;
rt_uint32_t
send_size
=
0
;
rt_size_t
ptr
=
0
;
int
empty
=
0
;
rt_uint8_t
crlf
[
2
]
=
{
'\r'
,
'\n'
,};
func
=
(
struct
ufunction
*
)
serial
->
parent
.
user_data
;
data
=
(
struct
vcom
*
)
func
->
user_data
;
size
=
(
size
>=
CDC_BULKIN_MAXSIZE
)
?
CDC_BULKIN_MAXSIZE
:
size
;
baksize
=
size
;
RT_ASSERT
(
serial
!=
RT_NULL
);
RT_ASSERT
(
buf
!=
RT_NULL
);
...
...
@@ -717,64 +743,37 @@ static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_s
if
(
data
->
connected
)
{
size
=
0
;
if
((
serial
->
parent
.
open_flag
&
RT_DEVICE_FLAG_STREAM
))
{
empty
=
0
;
while
(
ptr
<
baksize
)
while
(
send_size
<
size
)
{
while
(
ptr
<
bak
size
&&
buf
[
ptr
]
!=
'\n'
)
while
(
ptr
<
size
&&
buf
[
ptr
]
!=
'\n'
)
{
ptr
++
;
}
if
(
ptr
<
bak
size
)
if
(
ptr
<
size
)
{
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
();
if
(
rt_ringbuffer_space_len
(
&
data
->
tx_ringbuffer
)
>=
2
)
{
rt_ringbuffer_put_force
(
&
data
->
tx_ringbuffer
,
crlf
,
2
);
size
++
;
}
rt_hw_interrupt_enable
(
level
);
}
else
{
empty
=
1
;
break
;
}
/* ring buffer is full */
if
(
size
==
ptr
)
{
empty
=
1
;
break
;
}
send_size
+=
_vcom_rb_block_put
(
data
,
(
const
rt_uint8_t
*
)
&
buf
[
send_size
],
ptr
-
send_size
);
_vcom_rb_block_put
(
data
,
crlf
,
2
);
send_size
++
;
ptr
++
;
}
else
if
(
ptr
==
size
)
{
send_size
+=
_vcom_rb_block_put
(
data
,
(
const
rt_uint8_t
*
)
&
buf
[
send_size
],
ptr
-
send_size
);
}
else
{
break
;
}
}
}
if
(
size
<
baksize
&&
!
empty
)
else
{
level
=
rt_hw_interrupt_disable
();
size
+=
rt_ringbuffer_put_force
(
&
data
->
tx_ringbuffer
,
(
rt_uint8_t
*
)
&
buf
[
size
],
baksize
-
size
);
rt_hw_interrupt_enable
(
level
);
}
if
(
size
)
{
rt_event_send
(
&
data
->
tx_event
,
CDC_TX_HAS_DATE
);
while
(
send_size
<
size
)
{
send_size
+=
_vcom_rb_block_put
(
data
,
(
rt_uint8_t
*
)
&
buf
[
send_size
],
size
-
send_size
);
}
}
}
else
...
...
@@ -902,6 +901,7 @@ static void vcom_tx_thread_entry(void* parameter)
#else
rt_hw_serial_isr
(
&
data
->
serial
,
RT_SERIAL_EVENT_TX_DMADONE
);
#endif
rt_event_send
(
&
data
->
tx_event
,
CDC_TX_HAS_SPACE
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录