1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

feat(nuttx): add builtin profiler adaptation (#5415)

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
_VIFEXTech 2024-01-22 21:31:22 +08:00 committed by GitHub
parent 7b68aef4ab
commit 2e90e65383
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 140 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include <nuttx/tls.h>
#include <syslog.h>
#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));
}

View File

@ -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 <nuttx/arch.h>
#include <stdio.h>
/*********************
* 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

View File

@ -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*/