rtel wrote on Monday, February 07, 2005:
I’m not sure what you mean when you say the compiler calculates this size.
When your application starts (before the scheduler has been started) the stack that is used is that allocated by the compiler/linker. Normally you can influence it’s size using a linker command - or something similar as per your particular compiler.
The size of the stack used by each task is passed as a parameter to sTaskCreate(), so you could use your portCalcStack() function to generate the parameter value.
The only task that is out of the applications control that uses portMINIMAL_STACK_SIZE is the idle task. Normally the idle task does not require much stack so this can be set small. The demo application tasks sometimes use portMINIMAL_STACK_SIZE but this is just for convenience - they could use any appropriate stack size.
One issue for very memory constrained systems is how to recover the memory used by the original - linker assigned - stack. Once the scheduler has started this is not required any more so is wasted RAM [unless you have the scheduler end function implemented, in which case you need a stack to return to. A nice solution to this is to turn your main() function into a task before the scheduler starts and use this in place of one of your application tasks. I have not implemented this as part of the standard kernel as it uses more ROM for the extra functionality, maybe it should be a conditional compilation option?