79 2.5 uxTaskGetStackHighWaterMark()
[[FreeRTOS_Reference_Manual_V10.0.0.pdf#page=79&selection=0,2,4,29|FreeRTOS_Reference_Manual_V10.0.0, page 79]]
#include "FreeRTOS.h"
#include "task.h"
UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
函数说明:
xTask: 要获取栈水位线的目标函数的句柄。#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"
void task1(void *pvPara)
{
while (true) {
printf("Task1 is running!\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void app_main(void)
{
TaskHandle_t handle_task1;
xTaskCreate(task1, "Task1", 2048, NULL, 1, &handle_task1);
printf("high water mark: %d\n", uxTaskGetStackHighWaterMark(handle_task1));
}

从输出结果可以得到,栈水位线是1352,因为我们设置的栈深是2048,因此次函数最少需要:
2048 - 1352 = 696,即此函数最少需要696个栈深的内存空间。
因为我们使用的是32位的ESP32,在32位CPU中,一个栈深占用4个字节的内存,所以这个函数最少使用:696 * 4 = 2784个字节的内存。[[堆栈宽度与深度]]