Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
天中雨水
rt-thread
提交
22139e66
R
rt-thread
项目概览
天中雨水
/
rt-thread
该项目与 Fork 源项目分叉
Fork自
RT-Thread / rt-thread
通知
2
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,发现更多精彩内容 >>
提交
22139e66
编写于
7月 09, 2021
作者:
C
chenjh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[serial_v2] Serial_v2 support device ops feature
上级
f8cf8341
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
0 deletion
+80
-0
components/drivers/serial/serial_v2.c
components/drivers/serial/serial_v2.c
+80
-0
未找到文件。
components/drivers/serial/serial_v2.c
浏览文件 @
22139e66
...
...
@@ -19,6 +19,7 @@
#ifdef RT_USING_POSIX
#include <dfs_posix.h>
#include <dfs_poll.h>
#include <sys/ioctl.h>
#ifdef getc
#undef getc
...
...
@@ -609,7 +610,10 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
return
-
RT_EINVAL
;
}
#ifndef RT_USING_DEVICE_OPS
dev
->
write
=
_serial_poll_tx
;
#endif
dev
->
open_flag
|=
RT_SERIAL_TX_BLOCKING
;
return
RT_EOK
;
}
...
...
@@ -637,7 +641,10 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
tx_fifo
->
buffer
,
serial
->
config
.
tx_bufsz
);
serial
->
serial_tx
=
tx_fifo
;
#ifndef RT_USING_DEVICE_OPS
dev
->
write
=
_serial_fifo_tx_blocking_buf
;
#endif
}
else
{
...
...
@@ -648,7 +655,11 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
RT_ASSERT
(
tx_fifo
!=
RT_NULL
);
serial
->
serial_tx
=
tx_fifo
;
#ifndef RT_USING_DEVICE_OPS
dev
->
write
=
_serial_fifo_tx_blocking_nbuf
;
#endif
/* Call the control() API to configure the serial device by RT_SERIAL_TX_BLOCKING*/
serial
->
ops
->
control
(
serial
,
RT_DEVICE_CTRL_CONFIG
,
...
...
@@ -676,7 +687,10 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
serial
->
config
.
tx_bufsz
);
serial
->
serial_tx
=
tx_fifo
;
#ifndef RT_USING_DEVICE_OPS
dev
->
write
=
_serial_fifo_tx_nonblocking
;
#endif
dev
->
open_flag
|=
RT_SERIAL_TX_NON_BLOCKING
;
/* Call the control() API to configure the serial device by RT_SERIAL_TX_NON_BLOCKING*/
serial
->
ops
->
control
(
serial
,
...
...
@@ -712,7 +726,10 @@ static rt_err_t rt_serial_rx_enable(struct rt_device *dev,
return
-
RT_EINVAL
;
}
#ifndef RT_USING_DEVICE_OPS
dev
->
read
=
_serial_poll_rx
;
#endif
dev
->
open_flag
|=
RT_SERIAL_RX_BLOCKING
;
return
RT_EOK
;
}
...
...
@@ -727,7 +744,10 @@ static rt_err_t rt_serial_rx_enable(struct rt_device *dev,
rt_ringbuffer_init
(
&
(
rx_fifo
->
rb
),
rx_fifo
->
buffer
,
serial
->
config
.
rx_bufsz
);
serial
->
serial_rx
=
rx_fifo
;
#ifndef RT_USING_DEVICE_OPS
dev
->
read
=
_serial_fifo_rx
;
#endif
if
(
rx_oflag
==
RT_SERIAL_RX_NON_BLOCKING
)
{
...
...
@@ -766,7 +786,10 @@ static rt_err_t rt_serial_rx_disable(struct rt_device *dev,
RT_ASSERT
(
dev
!=
RT_NULL
);
serial
=
(
struct
rt_serial_device
*
)
dev
;
#ifndef RT_USING_DEVICE_OPS
dev
->
read
=
RT_NULL
;
#endif
if
(
serial
->
serial_rx
==
RT_NULL
)
return
RT_EOK
;
do
...
...
@@ -809,7 +832,10 @@ static rt_err_t rt_serial_tx_disable(struct rt_device *dev,
RT_ASSERT
(
dev
!=
RT_NULL
);
serial
=
(
struct
rt_serial_device
*
)
dev
;
#ifndef RT_USING_DEVICE_OPS
dev
->
write
=
RT_NULL
;
#endif
if
(
serial
->
serial_tx
==
RT_NULL
)
return
RT_EOK
;
tx_fifo
=
(
struct
rt_serial_tx_fifo
*
)
serial
->
serial_tx
;
...
...
@@ -1006,6 +1032,60 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
}
#ifdef RT_USING_DEVICE_OPS
static
rt_size_t
rt_serial_read
(
struct
rt_device
*
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
{
struct
rt_serial_device
*
serial
;
RT_ASSERT
(
dev
!=
RT_NULL
);
if
(
size
==
0
)
return
0
;
serial
=
(
struct
rt_serial_device
*
)
dev
;
if
(
serial
->
config
.
rx_bufsz
)
{
return
_serial_fifo_rx
(
dev
,
pos
,
buffer
,
size
);
}
return
_serial_poll_rx
(
dev
,
pos
,
buffer
,
size
);
}
static
rt_size_t
rt_serial_write
(
struct
rt_device
*
dev
,
rt_off_t
pos
,
const
void
*
buffer
,
rt_size_t
size
)
{
struct
rt_serial_device
*
serial
;
struct
rt_serial_tx_fifo
*
tx_fifo
;
RT_ASSERT
(
dev
!=
RT_NULL
);
if
(
size
==
0
)
return
0
;
serial
=
(
struct
rt_serial_device
*
)
dev
;
RT_ASSERT
((
serial
!=
RT_NULL
)
&&
(
buffer
!=
RT_NULL
));
tx_fifo
=
(
struct
rt_serial_tx_fifo
*
)
serial
->
serial_tx
;
if
(
serial
->
config
.
tx_bufsz
==
0
)
{
return
_serial_poll_tx
(
dev
,
pos
,
buffer
,
size
);
}
if
(
dev
->
open_flag
|
RT_SERIAL_TX_BLOCKING
)
{
if
((
tx_fifo
->
rb
.
buffer_ptr
)
==
RT_NULL
)
{
return
_serial_fifo_tx_blocking_nbuf
(
dev
,
pos
,
buffer
,
size
);
}
return
_serial_fifo_tx_blocking_buf
(
dev
,
pos
,
buffer
,
size
);
}
return
_serial_fifo_tx_nonblocking
(
dev
,
pos
,
buffer
,
size
);
}
const
static
struct
rt_device_ops
serial_ops
=
{
rt_serial_init
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录