Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lfmiao0
rt-thread
提交
e1587de6
R
rt-thread
项目概览
lfmiao0
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e1587de6
编写于
8月 14, 2019
作者:
T
tangweikang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[components][drivers] update capture driven framework
上级
47350505
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
47 deletion
+57
-47
components/drivers/Kconfig
components/drivers/Kconfig
+1
-1
components/drivers/include/drivers/rt_capture.h
components/drivers/include/drivers/rt_capture.h
+9
-10
components/drivers/misc/rt_capture.c
components/drivers/misc/rt_capture.c
+47
-36
未找到文件。
components/drivers/Kconfig
浏览文件 @
e1587de6
...
@@ -444,7 +444,7 @@ config RT_USING_CAPTURE
...
@@ -444,7 +444,7 @@ config RT_USING_CAPTURE
if RT_USING_CAPTURE
if RT_USING_CAPTURE
config RT_CAPTURE_RB_SIZE
config RT_CAPTURE_RB_SIZE
int "Set capture rinbuffer size"
int "Set capture rin
g
buffer size"
default 100
default 100
endif
endif
...
...
components/drivers/include/drivers/rt_capture.h
浏览文件 @
e1587de6
...
@@ -22,19 +22,19 @@ extern "C" {
...
@@ -22,19 +22,19 @@ extern "C" {
#define CAPTURE_CMD_CLEAR_BUF (128 + 0)
/* clear capture buf */
#define CAPTURE_CMD_CLEAR_BUF (128 + 0)
/* clear capture buf */
#define CAPTURE_CMD_SET_WATERMARK (128 + 1)
/* Set the callback threshold */
#define CAPTURE_CMD_SET_WATERMARK (128 + 1)
/* Set the callback threshold */
struct
capture_data
_struct
struct
capture_data
{
{
rt_bool_t
is_high
;
rt_uint32_t
pulsewidth_us
;
rt_uint32_t
pulsewidth_us
;
rt_bool_t
is_high
;
};
};
struct
rt_capture_device
struct
rt_capture_device
{
{
struct
rt_device
parent
;
struct
rt_device
parent
;
const
struct
rt_capture_ops
*
ops
;
const
struct
rt_capture_ops
*
ops
;
struct
rt_ringbuffer
*
ringbuff
;
struct
rt_ringbuffer
*
ringbuff
;
rt_size_t
watermark
;
rt_size_t
watermark
;
};
};
/**
/**
...
@@ -50,10 +50,9 @@ struct rt_capture_ops
...
@@ -50,10 +50,9 @@ struct rt_capture_ops
void
rt_hw_capture_isr
(
struct
rt_capture_device
*
capture
,
rt_bool_t
level
);
void
rt_hw_capture_isr
(
struct
rt_capture_device
*
capture
,
rt_bool_t
level
);
rt_err_t
rt_hw_capture_register
(
struct
rt_capture_device
*
capture
,
rt_err_t
rt_device_capture_register
(
struct
rt_capture_device
*
capture
,
const
char
*
name
,
const
char
*
name
,
rt_uint32_t
flag
,
void
*
data
);
void
*
data
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
components/drivers/misc/rt_capture.c
浏览文件 @
e1587de6
...
@@ -10,44 +10,45 @@
...
@@ -10,44 +10,45 @@
#include <rtthread.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <rtdevice.h>
#include <rtdbg.h>
static
rt_err_t
rt_capture_init
(
struct
rt_device
*
dev
)
static
rt_err_t
rt_capture_init
(
struct
rt_device
*
dev
)
{
{
rt_err_t
ret
;
struct
rt_capture_device
*
capture
;
struct
rt_capture_device
*
capture
;
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
dev
!=
RT_NULL
);
ret
=
RT_EOK
;
capture
=
(
struct
rt_capture_device
*
)
dev
;
capture
=
(
struct
rt_capture_device
*
)
dev
;
capture
->
watermark
=
RT_CAPTURE_RB_SIZE
/
2
;
capture
->
watermark
=
RT_CAPTURE_RB_SIZE
/
2
;
if
(
capture
->
ops
->
init
)
if
(
capture
->
ops
->
init
)
{
return
capture
->
ops
->
init
(
capture
);
}
else
{
{
ret
urn
-
RT_ENOSYS
;
ret
=
capture
->
ops
->
init
(
capture
)
;
}
}
return
ret
;
}
}
static
rt_err_t
rt_capture_open
(
struct
rt_device
*
dev
,
rt_uint16_t
oflag
)
static
rt_err_t
rt_capture_open
(
struct
rt_device
*
dev
,
rt_uint16_t
oflag
)
{
{
rt_err_t
ret
;
struct
rt_capture_device
*
capture
;
struct
rt_capture_device
*
capture
;
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
dev
!=
RT_NULL
);
ret
=
RT_EOK
;
capture
=
(
struct
rt_capture_device
*
)
dev
;
capture
=
(
struct
rt_capture_device
*
)
dev
;
if
(
capture
->
ringbuff
==
RT_NULL
)
if
(
capture
->
ringbuff
==
RT_NULL
)
{
{
capture
->
ringbuff
=
rt_ringbuffer_create
(
sizeof
(
struct
capture_data
_struct
)
*
RT_CAPTURE_RB_SIZE
);
capture
->
ringbuff
=
rt_ringbuffer_create
(
sizeof
(
struct
capture_data
)
*
RT_CAPTURE_RB_SIZE
);
}
}
if
(
capture
->
ops
->
open
)
if
(
capture
->
ops
->
open
)
{
{
return
capture
->
ops
->
open
(
capture
);
ret
=
capture
->
ops
->
open
(
capture
);
}
else
{
return
-
RT_ENOSYS
;
}
}
return
ret
;
}
}
static
rt_err_t
rt_capture_close
(
struct
rt_device
*
dev
)
static
rt_err_t
rt_capture_close
(
struct
rt_device
*
dev
)
...
@@ -58,32 +59,30 @@ static rt_err_t rt_capture_close(struct rt_device *dev)
...
@@ -58,32 +59,30 @@ static rt_err_t rt_capture_close(struct rt_device *dev)
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
dev
!=
RT_NULL
);
ret
=
-
RT_ERROR
;
ret
=
-
RT_ERROR
;
capture
=
(
struct
rt_capture_device
*
)
dev
;
capture
=
(
struct
rt_capture_device
*
)
dev
;
if
(
capture
->
ops
->
close
)
if
(
capture
->
ops
->
close
)
{
{
ret
=
capture
->
ops
->
close
(
capture
);
ret
=
capture
->
ops
->
close
(
capture
);
}
}
else
if
(
ret
!=
RT_EOK
)
{
{
return
-
RT_ENOSYS
;
return
ret
;
}
}
if
(
ret
==
RT_EOK
)
if
(
capture
->
ringbuff
)
{
{
if
(
capture
->
ringbuff
)
rt_ringbuffer_destroy
(
capture
->
ringbuff
);
{
capture
->
ringbuff
=
RT_NULL
;
rt_ringbuffer_destroy
(
capture
->
ringbuff
);
capture
->
ringbuff
=
RT_NULL
;
}
}
}
return
ret
;
return
ret
;
}
}
static
rt_size_t
rt_capture_read
(
struct
rt_device
*
dev
,
static
rt_size_t
rt_capture_read
(
struct
rt_device
*
dev
,
rt_off_t
pos
,
rt_off_t
pos
,
void
*
buffer
,
void
*
buffer
,
rt_size_t
size
)
rt_size_t
size
)
{
{
rt_size_t
receive_size
;
rt_size_t
receive_size
;
struct
rt_capture_device
*
capture
;
struct
rt_capture_device
*
capture
;
...
@@ -91,9 +90,9 @@ static rt_size_t rt_capture_read(struct rt_device *dev,
...
@@ -91,9 +90,9 @@ static rt_size_t rt_capture_read(struct rt_device *dev,
RT_ASSERT
(
dev
!=
RT_NULL
);
RT_ASSERT
(
dev
!=
RT_NULL
);
capture
=
(
struct
rt_capture_device
*
)
dev
;
capture
=
(
struct
rt_capture_device
*
)
dev
;
receive_size
=
rt_ringbuffer_get
(
capture
->
ringbuff
,
(
rt_uint8_t
*
)
buffer
,
sizeof
(
struct
capture_data_struct
)
*
size
);
receive_size
=
rt_ringbuffer_get
(
capture
->
ringbuff
,
(
rt_uint8_t
*
)
buffer
,
sizeof
(
struct
capture_data
)
*
size
);
return
receive_size
/
sizeof
(
struct
capture_data_struct
);
return
receive_size
/
sizeof
(
struct
capture_data
);
}
}
static
rt_err_t
rt_capture_control
(
struct
rt_device
*
dev
,
int
cmd
,
void
*
args
)
static
rt_err_t
rt_capture_control
(
struct
rt_device
*
dev
,
int
cmd
,
void
*
args
)
...
@@ -108,7 +107,10 @@ static rt_err_t rt_capture_control(struct rt_device *dev, int cmd, void *args)
...
@@ -108,7 +107,10 @@ static rt_err_t rt_capture_control(struct rt_device *dev, int cmd, void *args)
switch
(
cmd
)
switch
(
cmd
)
{
{
case
CAPTURE_CMD_CLEAR_BUF
:
case
CAPTURE_CMD_CLEAR_BUF
:
rt_ringbuffer_reset
(
capture
->
ringbuff
);
if
(
capture
->
ringbuff
)
{
rt_ringbuffer_reset
(
capture
->
ringbuff
);
}
break
;
break
;
case
CAPTURE_CMD_SET_WATERMARK
:
case
CAPTURE_CMD_SET_WATERMARK
:
capture
->
watermark
=
*
(
rt_size_t
*
)
args
;
capture
->
watermark
=
*
(
rt_size_t
*
)
args
;
...
@@ -139,12 +141,14 @@ rt_err_t rt_device_capture_register(struct rt_capture_device *capture, const cha
...
@@ -139,12 +141,14 @@ rt_err_t rt_device_capture_register(struct rt_capture_device *capture, const cha
RT_ASSERT
(
capture
!=
RT_NULL
);
RT_ASSERT
(
capture
!=
RT_NULL
);
RT_ASSERT
(
capture
->
ops
!=
RT_NULL
);
RT_ASSERT
(
capture
->
ops
!=
RT_NULL
);
RT_ASSERT
(
capture
->
ops
->
get_pulsewidth
!=
RT_NULL
);
device
=
&
(
capture
->
parent
);
device
=
&
(
capture
->
parent
);
device
->
type
=
RT_Device_Class_Miscellaneous
;
device
->
type
=
RT_Device_Class_Miscellaneous
;
device
->
rx_indicate
=
RT_NULL
;
device
->
rx_indicate
=
RT_NULL
;
device
->
tx_complete
=
RT_NULL
;
device
->
tx_complete
=
RT_NULL
;
capture
->
ringbuff
=
RT_NULL
;
#ifdef RT_USING_DEVICE_OPS
#ifdef RT_USING_DEVICE_OPS
device
->
ops
=
&
capture_ops
;
device
->
ops
=
&
capture_ops
;
...
@@ -161,21 +165,28 @@ rt_err_t rt_device_capture_register(struct rt_capture_device *capture, const cha
...
@@ -161,21 +165,28 @@ rt_err_t rt_device_capture_register(struct rt_capture_device *capture, const cha
return
rt_device_register
(
device
,
name
,
RT_DEVICE_FLAG_RDONLY
|
RT_DEVICE_FLAG_STANDALONE
);
return
rt_device_register
(
device
,
name
,
RT_DEVICE_FLAG_RDONLY
|
RT_DEVICE_FLAG_STANDALONE
);
}
}
/* ISR for capture interrupt */
/**
* This function is ISR for capture interrupt.
* level: RT_TRUE denotes high level pulse, and RT_FALSE denotes low level pulse.
*/
void
rt_hw_capture_isr
(
struct
rt_capture_device
*
capture
,
rt_bool_t
level
)
void
rt_hw_capture_isr
(
struct
rt_capture_device
*
capture
,
rt_bool_t
level
)
{
{
struct
capture_data
_struct
data
;
struct
capture_data
data
;
rt_size_t
receive_size
;
rt_size_t
receive_size
;
if
(
capture
->
ops
->
get_pulsewidth
(
capture
,
&
data
.
pulsewidth_us
)
!=
RT_EOK
)
if
(
capture
->
ops
->
get_pulsewidth
(
capture
,
&
data
.
pulsewidth_us
)
!=
RT_EOK
)
{
{
return
;
return
;
}
}
data
.
is_high
=
level
;
data
.
is_high
=
level
;
rt_ringbuffer_put
(
capture
->
ringbuff
,
(
rt_uint8_t
*
)
&
data
.
pulsewidth_us
,
sizeof
(
rt_uint32_t
));
if
(
rt_ringbuffer_put
(
capture
->
ringbuff
,
(
rt_uint8_t
*
)
&
data
,
sizeof
(
struct
capture_data
))
==
0
)
{
LOG_W
(
"capture ringbuffer doesn't have enough space."
);
}
receive_size
=
rt_ringbuffer_data_len
(
capture
->
ringbuff
)
/
sizeof
(
struct
capture_data
);
receive_size
=
rt_ringbuffer_data_len
(
capture
->
ringbuff
);
if
(
receive_size
>=
capture
->
watermark
)
if
(
receive_size
>=
capture
->
watermark
)
{
{
/* indicate to upper layer application */
/* indicate to upper layer application */
if
(
capture
->
parent
.
rx_indicate
!=
RT_NULL
)
if
(
capture
->
parent
.
rx_indicate
!=
RT_NULL
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录