diff --git a/src/drivers/nuttx/lv_nuttx_entry.c b/src/drivers/nuttx/lv_nuttx_entry.c index 54c45f55a..e484a137d 100644 --- a/src/drivers/nuttx/lv_nuttx_entry.c +++ b/src/drivers/nuttx/lv_nuttx_entry.c @@ -14,6 +14,7 @@ #include #include #include "lv_nuttx_cache.h" +#include "lv_nuttx_profiler.h" #include "../../../lvgl.h" @@ -98,6 +99,10 @@ void lv_nuttx_init(const lv_nuttx_dsc_t * dsc, lv_nuttx_result_t * result) lv_nuttx_cache_init(); +#if LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN + lv_nuttx_profiler_init(); +#endif + if(result) { lv_memzero(result, sizeof(lv_nuttx_result_t)); } diff --git a/src/drivers/nuttx/lv_nuttx_profiler.c b/src/drivers/nuttx/lv_nuttx_profiler.c new file mode 100644 index 000000000..3139c98f7 --- /dev/null +++ b/src/drivers/nuttx/lv_nuttx_profiler.c @@ -0,0 +1,96 @@ +/** + * @file lv_nuttx_profiler.c + * + */ + +/********************* + * INCLUDES + *********************/ + +#include "lv_nuttx_profiler.h" +#include "../../../lvgl.h" + +#if LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN + +#include +#include + +/********************* + * DEFINES + *********************/ + +#define TICK_TO_USEC(tick) ((tick) / cpu_freq) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +static uint32_t cpu_freq = 0; /* MHz */ + +/********************** + * STATIC VARIABLES + **********************/ + +static uint32_t tick_get_cb(void); +static void flush_cb(const char * buf); + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +void lv_nuttx_profiler_init(void) +{ + cpu_freq = (uint32_t)up_perf_getfreq() / 1000000; + if(cpu_freq == 0) { + LV_LOG_ERROR("Failed to get CPU frequency"); + return; + } + LV_LOG_USER("CPU frequency: %" LV_PRIu32 " MHz", cpu_freq); + + lv_profiler_builtin_config_t config; + lv_profiler_builtin_config_init(&config); + config.tick_per_sec = 1000000; /* 1 sec = 1000000 usec */ + config.tick_get_cb = tick_get_cb; + config.flush_cb = flush_cb; + lv_profiler_builtin_init(&config); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +static uint32_t tick_get_cb(void) +{ + static uint32_t prev_tick = 0; + static uint32_t cur_tick_us = 0; + uint32_t act_time = up_perf_gettime(); + uint32_t elaps; + + /*If there is no overflow in sys_time simple subtract*/ + if(act_time >= prev_tick) { + elaps = act_time - prev_tick; + } + else { + elaps = UINT32_MAX - prev_tick + 1; + elaps += act_time; + } + + cur_tick_us += TICK_TO_USEC(elaps); + prev_tick = act_time; + return cur_tick_us; +} + +static void flush_cb(const char * buf) +{ + printf("%s", buf); +} + +#endif diff --git a/src/drivers/nuttx/lv_nuttx_profiler.h b/src/drivers/nuttx/lv_nuttx_profiler.h new file mode 100644 index 000000000..8b8cf6521 --- /dev/null +++ b/src/drivers/nuttx/lv_nuttx_profiler.h @@ -0,0 +1,39 @@ +/** + * @file lv_nuttx_profiler.h + * + */ + +#ifndef LV_NUTTX_PROFILER_H +#define LV_NUTTX_PROFILER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_nuttx_profiler_init(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_NUTTX_PROFILER_H*/