Page 1 of 1

Static arrays in tasks

PostPosted: Thu Nov 06, 2008 4:24 am
by Meista
I have a strange problem with arrays in salvo tasks.

The salvo manuals cleary says that if information should be stored during a context switch, the variables must be defined as static.
On the other hand if the value is not needed, it doesn't have to be static.

In my application I have to handle large character arrays (e.g. 150 bytes) in the tasks. If I define them as static everything works fine. But if they are not static, the msp430 has very strange behavior if the array size is bigger than 125 bytes(resets or locks during operation etc.)

I am using the MSP430 F1611 with the CrossStudio 1.4 and Salvo 4 pro.

Has anyone an idea?

Re: Static arrays in tasks

PostPosted: Thu Nov 06, 2008 6:26 am
by aek
You're probably overflowing the stack, or the declaration is really giving you a 125-_word_-size array, which violates Salvo's spec for the MSP430 (see the Salvo compiler reference manual RM-RA430.PDF).

One thing to keep in mind is that you ultimately are using the same maximum amount of RAM whether you declare this large array as static or as an auto variable, assuming there is no other auto variable usage that's bigger.

If static, it's obviously always present. If auto, it's present only when the task runs, but it still pushes the SP down by the size of the array, and you need to write for / test for proper operation when the stack is that large.

So, overall, it doesn't make much difference in terms of how much RAM it costs you, so it's not much of a "penalty" to keep it static.


[This message has been edited by aek (edited November 06, 2008).]

Re: Static arrays in tasks

PostPosted: Thu Nov 06, 2008 6:39 am
by aek
Just to be clear -- a 125-_word_-size array in a Salvo task with CW430 as th compiler yields 250 bytes of auto variables. The limit (see RM-RA430.PDF) is 255, so if you task had another 6 bytes of auto variables, you would see problems.

IOW, Salvo maintains an 8-bit local stack frame pointer with RA430.


Re: Static arrays in tasks

PostPosted: Thu Nov 06, 2008 6:51 am
by aek
Note also that compilers also may use a function's local stack space when performing certain operations, thereby further enlarging the function's stack frame, unbeknownst to the user.