Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner