beginner: pasm how to share variables between 2 cogs
robbyd
Posts: 6
Could somebody explain how to share variables/data between 2 cogs. The examples in the forum are too long and to specific. I learned how to create a List of longs in the boot.spin and pass the start of the list with par to one cog but I get only the starting values to the cog but no refresh. the values are static to cog 2 but cog 1 rewrite the (wrlong) all the time. How are the correct programming model ? Kind regards Robby
Comments
If cog 1 writes a value to the hub, cog 2 wont know it has changed unless it reads from the same location (in hub RAM).
To give you a general idea (this is going to seem complicated and will take a while to wrap your brain around), you need to obtain the memory address of the variable that the 1st cog is writing to. Once you get the address (not variable name) you then store that address in a variable and pass it to an initialization function for the object with the 2nd cog. Then you copy the address into a local variable for that specific cog/object. After you've stored it locally to that object, you can then read it into a PASM variable that is local to that object and at that point you have the address stored into a variable in PASM that you can use with rdlong or wrlong.
Kuroneko taught me how to do this, so if you post your code as he has requested, I'm sure he'll give you a specific example with your own code.