设为首页 加入收藏

TOP

在Amazon FreeRTOS V10中使用运行时统计信息(三)
2019-08-29 23:53:01 】 浏览:95
Tags:Amazon FreeRTOS V10 使用 行时 统计 信息
也可以使用任何其他定时器)。

 

添加FTM0

  定时器配置为10 kHz:

 

定时器输出频率

  我们将使用定时器中断来增加一个计数器,所以不要忘记打开中断:

 

定时器溢出中断使能

  然后单击按钮以更新项目源:

 

更新项目

  切换回开发人员视角。

5、定时器ISR

  接下来,我们将定时器中断代码添加到应用程序:

 1 #include "fsl_ftm.h"
 2 
 3 static uint32_t RTOS_RunTimeCounter; /* runtime counter, used for configGENERATE_RUNTIME_STATS */
 4 
 5  
 6 
 7 void FTM0_IRQHandler(void) {
 8 
 9   /* Clear interrupt flag.*/
10 
11   FTM_ClearStatusFlags(FTM0, kFTM_TimeOverflowFlag);
12 
13   RTOS_RunTimeCounter++; /* increment runtime counter */
14 
15 }

6、添加定时器驱动

  该项目尚未编译,因为必要的驱动程序尚未成为项目的一部分。要添加它们,请使用“管理SDK组件”按钮:

 

管理SDK组件按钮

  然后检查ftm驱动程序并按OK,将额外的驱动程序源添加到项目中。

 

FTM驱动程序

7、向FreeRTOS添加定时器:用于运行时统计的FreeRTOS定时器宏

  将以下行添加到FreeRTOSConfig.h:

1 extern void RTOS_AppConfigureTimerForRuntimeStats(void);
2 
3 #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()   RTOS_AppConfigureTimerForRuntimeStats()
4 
5 extern uint32_t RTOS_AppGetRuntimeCounterValueFromISR(void);
6 
7 #define portGET_RUN_TIME_COUNTER_VALUE()           RTOS_AppGetRuntimeCounterValueFromISR()

  这告诉FreeRTOS它将用于初始化定时器的功能以及获取定时器值的功能。

 

向FreeRTOSConfig.h添加了运行时计数器设置

8FreeRTOS Callback for Timer

  现在我们需要添加我们配置FreeRTOS使用的两个回调。

 1 void RTOS_AppConfigureTimerForRuntimeStats(void) {
 2 
 3   RTOS_RunTimeCounter = 0;
 4 
 5   EnableIRQ(FTM0_IRQn);
 6 
 7 }
 8 
 9  
10 
11 uint32_t RTOS_AppGetRuntimeCounterValueFromISR(void) {
12 
13   return RTOS_RunTimeCounter;
14 
15 }

9、正在运行...

  构建和调试您的应用程序。如果您现在停止应用程序并检查任务列表,它现在显示运行时信息:

 

显示运行时信息

10、没有Eclipse?没问题!

  上面我使用了FreeRTOS的Eclipse Task List视图,这是NXP为他们的基于Eclipse的IDE(MCUXpresso IDE,S32DS for ARM和Kinetis Design Studio)所做的事情。但是可以直接从应用程序显示该信息,例如在终端LCD显示器上。McuOnEclipse上的FreeRTOS 包含一个使用它的shell /终端接口。

 

控制台上的任务运行时信息

  下面的代码片段显示了如何为每个任务打印信息:

 1 #if configGENERATE_RUN_TIME_STATS
 2 
 3   ulTotalTime = portGET_RUN_TIME_COUNTER_VALUE(); /* get total time passed in system */
 4 
 5   ulTotalTime /= 100UL; /* For percentage calculations. */
 6 
 7 #endif
 8 
 9 ...
10 
11 #if configGENERATE_RUN_TIME_STATS && configUSE_TRACE_FACILITY
12 
13       /* runtime */
14 
15       UTIL1_strcpy(tmpBuf, sizeof(tmpBuf), (unsigned char*)"0x");
16 
17       UTIL1_strcatNum32Hex(tmpBuf, sizeof(tmpBuf), taskStatus.ulRunTimeCounter);
18 
19       if (ulTotalTime>0) { /* to avoid division by zero */
20 
21         /* What percentage of the total run time has the task used?
22 
23            This will always be rounded down to the nearest integer.
24 
25            ulTotalRunTime has already been divided by 100. */
26 
27         ulStatsAsPercentage = taskStatus.ulRunTimeCounter/ulTotalTime;
28 
29         if (ulStatsAsPercentage>0) {
30 
31           UTIL1_strcat(tmpBuf, sizeof(tmpBuf), (unsigned char*)" (");
32 
33           UTIL1_strcatNum16uFormatted(tmpBuf, sizeof(tmpBuf), ulStatsAsPercentage, ' ', 3);
34 
35           UTIL1_strcat(tmpBuf, sizeof(tmpBuf), (unsigned char*)"%)");
36 
37         } else {
38 
39           /* If the percentage is zero here then the task has consumed less than 1% of the total run time. */
40 
41           UTIL1_strcat(tmpBuf, sizeof(tmpBuf), (unsigned char*)" ( <1%)");
42 
43         }
44 
45       }
46 
47       buf[0] = '\0';
48 
49       UTIL1_strcatPad(buf, sizeof(buf), tmpBuf, ' ', PAD_STAT_TASK_RUNTIME);
50 
51       CLS1_SendStr(buf, io->stdOut);
52 
53 #endif
54 
55       CLS1_SendSt
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇痞子衡嵌入式:PCM编码与Waveform.. 下一篇OpenWrt-Git依赖报错

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目