FreeRTOS How to query the remaining stack space of a task

Source: Internet
Author: User


1. The official document provides functions to query the remaining stack space of the task, first of all to look at the Official document interpretation (the official document of a great god translator. )

parameter explanation: Xtask: The handle of the queried task--for information on how to get the task handle, see the parameter pxcreatedtask of the API function Xtaskcreate (). If a NULL handle is passed in, the task queries the high watermark of its own stack space.

return Value: The actual usage of the task stack space floats up and down as the task executes and the interrupt process progresses. Uxtaskgetstackhighwatermark () returns the minimum amount of stack space that is left in the run history from which the task started execution. This value is the remaining unused stack space when the stack space is used to reach the deepest. The closer the value is to 0, the more the task is not far from the stack overflow.

Here's how I'm going to use it:

You first need to add a task handle when creating a task:

The specific methods are:

1, Xtaskhandle pvcreatedtask_toggleled4; This code is defined as a null pointer variable. (typedef void * XTASKHANDLE;)

2,xtaskcreate (TOGGLELED4, (int8_t *) "LED4", Configminimal_stack_size, NULL, Led_task_prio,pvcreatedtask_ ToggleLed4); Create a task

3, to use Uxtaskgetstackhighwatermark This function, first of all have to look at the following description:

* Include_uxtaskgetstackhighwatermark must is set to 1 in FreeRTOSConfig.h for
* This function is available.

In the FreeRTOSConfig.h file to change the macro definition of Include_uxtaskgetstackhighwatermark to 1, can not be changed, modify the properties of the document, read-only remove!

4,///The following is the task I want to query the remaining stack space, which called Uxtaskgetstackhighwatermark this function

void ToggleLed4 (void * pvparameters)
{
unsigned portbase_type Uxhighwatermark;
for (;;)
{
/* Toggle LED4 each 250MS */
Stm_eval_ledtoggle (LED4);
Uxhighwatermark=uxtaskgetstackhighwatermark (PVCREATEDTASK_TOGGLELED4);
printf ("ToggleLed4 remaining stack space is what:%d.\r\n", Uxhighwatermark);//gxp, serial detection, November 17, 2015 11:26:42
Vtaskdelay (500);
}
}

5. Look at the results:

6. Analysis:

1, the "74" here, should be 74*4=296 bytes (1 bytes = 8 bits).

2, according to the data returned to judge, the task is still remaining 296 bytes are not used, resulting in waste, so in the setting of the stack space to reduce the setting!            

FreeRTOS How to query the remaining stack space of a task

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.