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

Stack used for function calls

Posted by dev on January 27, 2013
As I know every task get assigned some stack(configured by user) from heap.
Does function call from a task uses the same stack which has been assigned to particular stack ? (Yes, Got from same website while browsing through other questions)
also what about nested function ? (Yes , assumption)
Can you please give some pointer(Book, threads) to know more about memory allocation for function calls?

RE: Stack used for function calls

Posted by MEdwards on January 27, 2013
How memory is allocated in functions has nothing to do with FreeRTOS, and everything to do with your compiler. If you want to learn about this stuff you would find the answers in a C book not an RTOS book.

If you declare a local non static (does not use the static key word) variable inside a function then the compiler will wither allocate space for the variable on the stack or just hold the variable in a register. In most cases it will be on the stack if the compiler optimization is low, and in a register if the optimization is high. In both cases every task that calls the function will get a different copy of the variable and the function is said to be re-entrant.

If you put the word static in front of the variable declaration then the variable will instead be held in a global data pool just like global and file local variables. In this case every task that calls the function will use the same variable, and the function is said to not be re-entrant.

RE: Stack used for function calls

Posted by dev on January 27, 2013
I am a novice never worked on RTOS , please bear with me
Please clarify below doubt
Task#1 - Has been allocated with Stack#1 from configTOTAL_HEAP_SIZE
Task#2 - Has been allocated with Stack#2 from configTOTAL_HEAP_SIZE

If task#1 has called a function#1 (the called function#1 may call another function#2) , the local variables of function#1 and function#2 will be placed in which stack ? Stack#1 ? or some FreeRTOS uses some global stacks to be used for these things.

RE: Stack used for function calls

Posted by Richard Damon on January 27, 2013
Tasks are no different than any other function in your program (including main). When one function calls another, they use the same stack, so if the function that implements task#1 calls function#1, that function (for this call) will use the stack space from task#1. If the function that implements task#2 calls the same function, then for that call, it will use task#2 stack.

There are some ports that will move the Interrupt stack to a different space, so that you do not need to reserve space for the interrupts in every task, but that is something different.

RE: Stack used for function calls

Posted by dev on January 28, 2013
Thanks, now i got clear picture


[ 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