freertos有很多很酷的功能,其中一个是它可以报告每个任务中花费的cpu百分比。
需要在freertosconfig.h中配置一些#定义:
#define configgenerate_run_time_stats 1
/* 1: generate runtime statistics; 0: no runtime statistics */
可以使用systick计时器,但这不会给精确的结果,因此我们该计时器。
#define configgenerate_run_time_stats_use_ticks 0
/* 1: use the rtos tick counter as runtime counter. 0: use extra timer */
接下来,需要配置如何使用计时器:为此,指定计时器配置函数的名称和获取计时器值的函数:
#define portconfigure_timer_for_run_time_stats() mcurtos_appconfiguretimerforruntimestats()
#define portget_run_time_counter_value() mcurtos_appgetruntimecountervaluefromisr()
使用i.mx rt的gpt(通用计时器):
#include fsl_gpt.h
uint32_t mcurtos_runtimecounter; //需要一个用于测量时间的32位计数器
/* runtime counter, used for configgenerate_runtime_stats */
将计时器配置为0.1毫秒(rtos滴答计时器频率的10倍),设置为1 khz:
static void appconfiguretimerforruntimestats(void) {
uint32_t gptfreq;
gpt_config_t gptconfig;
gpt_getdefaultconfig(&gptconfig);
/* initialize gpt module */
gpt_init(gpt2, &gptconfig);
/* divide gpt clock source frequency by 3 inside gpt module */
gpt_setclockdivider(gpt2, 3);
/* get gpt clock frequency */
gptfreq = clock_getfreq(kclock_perclk);
/* gpt frequency is divided by 3 inside module */
gptfreq /= 3;
/* set gpt module to 10x of the freertos tick counter */
gptfreq = usec_to_count(100, gptfreq); /* freertos tick is 1 khz */
gpt_setoutputcomparevalue(gpt2, kgpt_outputcompare_channel1, gptfreq);
/* enable gpt output compare1 interrupt */
gpt_enableinterrupts(gpt2, kgpt_outputcompare1interruptenable);
/* enable at the interrupt and start timer */
enableirq(gpt2_irqn);
gpt_starttimer(gpt2);
}
接下来是计时器中断服务例程的实现。
void gpt2_irqhandler(void) {
/* clear interrupt flag.*/
gpt_clearstatusflags(gpt2, kgpt_outputcompare1flag);
mcurtos_runtimecounter++; /* increment runtime counter */
#if defined __cortex_m && (__cortex_m == 4u || __cortex_m == 7u)
__dsb();
#endif
}
最后,在启动调度器之前,必须调用timer初始化函数。
使用串行连接接口(uart、usb、segger rtt),也可以使用命令行接口检索相同的信息:
信息显示在eclipse环境下的freertos任务列表的“运行时”列中(针对mcuxpresso ide显示):
在freertos中收集运行时信息通常需要计时器(也可以使用systick)。收集的信息可以很好地概括cpu时间的使用情况,从而有助检查系统负荷。
MTK平台山寨手机出现毛病检修方法
制造要闻:我国大数据专利公开量居世界第二 机器人专业成爆款
如何更好的使5G技术与车联网相结合
瞄准化合物半导体砷化镓领域,这个项目落户江苏
区块链应用的汽车领域规模会怎样
MIMXRT1064的FreeRTOS任务运行时统计信息
AC/DC线性电源和开关电源的区别
iPhone7Plus\三星S7Edge\谷歌Pixel XL和LG V20自拍性能评测,谁是真机皇?
PCB样板厂容易出现什么问题
重铜和极限铜PCB:孔尺寸,走线宽度和间距
英伟达四款CMP矿卡规格曝光
三星S8 Plus配置和真机图曝光 , 售价近7000元
DxOMark将在本周陆续发布新的iPhone评测
用ARM和FPGA搭建神经网络处理器通信方案
智能搬运机器人系列之利用X3派实现目标物块的识别与抓取
特斯拉不排除与一家传统车企友好合并
Galaxy Note9最新消息 谍照图大曝光
在高速应用中使用JFET输入放大器有哪些优势
非授权频谱或为5G之关键
芯片短缺已影响到低利润小家电生产 台积电拿28.87亿美元在南京扩产