From 436bd377f94324c50a0ab95f0e80ca7af6dba12b Mon Sep 17 00:00:00 2001 From: aixiao Date: Sun, 14 Apr 2024 22:26:12 +0800 Subject: [PATCH] Add the stack high water mark for custom tasks using the printTaskStackHighWaterMark() function. --- Source/common.c | 20 ++++++++++++++++++++ Source/common.h | 6 ++++++ Source/main.c | 11 ++++------- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Source/common.c b/Source/common.c index 1826151..a7536d9 100644 --- a/Source/common.c +++ b/Source/common.c @@ -33,29 +33,49 @@ void vApplicationTickHook(void) { /* The full demo includes a software timer demo/test that requires prodding periodically from the tick interrupt. */ + /*完整的演示包括软件定时器演示/测试,需要 + 从滴答声中断中周期性地发出提示*/ #if (mainENABLE_TIMER_DEMO == 1) vTimerPeriodicISRTests(); #endif /* Call the periodic queue overwrite from ISR demo. */ + /*调用ISR演示中的周期性队列覆盖*/ #if (mainENABLE_QUEUE_OVERWRITE == 1) vQueueOverwritePeriodicISRDemo(); #endif /* Call the periodic event group from ISR demo. */ + /*从ISR演示中调用定期事件组*/ #if (mainENABLE_EVENT_GROUP == 1) vPeriodicEventGroupsProcessing(); #endif /* Call the code that uses a mutex from an ISR. */ + /*从ISR调用使用互斥的代码*/ #if (mainENABLE_INTERRUPT_SEMAPHORE == 1) vInterruptSemaphorePeriodicTest(); #endif /* Call the code that 'gives' a task notification from an ISR. */ + /*调用从ISR“发出”任务通知的代码*/ #if (mainENABLE_TASK_NOTIFY == 1) xNotifyTaskFromISR(); #endif } #endif } + + +void _printTaskStackHighWaterMark(void) +{ + TaskHandle_t currentTask = xTaskGetCurrentTaskHandle(); + if (currentTask != NULL) + { + printf("TASK STACK HIGH WATER MARK: %ld\n", uxTaskGetStackHighWaterMark(currentTask)); + } + else + { + printf("FAILED TO GET CURRENT TASK HANDLE.\n"); + } +} diff --git a/Source/common.h b/Source/common.h index b37fa88..c88ea5d 100644 --- a/Source/common.h +++ b/Source/common.h @@ -6,11 +6,17 @@ #include "task.h" #include "semphr.h" +#include #include "hardware/pio.h" + +#define BUILD(fmt...) do { fprintf(stderr,"%s %s ",__DATE__,__TIME__); fprintf(stderr, ##fmt); } while(0) + static inline bool uart_rx_program_available(PIO pio, uint sm) { return !pio_sm_is_rx_fifo_empty(pio, sm); } +void _printTaskStackHighWaterMark(void); + #endif diff --git a/Source/main.c b/Source/main.c index ffeaf6d..17affb7 100644 --- a/Source/main.c +++ b/Source/main.c @@ -42,9 +42,7 @@ void Read_Onboard_Temperature(void *pvParameters) adc_set_temp_sensor_enabled(true); adc_select_input(4); // Input 4 is the onboard temperature sensor. - UBaseType_t uxHighWaterMark; - uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL ); - printf("%ld\n", uxHighWaterMark); + _printTaskStackHighWaterMark(); while (1) { const float conversionFactor = 3.3f / (1 << 12); @@ -54,8 +52,7 @@ void Read_Onboard_Temperature(void *pvParameters) printf("Onboard temperature %.02f°C %.02f°F\n", tempC, (tempC * 9 / 5 + 32)); - uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL ); - printf("%ld\n", uxHighWaterMark); + _printTaskStackHighWaterMark(); vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时 } @@ -88,7 +85,7 @@ int main(void) { printf("Temperature Task Error!"); } - +/* // IM1253B 电压、功率模块 xReturned = xTaskCreate(IM1253B, "IM1253B task", 1024, NULL, tskIDLE_PRIORITY, &IM1253B_xHandle); if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) @@ -116,7 +113,7 @@ int main(void) { printf("HC-04 Task Error!"); } - +*/ vTaskStartScheduler(); return 0;