rtel wrote on Monday, August 13, 2007:
> 1) if I want to keep the value of an array between task switch
> that the array will have the same values after task return
> what is the best way to do it
> I am using "static" right now, is it ok?
If the array is declared on the stack then it will automatically have the same value between context switches - but be aware that the stack must be dimensioned to be large enough to hold the array.
If you declare the array static then it will not be on the stack, but will retain its value because it is just a block of memory. Be aware doint this though that the code will not be reentrant. It will only hold its value if no other tasks write to the array.
> 2) I am almost sure that those values are not pushed to the
> stack (array can
> be very big)
> so were exactly they are kept between calls?
Wherever your linker places the array in your RAM. Look at the map generated by the build if you need to know where this is.
> 3) reading examples I found that parameters sent to task use
> memory allocation
Some examples do this, it is not mandatory.
> when does it is exactly needed? way?
> for example telling task to ran with delay of N msec.
> do it need to be used by parameters sending with memory allocation?
You do not need to pass anything in if you don’t need to.
> do I need to use parameters with memory allocation for
> solving question number
> 1 ?
> 4) finally "volatile". on which variables it should be used
> does the array from 1 should be declared as volatile to keep
> its data between
> task switch?
> does all the variables in a task should be volatile?
The array need not be declared volatile unless values in it are going to be changed in a way that is unexpected by the sequential flow of your program - for example, by another task or by an interrupt. This is just the normal use of the volatile qualifier.