Calculate Stack Space?
James Long
Posts: 1,181
Ok....so I seached the forums.....what is the proper way to calculate the stack for a new cog?
I may have not seached right....so if there is a previous thread....just point me to the right thread.
I'm learning....I promise.
James L
I may have not seached right....so if there is a previous thread....just point me to the right thread.
I'm learning....I promise.
James L
Comments
Any call on a method (function or procedure) requires a long for the return address information. This may include the pointer to the previous stack frame or that may take a second long. Chip will have to chime in here on that. A long for the return value is always allocated. If the called method declares local variables, each one will take an additional long. If the called method has any parameters, a long for each will be allocated in the caller's stack frame. Expressions use the stack for evaluation, so they may cause the use of additional levels of the stack.
Without public documentation on the SPIN interpretive byte code, it's difficult to determine exactly how much stack is needed for any given program. Start with figuring out how deep the deepest call will go and add up the space needed for parameters, local variables, and return address information for that call chain. Add 8-16 levels for expression evaluation and you should have a pretty good lower bound. At least there are no interrupts to non-deterministically require more.
Since you answered that question so well.....I have another for you to instruct me on.
Take a look at max_1270.spin and inform me about the following routine.
pub get_count(control_bit, average_sample, ADC_count_address) | temp, adresult_temp
I get the control_bit (the information to start conversion) and the average_sample (the number of samples to average)
The ADC_count_address has me stumped.
Maybe it been too long since I did any programming with the stamps....wow I'm really rusty.
James L
That's an easy one. The get_count routine is intended to run continuously in its own cog. Such routines cannot return a value directly, so they have to communicate through common memory locations. Rather than have a specific variable built into the source of the MAX1270 object, the author provided for the user to pass the address of a variable instead. Say you have a variable declared "long FOOBAH". You would write "start(???, ???, @FOOBAH)" with the appropriate "XXX." in front and the "???" replaced by whatever you need. The new cog would be started and you would shortly find the ADC averaged value in FOOBAH and it would be continuously updated as new average values were acquired.
Mike
Some languages allow you to pass a variable to a subroutine as a variable, "by reference", or "by value". The first is almost like a macro. Where the parameter name appears, the variable in all its complexity of subscripts, pointers, etc. functionally appears. This form isn't used much any more so you can forget it. "by reference" means that the address of a variable is passed. This location can then be referenced or modified by the subroutine. "by value" means that the actual current value of the variable is passed. There's no way to change the source of the value (the variable) in this type. SPIN uses "by value" always. It allows you to pass the address of a variable "by value" which allows you to effectively have "by reference" parameters so you can change things in the caller's variables.
Post Edited (Mike Green) : 9/16/2006 3:20:46 AM GMT
It confused me...I was expecting the @ symbol.
is the @ symbol required?· By this example it is not.
James
BTW you are going to teach me alot. Thanks Mike.
This would start up a cog with get_count with a 0-10V range, internal reference, no power down, averaging 8 readings each cycle. The result would appear periodically in myData and there's no "@" in the call to MAX1270.start
So the @ is only for getting the address of the variable. Is it required?
Better yet....when is the @ required?
I tried something last night.....just put something together for a max 1202....I have included it here.....for you guys to tell me what I'm doing wrong.
Hey be easy.....it was late....and I'm somewhat confused at this point.
James
Is there any instance that (other than maybe Stack) that the "@" MUST be used?
I hope I got that right.....
James L