|
@@ -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);
|