Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dgr6878
rt-thread
提交
7c441785
R
rt-thread
项目概览
dgr6878
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7c441785
编写于
12月 23, 2017
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DeviceDrivers] Add CPU time
上级
ef922c30
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
217 addition
and
0 deletion
+217
-0
components/drivers/Kconfig
components/drivers/Kconfig
+24
-0
components/drivers/cputime/SConscript
components/drivers/cputime/SConscript
+14
-0
components/drivers/cputime/cputime.c
components/drivers/cputime/cputime.c
+70
-0
components/drivers/cputime/cputime_cortexm.c
components/drivers/cputime/cputime_cortexm.c
+66
-0
components/drivers/include/drivers/cputime.h
components/drivers/include/drivers/cputime.h
+39
-0
components/drivers/include/rtdevice.h
components/drivers/include/rtdevice.h
+4
-0
未找到文件。
components/drivers/Kconfig
浏览文件 @
7c441785
...
...
@@ -16,6 +16,30 @@ config RT_USING_HWTIMER
bool "Using hardware timer device drivers"
default n
config RT_USING_CPUTIME
bool "Enable CPU time for high resolution clock counter"
default n
help
When enable this option, the BSP should provide a rt_clock_cputime_ops
for CPU time by:
clock_cpu_setops(const struct rt_clock_cputime_ops *ops);
Then developer can use high resolution clock counter with:
ts = clock_cpu_gettime();
/* The unit of clock_cpu_gettime() can be returned by */
unit = clock_cpu_getres(); /* number for nanosecond */
if RT_USING_CPUTIME
config RT_USING_CPUTIME_CORTEXM
bool "Use DWT for CPU time"
default y
depends on ARCH_ARM_CORTEX_M3 || ARCH_ARM_CORTEX_M4 || ARCH_ARM_CORTEX_M7
help
Some Cortex-M3/4/7 MCU has Data Watchpoint and Trace Register, use
the cycle counter in DWT for CPU time.
endif
config RT_USING_I2C
bool "Using I2C device drivers"
default n
...
...
components/drivers/cputime/SConscript
0 → 100644
浏览文件 @
7c441785
from
building
import
*
cwd
=
GetCurrentDir
()
CPPPATH
=
[
cwd
+
'/../include'
]
src
=
Split
(
'''
cputime.c
'''
)
if
GetDepend
(
'RT_USING_CPUTIME_CORTEXM'
):
src
+=
[
'cputime_cortexm.c'
]
group
=
DefineGroup
(
'DeviceDrivers'
,
src
,
depend
=
[
'RT_USING_CPUTIME'
],
CPPPATH
=
CPPPATH
)
Return
(
'group'
)
components/drivers/cputime/cputime.c
0 → 100644
浏览文件 @
7c441785
/*
* File : cputime.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-23 Bernard first version
*/
#include <rtdevice.h>
#include <rtthread.h>
static
const
struct
rt_clock_cputime_ops
*
_cputime_ops
=
RT_NULL
;
/**
* The clock_cpu_getres() function shall return the resolution of CPU time, the
* number of nanosecond per tick.
*/
uint32_t
clock_cpu_getres
(
void
)
{
if
(
_cputime_ops
)
return
_cputime_ops
->
cputime_getres
();
rt_set_errno
(
-
ENOSYS
);
return
0
;
}
/**
* The clock_cpu_gettime() function shall return the current value of cpu time tick.
*/
uint32_t
clock_cpu_gettime
(
void
)
{
if
(
_cputime_ops
)
return
_cputime_ops
->
cputime_gettime
();
rt_set_errno
(
-
ENOSYS
);
return
0
;
}
/**
* The clock_cpu_seops() function shall set the ops of cpu time.
*
* @return always return 0.
*/
int
clock_cpu_setops
(
const
struct
rt_clock_cputime_ops
*
ops
)
{
_cputime_ops
=
ops
;
if
(
ops
)
{
RT_ASSERT
(
ops
->
cputime_getres
!=
RT_NULL
);
RT_ASSERT
(
ops
->
cputime_gettime
!=
RT_NULL
);
}
return
0
;
}
components/drivers/cputime/cputime_cortexm.c
0 → 100644
浏览文件 @
7c441785
/*
* File : cputime_cortexm.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-23 Bernard first version
*/
#include <rthw.h>
#include <rtdevice.h>
#include <rtthread.h>
#include <board.h>
/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
static
uint32_t
cortexm_cputime_getres
(
void
)
{
return
(
1000
*
1000
*
1000
)
/
SystemCoreClock
;
}
static
uint32_t
cortexm_cputime_gettime
(
void
)
{
return
DWT
->
CYCCNT
;
}
const
static
struct
rt_clock_cputime_ops
_cortexm_ops
=
{
cortexm_cputime_getres
,
cortexm_cputime_gettime
};
int
cortexm_cputime_init
(
void
)
{
/* check support bit */
if
((
DWT
->
CTRL
&
(
1UL
<<
DWT_CTRL_NOCYCCNT_Pos
))
==
0
)
{
/* whether cycle counter not enabled */
if
((
DWT
->
CTRL
&
(
1UL
<<
DWT_CTRL_CYCCNTENA_Pos
))
==
0
)
{
/* enable cycle counter */
DWT
->
CTRL
|=
(
1UL
<<
DWT_CTRL_CYCCNTENA_Pos
);
}
clock_cpu_setops
(
&
_cortexm_ops
);
}
return
0
;
}
INIT_BOARD_EXPORT
(
cortexm_cputime_init
);
components/drivers/include/drivers/cputime.h
0 → 100644
浏览文件 @
7c441785
/*
* File : cputime.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-23 Bernard first version
*/
#ifndef CPUTIME_H__
#define CPUTIME_H__
struct
rt_clock_cputime_ops
{
uint32_t
(
*
cputime_getres
)
(
void
);
uint32_t
(
*
cputime_gettime
)(
void
);
};
uint32_t
clock_cpu_getres
(
void
);
uint32_t
clock_cpu_gettime
(
void
);
int
clock_cpu_setops
(
const
struct
rt_clock_cputime_ops
*
ops
);
#endif
components/drivers/include/rtdevice.h
浏览文件 @
7c441785
...
...
@@ -108,6 +108,10 @@ extern "C" {
#include "drivers/audio.h"
#endif
#ifdef RT_USING_CPUTIME
#include "drivers/cputime.h"
#endif
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录