簡體   English   中英

FreeRTOS vTaskGetRunTimeStats

[英]FreeRTOS vTaskGetRunTimeStats

首先,我正在使用 SiLabs IDE 在 Giant Gecko EFM32 上進行構建,並希望通過 vTaskGetRunTimeStats() 跟蹤我的任務使用情況。 所以首先,我使用 STK3700_freertos_tickless,它有兩個任務——我添加了其中一個:

static char cBuffer[ 512 ];
vTaskGetRunTimeStats( cBuffer );

到我的 FreeRTOSConfig.h:

#define configUSE_TRACE_FACILITY                  ( 1 )
#define configGENERATE_RUN_TIME_STATS             ( 1 )
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()  ( ulHighFrequencyTimerTicks = 0UL )
#define configUSE_STATS_FORMATTING_FUNCTIONS      ( 1 )
#define portGET_RUN_TIME_COUNTER_VALUE()          ulHighFrequencyTimerTicks

現在,首先 - 我刪除了:

volatile unsigned long ulHighFrequencyTimerTicks;

並將其移至 tasks.c,因為我得到:

./FreeRTOS/efm32gg/tasks.o: 在函數vTaskStartScheduler': C:\Users\Chris\SimplicityStudio\v3_workspace\STK3700_freertos_tickless\GNU ARM v4.8.3 - Debug/../FreeRTOS/efm32gg/tasks.c:1532: undefined reference to ulHighFrequencyTimerTicks'./FreeRTOS/efm32gg/tasks.o: 在函數uxTaskGetSystemState': C:\Users\Chris\SimplicityStudio\v3_workspace\STK3700_freertos_tickless\GNU ARM v4.8.3 - Debug/../FreeRTOS/efm32gg/tasks.c:1815: undefined reference to 。/FreeRTOS/efm32gg/tasks.o: 在函數vTaskSwitchContext': C:\Users\Chris\SimplicityStudio\v3_workspace\STK3700_freertos_tickless\GNU ARM v4.8.3 - Debug/../FreeRTOS/efm32gg/tasks.c:2173: undefined reference to ulHighFrequencyTimerTicks 的 collect2.exe 的引用:錯誤:ld 返回 1 退出狀態 make:*** [STK3700_freertos_tickless.axf] 錯誤 1

如果我把它放在 tasks.c 中以消除錯誤,那么我的演示就會卡在

void vPortFree( void *pv )
{
    /* Memory cannot be freed using this scheme.  See heap_2.c, heap_3.c and
    heap_4.c for alternative implementations, and the memory management pages of
    http://www.FreeRTOS.org for more information. */
    ( void ) pv;

    /* Force an assert as it is invalid to call this function. */
    configASSERT( pv == NULL );
}

增加我的堆沒有任何幫助。 我知道我應該解決第一個錯誤,但是將它作為 extern 放在 FreeRTOSConfig.h 中是行不通的。

缺少哪個設置? 將 high tick def 移動到 tasks.c 是否有效?

提前致謝, 克里斯

更新 1:

在 FreeRTOSconfig.h 中添加函數:

/* Run time stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS             ( 1 )
extern volatile unsigned long ulHighFrequencyTimerTicks;
extern void vConfigureTimerForRunTimeStats( void );
extern unsigned long vGetTimerForRunTimeStats( void );
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()    vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE()            vGetTimerForRunTimeStats()

和 main.c 分別是:

void vConfigureTimerForRunTimeStats( void ) {
    CMU->HFRCOCTRL = 0x8;                           // Set High Freq. RC Osc. to 1 MHz
    CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_TIMER3;     // Enable clock for Timer3
    TIMER3->CNT = 0x0;
    TIMER3->CTRL = ( TIMER3->CTRL & ~_TIMER_CTRL_PRESC_MASK) | TIMER_CTRL_PRESC_DIV1024; // Prescaler needed to reduce resolution, 1024
    TIMER3->CMD = 0x1;                              // Start Timer3
}

unsigned long vGetTimerForRunTimeStats( void ) {
    return ( TIMER3->CNT );
}

所有編譯都很好,我的 vTaskGetRunTimeStats 在以下函數中被調用,基於 STK3700_freertos_tickless 示例代碼:

static void LcdPrint(void *pParameters)
{
  pParameters = pParameters;   /* to quiet warnings */
  static char sBuffer[ 240 ]; // 40 B per task

  for (;;)
  {
    /* Wait for semaphore, then display next number */
   if (pdTRUE == xSemaphoreTake(sem, portMAX_DELAY)) {  
    SegmentLCD_Write(text);
    }

   vTaskGetRunTimeStats( ( char * ) sBuffer );

  }
}

