Stack Length Calculations for Cogs
JoeFL
Posts: 10
I've viewed the stack length demo spn code and I seem to understand it.
But, my program calls 4 methods in 4 different cogs from the top method.
Question: Can the stack length demo code be applied to determine my code's optimum
stack length for each cog?
Pub Main
coginit(2, Method1, @stack[100])
coginit(3, Method2, @stack[200])
coginit(4, Method3, @stack[300])
coginit(5, Method4, @stack[400])
pgm code
Pub Method1
pgm code
Pub Method2
pgm code
Pub Method3
pgm code
Pub Method4
pgm code
But, my program calls 4 methods in 4 different cogs from the top method.
Question: Can the stack length demo code be applied to determine my code's optimum
stack length for each cog?
Pub Main
coginit(2, Method1, @stack[100])
coginit(3, Method2, @stack[200])
coginit(4, Method3, @stack[300])
coginit(5, Method4, @stack[400])
pgm code
Pub Method1
pgm code
Pub Method2
pgm code
Pub Method3
pgm code
Pub Method4
pgm code
Comments
You did not give us the whole code, so it's maybe OK, but on the first glance it looks like there could be some misunderstandings:
The range of COG-IDs is 0-7. Usually your main is started in COG 0. So, in your coginits you could go ahead with 1-4.
BUT: In general you should not use COGINIT without a damn good reason! In nearly all cases it is better to use COGNEW!
I don't know how you defined stack, but your code looks odd to me in regards of stack usage.
The main does not need any room in your stack-array, because it is using the whole remaining HUB-RAM as stack-space (The whole memory marked as free when you hit F8 in the propeller tool).
So, in the first coginit you can start Method1 with @stack[0]. Giving each method a stack with 100 longs, the size for the stack-array would be stack[400]. Please remember, the SPIN language has a stack which grows buttom-up and not top-down as in many other systems.
it does look a little strange. In my top method I do call another method which handles some serial communication which uses about 50 longs in the stack, thus the reason cog2 starts using the stack @ 100, Because the serial communication is utilized in cog1, thus the reason my method1 starts in cog2. If I'm not enabling and/or disabling cogs, why are you saying its wrong to use coginit ? Thanks
Especially if you want to put code into the Object-Exchange it's an absolute NOGO to have fixed COG-numbers in this object.
You can enclose it in [code] tags from advance edit and it will be scroolable, or you can attach it as a zip. Its easier to fix when we can look at it.