Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
卖小麦←_←
rt-thread
提交
748f6afd
R
rt-thread
项目概览
卖小麦←_←
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
748f6afd
编写于
10月 07, 2022
作者:
armink_ztl
提交者:
guo
10月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DeviceDriver][serialv2] Support configure when serial is open.
上级
250de80e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
18 deletion
+30
-18
components/drivers/serial/serial_v2.c
components/drivers/serial/serial_v2.c
+30
-18
未找到文件。
components/drivers/serial/serial_v2.c
浏览文件 @
748f6afd
...
...
@@ -12,7 +12,7 @@
#include <rtthread.h>
#include <rtdevice.h>
#define DBG_TAG "
UART
"
#define DBG_TAG "
Serial
"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
...
...
@@ -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
,
rt_uint16_t
write_
index
)
rt_uint16_t
write_
size
)
{
rt_uint16_t
size
;
RT_ASSERT
(
rb
!=
RT_NULL
);
...
...
@@ -262,27 +262,28 @@ static rt_size_t rt_serial_update_write_index(struct rt_ringbuffer *rb,
/* whether has enough space */
size
=
rt_ringbuffer_space_len
(
rb
);
/* no space */
if
(
size
==
0
)
return
0
;
/* drop some data */
if
(
size
<
write_index
)
write_index
=
size
;
/* no space, drop some data */
if
(
size
<
write_size
)
{
write_size
=
size
;
#if !defined(RT_USING_ULOG) || defined(ULOG_USING_ISR_LOG)
LOG_W
(
"The serial buffer (len %d) is overflow."
,
rb
->
buffer_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
* length of data in current mirror */
rb
->
write_index
+=
write_
index
;
return
write_
index
;
rb
->
write_index
+=
write_
size
;
return
write_
size
;
}
/* we are going into the other side of the 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,
tx_fifo
=
(
struct
rt_serial_tx_fifo
*
)
serial
->
serial_tx
;
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,
* if the activated mode is RT_TRUE, it will return directly */
if
(
tx_fifo
->
activated
==
RT_TRUE
)
return
0
;
...
...
@@ -1121,15 +1128,15 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
if
(
args
!=
RT_NULL
)
{
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*/
return
-
RT_EBUSY
;
}
/* set serial configure */
/* set serial configure */
serial
->
config
=
*
pconfig
;
serial
->
ops
->
configure
(
serial
,
(
struct
serial_configure
*
)
args
);
serial
->
ops
->
configure
(
serial
,
(
struct
serial_configure
*
)
args
);
}
break
;
...
...
@@ -1477,13 +1484,18 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
struct
rt_serial_rx_fifo
*
rx_fifo
;
rt_size_t
rx_length
=
0
;
rx_fifo
=
(
struct
rt_serial_rx_fifo
*
)
serial
->
serial_rx
;
rt_base_t
level
;
RT_ASSERT
(
rx_fifo
!=
RT_NULL
);
/* If the event is RT_SERIAL_EVENT_RX_IND, rx_length is equal to 0 */
rx_length
=
(
event
&
(
~
0xff
))
>>
8
;
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_hw_interrupt_enable
(
level
);
}
/* Get the length of the data from the ringbuffer */
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录