但現在我的錯誤是一個未定義的引用:

完成構建:../src/main.c 構建目標:STK3700_freertos_tickless.axf 調用:GNU ARM C 鏈接器 arm-none-eabi-gcc -g -gdwarf-2 -mcpu=cortex-m3 -mthumb -T "STK3700_freertos_tickless.ld " -Xlinker --gc-sections -Xlinker -Map="STK3700_freertos_tickless.map" --specs=nano.specs -o STK3700_freertos_tickless.axf "./src/low_power_tick_management.o" "./src/main.o" "。 /emlib/em_assert.o" "./emlib/em_burtc.o" "./emlib/em_cmu.o" "./emlib/em_emu.o" "./emlib/em_gpio.o" "./emlib/em_int. o" "./emlib/em_lcd.o" "./emlib/em_rmu.o" "./emlib/em_rtc.o" "./emlib/em_system.o" "./FreeRTOS/efm32gg/croutine.o" " ./FreeRTOS/efm32gg/heap_1.o" "./FreeRTOS/efm32gg/list.o" "./FreeRTOS/efm32gg/port_gcc.o" "./FreeRTOS/efm32gg/queue.o" "./FreeRTOS/efm32gg/ tasks.o" "./FreeRTOS/efm32gg/timers.o" "./Drivers/segmentlcd.o" "./Drivers/sleep.o" "./CMSIS/efm32gg/startup_gcc_efm32gg.o" "./CMSIS/efm32gg /system_efm32gg.o" "./BSP/bsp_trace.o" -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group./src/main.o: 在LcdPrint': C:\Users\Chris\SimplicityStudio\v3_workspace\STK3700_freertos_tickless\GNU ARM v4.8.3 - Debug/../src/main.c:61: undefined reference to函數中 LcdPrint': C:\Users\Chris\SimplicityStudio\v3_workspace\STK3700_freertos_tickless\GNU ARM v4.8.3 - Debug/../src/main.c:61: undefined reference to vTaskGetRunTimeStats' collect2.exe: 錯誤:ld 返回 1 退出狀態制作:*** [STK3700_freertos_tickless.axf] 錯誤 1

我的 main.c 文件中有 #include "FreeRTOSConfig.h" #include "FreeRTOS.h" 和 #include "task.h"。 Task.h 包含:void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION;

最后有什么想法嗎? 差不多好了! C

更新 2:

忘記更新 1,代碼有效 - 一個干凈的項目就成功了。

但現在確實是 heap_1.c 問題卡在了 assertEFM 函數中。

file    "../FreeRTOS/efm32gg/heap_1.c"  
line    153 

我將嘗試增加堆棧 + 也使用較小的 sprintf 代碼。 最好的,C

我認為這里有幾件事混在一起。

首先,我不知道 ulHighFrequencyTimerTicks 通常在哪里定義或遞增,它不是 FreeRTOS 變量,因此假設它是應用程序的一部分。 這是有道理的,因為運行時統計需要應用程序提供的時鍾(因為時鍾取決於可用的硬件)。 在任何情況下,它都只是一個變量,所以正常的 C 作用域規則適用。 我希望它將在一個文件中聲明並遞增,但隨后定義 portGET_RUN_TIME_COUNTER_VALUE() 以引用它意味着您正試圖從一個單獨的文件中引用它 - 因此鏈接器錯誤。 這可以通過將變量保留在原處並在試圖在范圍外使用它的文件中將其聲明為 extern 來解決。 或者,在聲明僅返回變量值的 ulHighFrequenyTimerTicks 的文件中實施“get”函數,並定義 portGET_RUN_TIME_COUNTER_VALUE() 以調用該函數。

(要回答其他評論 portGET_RUN_TIME_COUNTER_VALUE() 只需要評估一個值,它可以是函數返回值,或者直接引用變量: http ://www.freertos.org/rtos-run-time-stats .html )

接下來,configUSE_STATS_FORMATTING_FUNCTIONS 不需要為 1 即可使用 vTaskGetRunTimeState()。 如果您想要使用將收集的統計信息格式化為人類可讀表的輔助函數之一,它只需要為 1。 http://www.freertos.org/a00110.html#configUSE_STATS_FORMATTING_FUNCTIONS

然后,如前所述,卡在 vPortFree() 中與鏈接器問題無關。 我假設你被卡在了 configASSERT() 中? 如果是這樣,那么您正試圖釋放一個未首先通過調用 pvPortMalloc() 分配的內存塊,或者您正試圖釋放一個已損壞的內存塊,或者您正試圖釋放同一塊內存兩次。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM