Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逆着光、寻觅
rt-thread
提交
afe3b161
R
rt-thread
项目概览
逆着光、寻觅
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
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,发现更多精彩内容 >>
提交
afe3b161
编写于
3月 17, 2017
作者:
armink_ztl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DeviceDrivers] Enhanced serial DMA rx driver reliability.
上级
282c2f22
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
30 deletion
+48
-30
components/drivers/serial/serial.c
components/drivers/serial/serial.c
+48
-30
未找到文件。
components/drivers/serial/serial.c
浏览文件 @
afe3b161
...
@@ -166,14 +166,15 @@ rt_inline int _serial_int_tx(struct rt_serial_device *serial, const rt_uint8_t *
...
@@ -166,14 +166,15 @@ rt_inline int _serial_int_tx(struct rt_serial_device *serial, const rt_uint8_t *
*
*
* @return length
* @return length
*/
*/
static
rt_size_t
rt_dma_calc_recved_len
(
struct
rt_serial_device
*
serial
)
{
static
rt_size_t
rt_dma_calc_recved_len
(
struct
rt_serial_device
*
serial
)
static
rt_size_t
rx_length
;
{
struct
rt_serial_rx_fifo
*
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
rt_size_t
rx_length
;
struct
rt_serial_rx_fifo
*
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
rx_length
=
(
rx_fifo
->
put_index
>=
rx_fifo
->
get_index
)
?
(
rx_fifo
->
put_index
-
rx_fifo
->
get_index
)
:
rx_length
=
(
rx_fifo
->
put_index
>=
rx_fifo
->
get_index
)
?
(
rx_fifo
->
put_index
-
rx_fifo
->
get_index
)
:
(
serial
->
config
.
bufsz
-
(
rx_fifo
->
get_index
-
rx_fifo
->
put_index
));
(
serial
->
config
.
bufsz
-
(
rx_fifo
->
get_index
-
rx_fifo
->
put_index
));
return
rx_length
;
return
rx_length
;
}
}
...
@@ -183,14 +184,16 @@ static rt_size_t rt_dma_calc_recved_len(struct rt_serial_device *serial) {
...
@@ -183,14 +184,16 @@ static rt_size_t rt_dma_calc_recved_len(struct rt_serial_device *serial) {
* @param serial serial device
* @param serial serial device
* @param len get data length for this operate
* @param len get data length for this operate
*/
*/
static
void
rt_dma_recv_update_get_index
(
struct
rt_serial_device
*
serial
,
rt_size_t
len
)
{
static
void
rt_dma_recv_update_get_index
(
struct
rt_serial_device
*
serial
,
rt_size_t
len
)
struct
rt_serial_rx_fifo
*
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
{
struct
rt_serial_rx_fifo
*
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
RT_ASSERT
(
len
<=
rt_dma_calc_recved_len
(
serial
));
RT_ASSERT
(
len
<=
rt_dma_calc_recved_len
(
serial
));
rx_fifo
->
get_index
+=
len
;
rx_fifo
->
get_index
+=
len
;
if
(
rx_fifo
->
get_index
>
serial
->
config
.
bufsz
)
{
if
(
rx_fifo
->
get_index
>
serial
->
config
.
bufsz
)
{
rx_fifo
->
get_index
-=
serial
->
config
.
bufsz
;
rx_fifo
->
get_index
-=
serial
->
config
.
bufsz
;
}
}
}
}
...
@@ -201,37 +204,41 @@ static void rt_dma_recv_update_get_index(struct rt_serial_device *serial, rt_siz
...
@@ -201,37 +204,41 @@ static void rt_dma_recv_update_get_index(struct rt_serial_device *serial, rt_siz
* @param serial serial device
* @param serial serial device
* @param len received length for this transmit
* @param len received length for this transmit
*/
*/
static
void
rt_dma_recv_update_put_index
(
struct
rt_serial_device
*
serial
,
rt_size_t
len
)
{
static
void
rt_dma_recv_update_put_index
(
struct
rt_serial_device
*
serial
,
rt_size_t
len
)
{
struct
rt_serial_rx_fifo
*
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
struct
rt_serial_rx_fifo
*
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
rt_size_t
i
;
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
if
(
rx_fifo
->
get_index
<=
rx_fifo
->
put_index
)
{
if
(
rx_fifo
->
get_index
<=
rx_fifo
->
put_index
)
{
rx_fifo
->
put_index
+=
len
;
rx_fifo
->
put_index
+=
len
;
/* beyond the fifo end */
/* beyond the fifo end */
if
(
rx_fifo
->
put_index
>=
serial
->
config
.
bufsz
)
{
if
(
rx_fifo
->
put_index
>=
serial
->
config
.
bufsz
)
for
(
i
=
0
;
i
<=
len
/
serial
->
config
.
bufsz
;
i
++
)
{
{
rx_fifo
->
put_index
-=
serial
->
config
.
bufsz
;
rx_fifo
->
put_index
%=
serial
->
config
.
bufsz
;
}
/* force overwrite get index */
/* force overwrite get index */
if
(
rx_fifo
->
put_index
>=
rx_fifo
->
get_index
)
{
if
(
rx_fifo
->
put_index
>=
rx_fifo
->
get_index
)
{
rx_fifo
->
get_index
=
rx_fifo
->
put_index
+
1
;
rx_fifo
->
get_index
=
rx_fifo
->
put_index
+
1
;
}
}
}
}
}
else
{
}
else
{
rx_fifo
->
put_index
+=
len
;
rx_fifo
->
put_index
+=
len
;
if
(
rx_fifo
->
put_index
>=
rx_fifo
->
get_index
)
{
if
(
rx_fifo
->
put_index
>=
rx_fifo
->
get_index
)
{
/* beyond the fifo end */
/* beyond the fifo end */
if
(
rx_fifo
->
put_index
>=
serial
->
config
.
bufsz
)
{
if
(
rx_fifo
->
put_index
>=
serial
->
config
.
bufsz
)
for
(
i
=
0
;
i
<=
len
/
serial
->
config
.
bufsz
;
i
++
)
{
{
rx_fifo
->
put_index
-=
serial
->
config
.
bufsz
;
rx_fifo
->
put_index
%=
serial
->
config
.
bufsz
;
}
}
}
/* force overwrite get index */
/* force overwrite get index */
rx_fifo
->
get_index
=
rx_fifo
->
put_index
+
1
;
rx_fifo
->
get_index
=
rx_fifo
->
put_index
+
1
;
}
}
}
}
if
(
rx_fifo
->
get_index
>=
serial
->
config
.
bufsz
)
rx_fifo
->
get_index
=
0
;
}
}
/*
/*
...
@@ -607,17 +614,17 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
...
@@ -607,17 +614,17 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
if
(
args
)
if
(
args
)
{
{
struct
serial_configure
*
pconfig
=
(
struct
serial_configure
*
)
args
;
struct
serial_configure
*
pconfig
=
(
struct
serial_configure
*
)
args
;
if
(
pconfig
->
bufsz
!=
serial
->
config
.
bufsz
&&
serial
->
parent
.
ref_count
)
if
(
pconfig
->
bufsz
!=
serial
->
config
.
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
;
if
(
serial
->
parent
.
ref_count
)
if
(
serial
->
parent
.
ref_count
)
{
{
/* serial device has been opened, to configure it */
/* serial device has been opened, to configure it */
serial
->
ops
->
configure
(
serial
,
(
struct
serial_configure
*
)
args
);
serial
->
ops
->
configure
(
serial
,
(
struct
serial_configure
*
)
args
);
}
}
}
}
...
@@ -754,25 +761,36 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
...
@@ -754,25 +761,36 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
case
RT_SERIAL_EVENT_RX_DMADONE
:
case
RT_SERIAL_EVENT_RX_DMADONE
:
{
{
int
length
;
int
length
;
rt_base_t
level
;
/* get DMA rx length */
/* get DMA rx length */
length
=
(
event
&
(
~
0xff
))
>>
8
;
length
=
(
event
&
(
~
0xff
))
>>
8
;
if
(
serial
->
config
.
bufsz
==
0
)
{
if
(
serial
->
config
.
bufsz
==
0
)
{
struct
rt_serial_rx_dma
*
rx_dma
;
struct
rt_serial_rx_dma
*
rx_dma
;
rx_dma
=
(
struct
rt_serial_rx_dma
*
)
serial
->
serial_rx
;
rx_dma
=
(
struct
rt_serial_rx_dma
*
)
serial
->
serial_rx
;
RT_ASSERT
(
rx_dma
!=
RT_NULL
);
RT_ASSERT
(
rx_dma
!=
RT_NULL
);
RT_ASSERT
(
serial
->
parent
.
rx_indicate
!=
RT_NULL
);
RT_ASSERT
(
serial
->
parent
.
rx_indicate
!=
RT_NULL
);
serial
->
parent
.
rx_indicate
(
&
(
serial
->
parent
),
length
);
serial
->
parent
.
rx_indicate
(
&
(
serial
->
parent
),
length
);
rx_dma
->
activated
=
RT_FALSE
;
rx_dma
->
activated
=
RT_FALSE
;
}
else
{
}
else
{
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
/* update fifo put index */
/* update fifo put index */
rt_dma_recv_update_put_index
(
serial
,
length
);
rt_dma_recv_update_put_index
(
serial
,
length
);
/* calculate received total length */
length
=
rt_dma_calc_recved_len
(
serial
);
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
/* invoke callback */
/* invoke callback */
if
(
serial
->
parent
.
rx_indicate
!=
RT_NULL
)
{
if
(
serial
->
parent
.
rx_indicate
!=
RT_NULL
)
serial
->
parent
.
rx_indicate
(
&
(
serial
->
parent
),
rt_dma_calc_recved_len
(
serial
));
{
serial
->
parent
.
rx_indicate
(
&
(
serial
->
parent
),
length
);
}
}
}
}
break
;
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录