From ead6f8b0a08ac1c94670dca935f357a73462470d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 13 Jun 2022 20:02:01 -0400 Subject: [PATCH] support rt-thread --- SConscript | 10 ++-------- os/perf_os_patch_rt_thread.c | 36 +++++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/SConscript b/SConscript index 26bd410..7f0421e 100644 --- a/SConscript +++ b/SConscript @@ -1,18 +1,12 @@ Import('rtconfig') from building import * -src = ['perf_counter.c', 'os/rt-thread/perf_os_patch_rt_thread.c'] - -if rtconfig.PLATFORM in ['armcc', 'armclang']: # Keil-MDK - src += ['systick_wrapper_ual.s'] - -if rtconfig.PLATFORM == 'gcc': - src += ['systick_wrapper_gcc.s'] +src = ['perf_counter.c', 'os/perf_os_patch_rt_thread.c'] cwd = GetCurrentDir() path = [cwd] group = [] -group = DefineGroup('perf_counter', src, depend = ['PKG_USING_PERFCOUNTER'], CPPPATH = path) +group = DefineGroup('perf_counter', src, depend = ['PKG_USING_PERF_COUNTER'], CPPDEFINES = ['__PERF_CNT_USE_RTOS__'], CPPPATH = path) Return('group') diff --git a/os/perf_os_patch_rt_thread.c b/os/perf_os_patch_rt_thread.c index e2873b0..ba00f41 100644 --- a/os/perf_os_patch_rt_thread.c +++ b/os/perf_os_patch_rt_thread.c @@ -52,8 +52,8 @@ struct __task_cycle_info_t { #ifndef RT_USING_HOOK -#error In order to use perf_counter:RT-Thread-Patch, please define RT_USING_HOOK\ - in rtconfig.h. If you don't want to use this patch, please un-select it in RTE. +#error "In order to use perf_counter:RT-Thread-Patch, please define RT_USING_HOOK \ +in rtconfig.h. If you don't want to use this patch, please un-select it in RTE." #endif @@ -75,12 +75,34 @@ void __rt_thread_scheduler_hook(struct rt_thread *from, struct rt_thread *to) __on_context_switch_in(to->stack_addr); } -void __perf_os_patch_init(void) -{ - rt_scheduler_sethook(&__rt_thread_scheduler_hook); -} - task_cycle_info_t * get_rtos_task_cycle_info(void) { return &(((struct __task_cycle_info_t *)rt_current_thread->stack_addr)->tInfo); } + +void __perf_os_patch_init(void) +{ +#ifdef PKG_USING_PERF_COUNTER + rt_tick_sethook(user_code_insert_to_systick_handler); +#endif + rt_scheduler_sethook(__rt_thread_scheduler_hook); +} + +#ifdef PKG_USING_PERF_COUNTER +void __ensure_systick_wrapper(void) +{ +} + +#define DBG_TAG "perf_counter" +#define DBG_LVL DBG_INFO +#include + +static int _perf_counter_init(void) +{ + extern uint32_t SystemCoreClock; + init_cycle_counter(true); + LOG_I("perf_counter init, SystemCoreClock:%d", SystemCoreClock); + return 0; +} +INIT_PREV_EXPORT(_perf_counter_init); +#endif