[cputime] suuport perf_counter

This commit is contained in:
Meco Man 2022-06-14 06:50:31 -04:00 committed by guo
parent b010e434ed
commit 808259135f
2 changed files with 16 additions and 7 deletions

View File

@ -79,12 +79,10 @@ config RT_USING_CPUTIME
if RT_USING_CPUTIME
config RT_USING_CPUTIME_CORTEXM
bool "Use DWT for CPU time"
bool "Support Cortex-M CPU"
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.
depends on ARCH_ARM_CORTEX_M0 || ARCH_ARM_CORTEX_M3 || ARCH_ARM_CORTEX_M4 || ARCH_ARM_CORTEX_M7
select PKG_USING_PERF_COUNTER
endif
config RT_USING_I2C

View File

@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2017-12-23 Bernard first version
* 2022-06-14 Meco Man suuport pref_counter
*/
#include <rthw.h>
@ -13,9 +14,11 @@
#include <rtthread.h>
#include <board.h>
#ifdef PKG_USING_PERF_COUNTER
#include <perf_counter.h>
#endif
/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
static float cortexm_cputime_getres(void)
{
float ret = 1000 * 1000 * 1000;
@ -26,7 +29,11 @@ static float cortexm_cputime_getres(void)
static uint64_t cortexm_cputime_gettime(void)
{
#ifdef PKG_USING_PERF_COUNTER
return get_system_ticks();
#else
return DWT->CYCCNT;
#endif
}
const static struct rt_clock_cputime_ops _cortexm_ops =
@ -35,8 +42,12 @@ const static struct rt_clock_cputime_ops _cortexm_ops =
cortexm_cputime_gettime
};
int cortexm_cputime_init(void)
{
#ifdef PKG_USING_PERF_COUNTER
clock_cpu_setops(&_cortexm_ops);
#else
/* check support bit */
if ((DWT->CTRL & (1UL << DWT_CTRL_NOCYCCNT_Pos)) == 0)
{
@ -52,7 +63,7 @@ int cortexm_cputime_init(void)
clock_cpu_setops(&_cortexm_ops);
}
#endif /* PKG_USING_PERF_COUNTER */
return 0;
}
INIT_BOARD_EXPORT(cortexm_cputime_init);