btw: have not tried the code yet, just read it perhabs this helps too:
using uxTaskGetStackHighWaterMark function to determine how much stack has actually been used.. that interrupts also use the stack of the task that is interrupted
I implement GetTaskHighWaterMarkPercent in every program I do. You just may never know just how close to the edge your running if you don't use this.
Example....
Code: Select all
#define STACK_SIZE_xtask1 2048
#define STACK_SIZE_xtask2 4096
TaskHandle_t TaskHandle_xtask1;
TaskHandle_t TaskHandle_xtask2;
//********************************************************************
//
// ********************************************************************
void xtask1(void * parameter)
{
uint32_t x = 0;
for (;;)
{
printf("xtask1 Running: %u\r\n", x++);
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}
//********************************************************************
//
// ********************************************************************
void xtask2(void * parameter)
{
uint32_t x = 0;
for (;;)
{
printf("xtask2 Running: %u\r\n", x++);
vTaskDelay(125 / portTICK_PERIOD_MS);
}
}
/* -----------------------------------------------------------------------------
GetTaskHighWaterMarkPercent( TaskHandle_t task_handle, uint32_t stack_allotment )
Input Params:
- task_handle: The task handle name
- stack_allotment: How much stack space did you allocate to it when you created it
Returns: float with the % of stacke used
Example: printf("Stack Used %04.1f%%\r\n", GetTaskHighWaterMarkPercent(xTask1, 2048) );
Notes:
-----------------------------------------------------------------------------*/
float GetTaskHighWaterMarkPercent( TaskHandle_t task_handle, uint32_t stack_allotment )
{
UBaseType_t uxHighWaterMark;
uint32_t diff;
float result;
uxHighWaterMark = uxTaskGetStackHighWaterMark( task_handle );
diff = stack_allotment - uxHighWaterMark;
result = ( (float)diff / (float)stack_allotment ) * 100.0;
return result;
}
//
//
//
void app_main()
{
xTaskCreate(xTask1, "xTask1", STACK_SIZE_xtask1, NULL, 5, &TaskHandle_xtask1);
xTaskCreate(xTask2, "xTask2", STACK_SIZE_xtask2, NULL, 4, &TaskHandle_xtask2);
while(1)
{
TickType_t xTime1 = xTaskGetTickCount();
uint8_t temp1 = (uint8_t)GetTaskHighWaterMarkPercent(TaskHandle_xtask1, STACK_SIZE_xtask1);
uint8_t temp2 = (uint8_t)GetTaskHighWaterMarkPercent(TaskHandle_xtask2, STACK_SIZE_xtask2);
printf("\r\n************************************************\r\n");
printf("Tick: %06.1f\r\n", (float)xTime1 / 100.00);
printf("xTask1: %03u%%\r\n", temp1);
printf("xTask2: %03u%%\r\n", temp1);
if(temp1 > 90)
{
printf("!!! WARNING xTask1 Stack Useage to HIGH !!!\r\n");
}
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}