Page 1 of 1

function parameter limits for msp430

PostPosted: Thu Apr 03, 2008 8:48 am
by Dave Hohl
The MSP430 Reference Manual says that there is a limit of 255 8-bit values for auto variables and function parameters in tasks.

Is that the total per task, or total for all tasks?

Does it include all locals and function parameters in the calling tree, or only the top level task code?

Can you give me a brief explanation of why the restriction exists, so I have a better understanding of what is going on?


David Hohl

Re: function parameter limits for msp430

PostPosted: Thu Apr 03, 2008 10:57 am
by aek
The restriction is per task, and only at the task level (i.e. any underlying / called functions can have as many auto variables as they like).

This is a side-effect of Salvo's not requiring task stacks. Without a task stack, there's nowhere for Salvo to save and later restore auto variables at task level (i.e. auto variables declared inside a task). But a local stack frame must be synthesized for each Salvo task (this is one of the functions of the Salvo context switcher) because users can still declare and use auto variables in a task ... but auto variables do not persist across context switches (because there is no task stack).

The 8-bit limit is because of the internals of the Salvo context switcher and its need to store stack frame information in each task's tcb. A byte-sized field was chosen for this, as it is sufficient for nearly all applications.

Keep in mind that static auto variables in a Salvo task do _not_ require more RAM than (persistent) auto variables in a task of a more conventional RTOS. In the former, the variables are static (with scope under the programmer's control) in RAM, and in the other, they are stored in the tasks's stack, which is also in RAM somewhere. So the net RAM requirements as regards variables at the task level are the same.

Similarly, any auto variables in called functions are treated identically for Salvo and other RTOSes (they're unloaded from the stack as the function returns).

The main difference as regards RAM utilization is that in a conventional RTOS, the ability to block / context-switch at any level requires deep per-task call stacks, to temporarily save all those auto variables to RAM while the task is blocked. On something like the MSP430, this can add up rapidly to large blocks of RAM being allocated to task stacks. With Salvo, if you can code your application (and this is usually the case) to only context-switch at the task level -- and make any deeper non-blocking function calls you like -- then you get an immediate and substantial savings in RAM required, as each Salvo task uses a total of around 10-14 bytes (depends on configuration) of RAM. We routinely see customers running 10-20 or more tasks on even the "smaller" MSP430 parts like the '149/'169.


[This message has been edited by aek (edited April 03, 2008).]

Re: function parameter limits for msp430

PostPosted: Thu Apr 03, 2008 11:04 am
by Dave Hohl
Thanks for the quick feedback. As a long-time user of pre-emptive RTOSes I certainly appreciate the advantages that Salvo offers in applications with limited RAM resources. My question about the reason for the limit was just out of curiosity. I think I understand what is going on now.

Re: function parameter limits for msp430

PostPosted: Thu Apr 03, 2008 11:07 am
by aek
You're welcome.