Thanks for the suggestion. I probably should elaborate what I am trying to do.
I have created a Thread that simply goes through all my registered tasks and prints the high water mark in a percentage.
So durring run time I can see how close I am getting to the edge if you will.
To do this I need to pass the task handle and its stack allotment. I'd like to avoid passing the stack allotment size to me "GetTaskHighWaterMarkPercent" function, and have it somehow find out what that task was created with.
Code: Select all
UBaseType_t GetTaskHighWaterMark( TaskHandle_t task_handle )
{
UBaseType_t uxHighWaterMark;
uxHighWaterMark = uxTaskGetStackHighWaterMark( task_handle );
return uxHighWaterMark;
}
/* -----------------------------------------------------------------------------
GetTaskHighWaterMarkPercent( TaskHandle_t task_handle, uint32_t stack_allotment )
Input Params:
- task_handle: The task name you want to examine
- 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;
}
// Spin up the Task
xTaskCreate(heartBeatTask, "heartbeat_task", 1024, NULL, 1, &TaskHandle_heartBeatTask);
// Where is the Stack at ?
float temp1 = GetTaskHighWaterMarkPercent(TaskHandle_heartBeatTask, 1024);
printf(" %04.1f%%\r\n",temp1);