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

Can usTaskCheckFreeStackSpace() be right?

Posted by JohnnyBosc on October 21, 2008
I'm a tad confused abt. the usTaskCheckFreeStackSpace() function in task.c. Allow me to quote it in full (sry 'bout that) from the provided source code:

unsigned portSHORT usTaskCheckFreeStackSpace( const unsigned portCHAR * pucStackByte )
{
register unsigned portSHORT usCount = 0;

while( *pucStackByte == tskSTACK_FILL_BYTE )
{
pucStackByte -= portSTACK_GROWTH;
usCount++;
}

usCount /= sizeof( portSTACK_TYPE );

return usCount;
}


Now, on a PIC32 MCU portSTACK_GROWTH is = -4, i.e. every iteration in the while() loop will increase the tested address by 4 -- looks very much like we're counting 32-bit integers, doesn't it?

However, on exiting the while() loop the count of 32-bit integers in usCount is divided by sizeof(portSTACK_TYPE)!

In the PIC32 port, sizeof(portSTACK_TYPE) is = 4. In other words, I end up with a stack high water mark that is 4 TIMES TOO SMALL. This is borne out by setting a breakpoint in usTaskCheckFreeStackSpace() and just doing a memory dump of the memory being scanned.

Am I missing something really silly here, or is this a bona fide bug?

RE: Can usTaskCheckFreeStackSpace() be right?

Posted by Richard on October 21, 2008
Yes it 'was' a bug. It got fixed in the SVN copy a few days ago but is not yet in the download.

Apologies for any inconvenience caused.

Regards.

RE: Can usTaskCheckFreeStackSpace() be right?

Posted by JohnnyBosc on October 21, 2008
Thanks for the practically instantaneous answer.

Now, if I'd only bothered to read grahamfclark's post from just a couple of days ago...

RE: Can usTaskCheckFreeStackSpace() be right?

Posted by JohnnyBosc on October 21, 2008
Richard,

While you're at it can you confirm (or dis-) that the various forms of the macro taskCHECK_FOR_STACK_OVERFLOW() in task.c will in fact detect a stack *underflow* when portSTACK_GROWTH > 0? Granted, not that I know about a whole lot of CPU:s where the stack grows "upwards".

RE: Can usTaskCheckFreeStackSpace() be right?

Posted by Richard on October 21, 2008
As per your original question - the current SVN version handles cases where the stack grows up from low memory (portSTACK_GROWTH > 0), but the current release version doesn't.

The SVN repository is public (read only).

Regards.


[ 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