Stack Memory
JoeFL
Posts: 10
I'm writing my first Spin program and have a couple of questions.
1. When starting multiple Cogs, how can I be sure I'm allocating enough Stack space for each Cog?
2. Is sharing global variables between Cogs as easy are declaring Global variables in Cog_0
then just reading them in other Cogs, such as
Cog_0
Var long Cnt_Total
repeat
various code
Cog_1
dira[3]~~
repeat
if Cnt_Total == 5
outa[3]~~
else
outa[3]~
Cog_2
repeat
waitcnt(clkfreq/10 + cnt)
Cnt_Total++
If Cnt_Total == 10
Cnt_Total := 0
1. When starting multiple Cogs, how can I be sure I'm allocating enough Stack space for each Cog?
2. Is sharing global variables between Cogs as easy are declaring Global variables in Cog_0
then just reading them in other Cogs, such as
Cog_0
Var long Cnt_Total
repeat
various code
Cog_1
dira[3]~~
repeat
if Cnt_Total == 5
outa[3]~~
else
outa[3]~
Cog_2
repeat
waitcnt(clkfreq/10 + cnt)
Cnt_Total++
If Cnt_Total == 10
Cnt_Total := 0
Comments
http://obex.parallax.com/objects/25/
2) If the cogs' code is all in one object (usually the main one), global variables are accessible from any cog. You do have to be careful about simultaneous access from more than one cog though. You're generally safe using a variable if you're modifying it only in one cog. If you've got an array or some group of variables that are related, you may get into trouble depending on the details of what you're doing. Some cases of this are ok like a circular buffer with an input pointer and an output pointer where one pointer is changed by one cog and the other pointer is changed by another cog. For other cases, you may need to allow only one cog at a time to access the variables using the LOCKxxx statements (see the Propeller Manual for details and examples).