Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
6f75988c
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看板
提交
6f75988c
编写于
8月 19, 2013
作者:
B
bernard
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/RT-Thread/rt-thread
上级
d8695085
90c9c8a2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
38 deletion
+71
-38
components/drivers/include/rtdevice.h
components/drivers/include/rtdevice.h
+7
-0
components/drivers/src/pipe.c
components/drivers/src/pipe.c
+64
-38
未找到文件。
components/drivers/include/rtdevice.h
浏览文件 @
6f75988c
...
...
@@ -172,8 +172,15 @@ rt_inline rt_uint16_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb)
/**
* Pipe Device
*/
rt_err_t
rt_pipe_init
(
struct
rt_pipe_device
*
pipe
,
const
char
*
name
,
rt_uint8_t
*
buf
,
rt_size_t
size
);
rt_err_t
rt_pipe_detach
(
struct
rt_pipe_device
*
pipe
);
#ifdef RT_USING_HEAP
rt_err_t
rt_pipe_create
(
const
char
*
name
,
rt_size_t
size
);
void
rt_pipe_destroy
(
struct
rt_pipe_device
*
pipe
);
#endif
/**
* DataQueue for DeviceDriver
...
...
components/drivers/src/pipe.c
浏览文件 @
6f75988c
...
...
@@ -151,54 +151,79 @@ static rt_err_t rt_pipe_control(rt_device_t dev, rt_uint8_t cmd, void *args)
return
RT_EOK
;
}
/**
* This function will initialize a pipe device and put it under control of
* resource management.
*
* @param pipe the pipe device
* @param name the name of pipe device
* @param buf the buffer of pipe device
* @param size the size of pipe device buffer
*
* @return the operation status, RT_EOK on successful
*/
rt_err_t
rt_pipe_init
(
struct
rt_pipe_device
*
pipe
,
const
char
*
name
,
rt_uint8_t
*
buf
,
rt_size_t
size
)
{
RT_ASSERT
(
pipe
);
RT_ASSERT
(
buf
);
/* initialize suspended list */
rt_list_init
(
&
pipe
->
suspended_read_list
);
rt_list_init
(
&
pipe
->
suspended_write_list
);
/* initialize ring buffer */
rt_ringbuffer_init
(
&
pipe
->
ringbuffer
,
buf
,
size
);
/* create pipe */
pipe
->
parent
.
type
=
RT_Device_Class_Char
;
pipe
->
parent
.
init
=
RT_NULL
;
pipe
->
parent
.
open
=
RT_NULL
;
pipe
->
parent
.
close
=
RT_NULL
;
pipe
->
parent
.
read
=
rt_pipe_read
;
pipe
->
parent
.
write
=
rt_pipe_write
;
pipe
->
parent
.
control
=
rt_pipe_control
;
return
rt_device_register
(
&
(
pipe
->
parent
),
name
,
RT_DEVICE_FLAG_RDWR
);
}
RTM_EXPORT
(
rt_pipe_init
);
/**
* This function will detach a pipe device from resource management
*
* @param pipe the pipe device
*
* @return the operation status, RT_EOK on successful
*/
rt_err_t
rt_pipe_detach
(
struct
rt_pipe_device
*
pipe
)
{
return
rt_device_unregister
(
&
pipe
->
parent
);
}
RTM_EXPORT
(
rt_pipe_detach
);
#ifdef RT_USING_HEAP
rt_err_t
rt_pipe_create
(
const
char
*
name
,
rt_size_t
size
)
{
rt_err_t
result
=
RT_EOK
;
rt_uint8_t
*
rb_memptr
=
RT_NULL
;
struct
rt_pipe_device
*
pipe
=
RT_NULL
;
/* get aligned size */
size
=
RT_ALIGN
(
size
,
RT_ALIGN_SIZE
);
pipe
=
(
struct
rt_pipe_device
*
)
rt_calloc
(
1
,
sizeof
(
struct
rt_pipe_device
));
if
(
pipe
!=
RT_NULL
)
{
/* create ring buffer of pipe */
rb_memptr
=
rt_malloc
(
size
);
if
(
rb_memptr
==
RT_NULL
)
{
result
=
-
RT_ENOMEM
;
goto
__exit
;
}
/* initialize suspended list */
rt_list_init
(
&
pipe
->
suspended_read_list
);
rt_list_init
(
&
pipe
->
suspended_write_list
);
/* initialize ring buffer */
rt_ringbuffer_init
(
&
pipe
->
ringbuffer
,
rb_memptr
,
size
);
/* create device */
pipe
->
parent
.
type
=
RT_Device_Class_Char
;
pipe
->
parent
.
init
=
RT_NULL
;
pipe
->
parent
.
open
=
RT_NULL
;
pipe
->
parent
.
close
=
RT_NULL
;
pipe
->
parent
.
read
=
rt_pipe_read
;
pipe
->
parent
.
write
=
rt_pipe_write
;
pipe
->
parent
.
control
=
rt_pipe_control
;
return
rt_device_register
(
&
(
pipe
->
parent
),
name
,
RT_DEVICE_FLAG_RDWR
);
}
else
{
result
=
-
RT_ENOMEM
;
}
if
(
pipe
==
RT_NULL
)
return
-
RT_ENOMEM
;
__exit:
if
(
pipe
!=
RT_NULL
)
/* create ring buffer of pipe */
rb_memptr
=
rt_malloc
(
size
);
if
(
rb_memptr
==
RT_NULL
)
{
rt_free
(
pipe
);
if
(
rb_memptr
!=
RT_NULL
)
rt_free
(
rb_memptr
);
return
-
RT_ENOMEM
;
}
return
r
esult
;
return
r
t_pipe_init
(
pipe
,
name
,
rb_memptr
,
size
)
;
}
RTM_EXPORT
(
rt_pipe_create
);
...
...
@@ -208,7 +233,7 @@ void rt_pipe_destroy(struct rt_pipe_device *pipe)
return
;
/* un-register pipe device */
rt_
device_unregister
(
&
(
pipe
->
parent
)
);
rt_
pipe_detach
(
pipe
);
/* release memory */
rt_free
(
pipe
->
ringbuffer
.
buffer_ptr
);
...
...
@@ -217,3 +242,4 @@ void rt_pipe_destroy(struct rt_pipe_device *pipe)
return
;
}
RTM_EXPORT
(
rt_pipe_destroy
);
#endif
/* RT_USING_HEAP */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录