Add the stack high water mark for custom tasks using the printTaskStackHighWaterMark() function.

This commit is contained in:
aixiao 2024-04-14 22:26:12 +08:00
parent c6fdf8d4e2
commit 436bd377f9
3 changed files with 30 additions and 7 deletions

View File

@ -33,29 +33,49 @@ void vApplicationTickHook(void)
{ {
/* The full demo includes a software timer demo/test that requires /* The full demo includes a software timer demo/test that requires
prodding periodically from the tick interrupt. */ prodding periodically from the tick interrupt. */
/*完整的演示包括软件定时器演示/测试,需要
*/
#if (mainENABLE_TIMER_DEMO == 1) #if (mainENABLE_TIMER_DEMO == 1)
vTimerPeriodicISRTests(); vTimerPeriodicISRTests();
#endif #endif
/* Call the periodic queue overwrite from ISR demo. */ /* Call the periodic queue overwrite from ISR demo. */
/*调用ISR演示中的周期性队列覆盖*/
#if (mainENABLE_QUEUE_OVERWRITE == 1) #if (mainENABLE_QUEUE_OVERWRITE == 1)
vQueueOverwritePeriodicISRDemo(); vQueueOverwritePeriodicISRDemo();
#endif #endif
/* Call the periodic event group from ISR demo. */ /* Call the periodic event group from ISR demo. */
/*从ISR演示中调用定期事件组*/
#if (mainENABLE_EVENT_GROUP == 1) #if (mainENABLE_EVENT_GROUP == 1)
vPeriodicEventGroupsProcessing(); vPeriodicEventGroupsProcessing();
#endif #endif
/* Call the code that uses a mutex from an ISR. */ /* Call the code that uses a mutex from an ISR. */
/*从ISR调用使用互斥的代码*/
#if (mainENABLE_INTERRUPT_SEMAPHORE == 1) #if (mainENABLE_INTERRUPT_SEMAPHORE == 1)
vInterruptSemaphorePeriodicTest(); vInterruptSemaphorePeriodicTest();
#endif #endif
/* Call the code that 'gives' a task notification from an ISR. */ /* Call the code that 'gives' a task notification from an ISR. */
/*调用从ISR“发出”任务通知的代码*/
#if (mainENABLE_TASK_NOTIFY == 1) #if (mainENABLE_TASK_NOTIFY == 1)
xNotifyTaskFromISR(); xNotifyTaskFromISR();
#endif #endif
} }
#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");
}
}

View File

@ -6,11 +6,17 @@
#include "task.h" #include "task.h"
#include "semphr.h" #include "semphr.h"
#include <stdio.h>
#include "hardware/pio.h" #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) static inline bool uart_rx_program_available(PIO pio, uint sm)
{ {
return !pio_sm_is_rx_fifo_empty(pio, sm); return !pio_sm_is_rx_fifo_empty(pio, sm);
} }
void _printTaskStackHighWaterMark(void);
#endif #endif

View File

@ -42,9 +42,7 @@ void Read_Onboard_Temperature(void *pvParameters)
adc_set_temp_sensor_enabled(true); adc_set_temp_sensor_enabled(true);
adc_select_input(4); // Input 4 is the onboard temperature sensor. adc_select_input(4); // Input 4 is the onboard temperature sensor.
UBaseType_t uxHighWaterMark; _printTaskStackHighWaterMark();
uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL );
printf("%ld\n", uxHighWaterMark);
while (1) { while (1) {
const float conversionFactor = 3.3f / (1 << 12); 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)); printf("Onboard temperature %.02f°C %.02f°F\n", tempC, (tempC * 9 / 5 + 32));
uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL ); _printTaskStackHighWaterMark();
printf("%ld\n", uxHighWaterMark);
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时 vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
} }
@ -88,7 +85,7 @@ int main(void)
{ {
printf("Temperature Task Error!"); printf("Temperature Task Error!");
} }
/*
// IM1253B 电压、功率模块 // IM1253B 电压、功率模块
xReturned = xTaskCreate(IM1253B, "IM1253B task", 1024, NULL, tskIDLE_PRIORITY, &IM1253B_xHandle); xReturned = xTaskCreate(IM1253B, "IM1253B task", 1024, NULL, tskIDLE_PRIORITY, &IM1253B_xHandle);
if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
@ -116,7 +113,7 @@ int main(void)
{ {
printf("HC-04 Task Error!"); printf("HC-04 Task Error!");
} }
*/
vTaskStartScheduler(); vTaskStartScheduler();
return 0; return 0;