Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

How to see upper/lower bound of a task's stack?

Posted by awillson on January 15, 2016

Hello, I am working on a RAM test routine that needs to skip the current RTOS task's stack. How can I retrieve the current task's upper/lower stack boundary? Thanks!


How to see upper/lower bound of a task's stack?

Posted by rtel on January 15, 2016

This is not easy at the moment, although we are already working on a function that will extend the uxTaskGetSystemState() function to return stack boundaries too (and to allow it to be called on a task by task basis) - plus the current head revision allows task stacks to be allocated statically so you always know where they are.

In the mean time, assuming you are using an architecture for which the stack grows down, you can obtain the limit of the stack by adding the following function to the tasks.c. You pass in a task handle, or NULL if you are querying the stack limit of the calling task. The stack size will be known as it was a parameter passed into the function that created the stack (in words, not bytes!).

~~~~ StackTypet *pxTaskGetStackStart( TaskHandlet xTask ) { TCB_t *pxTCB;

/* If null is passed in here then it is the stack of the calling task that
is being queried. */
pxTCB = prvGetTCBFromHandle( xTask );
return ( pxTCB->pxStack );

} ~~~~


How to see upper/lower bound of a task's stack?

Posted by awillson on January 15, 2016

Hello RTE. I'm getting a hardfault on the return() statement. Are you sure this pointer is dereferenced correctly?

Also, the handle which I pass to this GetStackStart() function, is the handle which is returned to me by xTaskCreate() - correct?

vBISTSRAM1_Task_handle = xTaskCreate(vBISTSRAM1_Task, 
    (const char *) "vTaskBISTSRAM1",
	configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
	(xTaskHandle *) NULL);

...
		SRAM_BIST_Test(pxTaskGetStackStart(vBISTSRAM1_Task_handle), configMINIMAL_STACK_SIZE);

Thanks for your assistance.


How to see upper/lower bound of a task's stack?

Posted by rtel on January 16, 2016

I didn't actually try running the code, just typed it into the post, but it looks ok. I suspect your problem is to to the following comments -

Also, the handle which I pass to this GetStackStart() function, is the handle which is returned to me by xTaskCreate() - correct?

No! Please read the documentation for the xTaskCreate() API function - the handle is passed out using the last parameter. The return value is simply a pass/fail indication, not a pointer.

http://www.freertos.org/a00125.html


How to see upper/lower bound of a task's stack?

Posted by awillson on January 18, 2016

Thanks for your help. I mis-read the xTaskCreate() definition, sorry about that. The code you provided is working fine, and all is well now.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists