Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
198a6a16
R
rt-thread
项目概览
wwsmg1
/
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,发现更多精彩内容 >>
提交
198a6a16
编写于
7月 09, 2013
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #121 from grissiom/device-ref-count
device: add ref_count support
上级
4f0cb887
7bcce9e8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
1 deletion
+29
-1
include/rtdef.h
include/rtdef.h
+1
-0
src/device.c
src/device.c
+28
-1
未找到文件。
include/rtdef.h
浏览文件 @
198a6a16
...
@@ -779,6 +779,7 @@ struct rt_device
...
@@ -779,6 +779,7 @@ struct rt_device
rt_uint16_t
flag
;
/**< device flag */
rt_uint16_t
flag
;
/**< device flag */
rt_uint16_t
open_flag
;
/**< device open flag */
rt_uint16_t
open_flag
;
/**< device open flag */
rt_uint8_t
ref_count
;
/**< reference count */
rt_uint8_t
device_id
;
/**< 0 - 255 */
rt_uint8_t
device_id
;
/**< 0 - 255 */
/* device call back */
/* device call back */
...
...
src/device.c
浏览文件 @
198a6a16
/*
/*
* File : device.c
* File : device.c
* This file is part of RT-Thread RTOS
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 201
2
, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 201
3
, RT-Thread Development Team
*
*
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
* 2012-10-20 Bernard add device check in register function,
* 2012-10-20 Bernard add device check in register function,
* provided by Rob <rdent@iinet.net.au>
* provided by Rob <rdent@iinet.net.au>
* 2012-12-25 Bernard return RT_EOK if the device interface not exist.
* 2012-12-25 Bernard return RT_EOK if the device interface not exist.
* 2013-07-09 Grissiom add ref_count support
*/
*/
#include <rtthread.h>
#include <rtthread.h>
...
@@ -51,6 +52,7 @@ rt_err_t rt_device_register(rt_device_t dev,
...
@@ -51,6 +52,7 @@ rt_err_t rt_device_register(rt_device_t dev,
rt_object_init
(
&
(
dev
->
parent
),
RT_Object_Class_Device
,
name
);
rt_object_init
(
&
(
dev
->
parent
),
RT_Object_Class_Device
,
name
);
dev
->
flag
=
flags
;
dev
->
flag
=
flags
;
dev
->
ref_count
=
0
;
return
RT_EOK
;
return
RT_EOK
;
}
}
...
@@ -237,6 +239,11 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
...
@@ -237,6 +239,11 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
return
-
RT_EBUSY
;
return
-
RT_EBUSY
;
}
}
dev
->
ref_count
++
;
/* don't let bad things happen silently. If you are bitten by this assert,
* please set the ref_count to a bigger type. */
RT_ASSERT
(
dev
->
ref_count
!=
0
);
/* call device open interface */
/* call device open interface */
if
(
dev
->
open
!=
RT_NULL
)
if
(
dev
->
open
!=
RT_NULL
)
{
{
...
@@ -264,6 +271,14 @@ rt_err_t rt_device_close(rt_device_t dev)
...
@@ -264,6 +271,14 @@ rt_err_t rt_device_close(rt_device_t dev)
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
dev
!=
RT_NULL
);
if
(
dev
->
ref_count
==
0
)
return
-
RT_ERROR
;
dev
->
ref_count
--
;
if
(
dev
->
ref_count
!=
0
)
return
RT_EOK
;
/* call device close interface */
/* call device close interface */
if
(
dev
->
close
!=
RT_NULL
)
if
(
dev
->
close
!=
RT_NULL
)
{
{
...
@@ -297,6 +312,12 @@ rt_size_t rt_device_read(rt_device_t dev,
...
@@ -297,6 +312,12 @@ rt_size_t rt_device_read(rt_device_t dev,
{
{
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
dev
!=
RT_NULL
);
if
(
dev
->
ref_count
==
0
)
{
rt_set_errno
(
-
RT_ERROR
);
return
0
;
}
/* call device read interface */
/* call device read interface */
if
(
dev
->
read
!=
RT_NULL
)
if
(
dev
->
read
!=
RT_NULL
)
{
{
...
@@ -329,6 +350,12 @@ rt_size_t rt_device_write(rt_device_t dev,
...
@@ -329,6 +350,12 @@ rt_size_t rt_device_write(rt_device_t dev,
{
{
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
dev
!=
RT_NULL
);
if
(
dev
->
ref_count
==
0
)
{
rt_set_errno
(
-
RT_ERROR
);
return
0
;
}
/* call device write interface */
/* call device write interface */
if
(
dev
->
write
!=
RT_NULL
)
if
(
dev
->
write
!=
RT_NULL
)
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录