Correct way to share data between cogs
I've been studying the reference manual and I am trying to determine how cogs can share data. It seems to me that passing the address to a method running in a separate cog is one way.
Is it the best and/or only way?
Thanks!
Is it the best and/or only way?
Thanks!
VAR
long stack[10]
long cval
OBJ
Debug : "Extended_FDSerial.spin"
PUB LaunchCogs | cognum
Debug.start(31, 30, 0, 57600) ' ignore tx echo on rx
waitcnt(clkfreq * 3 + cnt) ' Pause for FullDuplexSerial.spin to initialize
Debug.tx(16) 'cls
cognum := cognew(Sensor([COLOR=red]@cval[/COLOR]), @stack)
repeat 50
Debug.Dec(cval)
Debug.tx(13)
waitcnt(clkfreq / 2 + cnt)
PUB Sensor([COLOR=red]cvaladdr[/COLOR]) | sval
sval := 0
repeat 100
sval++
LONG[[COLOR=red]cvaladdr[/COLOR]] := sval
waitcnt(clkfreq/2 + cnt)

Comments
VAR long myvariable, mystack[20] PUB main cognew(other,@mystack) waitcnt(clkfreq/10 + cnt) ' wait for cog to start Debug.dec(myvariable) PRI other repeat myvariable := ina[3..0] ' update every 100ms waitcnt(clkfreq/10 + cnt)What if the second cog is in another object?
This way you only have to pass one pointer.
I had a version using multiple cogs and an array where I was using the cogid to index into the array.
I am creating various examples for future reference...
Thanks again.
Dirkimus,
you might find this helpful:
You can change what you've already posted by clicking on the Edit button at the bottom of that above post and then insert the code tags, if you so desire.
In some detail and the experts are chiming in.
You may find it interesting.
Harprit.