communication via 2 cogs or more with PASM
robbyd
Posts: 6
hello, im beginner and have read the
http://forums.parallax.com/showthread.php?139410-How-can-I-share-data-in-between-cogs-in-PASM/page3&highlight=pass+variable
but I don´t understand this crank things at all.
Its too much specific to me.
I want to share one variable or more defined in boot.spin to a.spin and b.spin in PASM.
a.spin should read something, calc and writeback
b.spin do the same ...
a short example:
boot.spin
var
' Shared between a and b
long sync
long data
pub start xy
sync:=101;
a.start(2,@sync)
b.start(3,@sync)
dat
the next is the a.spin and b.spin object
con
pub start(cogNumber,parameterBlock)
coginit(cogNumber,@entry,parameterBlock)
dat
org
entry
mov t1,par
rdlong sync,t1
add t1,#4
rdlong data,t1
' Stupid but only 4 a test
' counting up
loop: mov vari,data
add vari,#1
mov data,vari
jmp loop
sync long 0 '
data long 0 '
vari long 0
when I do similar , I get values passed by boot.spin one time ,
but the variable will allways the same, when reading from outside ! (maybe they change only locally but I have no debugger to see whats going )
How can I do this correct ?
Wbr
http://forums.parallax.com/showthread.php?139410-How-can-I-share-data-in-between-cogs-in-PASM/page3&highlight=pass+variable
but I don´t understand this crank things at all.
Its too much specific to me.
I want to share one variable or more defined in boot.spin to a.spin and b.spin in PASM.
a.spin should read something, calc and writeback
b.spin do the same ...
a short example:
boot.spin
var
' Shared between a and b
long sync
long data
pub start xy
sync:=101;
a.start(2,@sync)
b.start(3,@sync)
dat
the next is the a.spin and b.spin object
con
pub start(cogNumber,parameterBlock)
coginit(cogNumber,@entry,parameterBlock)
dat
org
entry
mov t1,par
rdlong sync,t1
add t1,#4
rdlong data,t1
' Stupid but only 4 a test
' counting up
loop: mov vari,data
add vari,#1
mov data,vari
jmp loop
sync long 0 '
data long 0 '
vari long 0
when I do similar , I get values passed by boot.spin one time ,
but the variable will allways the same, when reading from outside ! (maybe they change only locally but I have no debugger to see whats going )
How can I do this correct ?
Wbr
Comments
So, in your example, you need to start the cog by..
coginit(@entry,@sync)
... and in the cog ...
entry rdlong csync,par
... add csync,#1
... wrlong csync,par
csync long 0
Note the way rdlong and wrlong dest is the data and srce is the hub pointer!!!
Note we normally do not define which cogs are used.
This should get you started. Then come back here with further questions. Btw, use the code tags to list code, or post the file/s in the advanced section.
If you'll post a simple version of your code, I will make it so that the variables are shared so that you can see it working and then go back and figure out how it is working.