Shop OBEX P1 Docs P2 Docs Learn Events
beginner: pasm how to share variables between 2 cogs — Parallax Forums

beginner: pasm how to share variables between 2 cogs

robbydrobbyd Posts: 6
edited 2012-05-08 19:01 in Propeller 1
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

  • kuronekokuroneko Posts: 3,623
    edited 2012-05-08 16:51
    Please attach your code so we can get an idea as to where the problem is.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-08 16:52
    Both PASM cogs need to know the location of hub RAM where they wish to share variables.

    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).
  • turbosupraturbosupra Posts: 1,088
    edited 2012-05-08 19:01
    I think you were trying to use my example before? http://forums.parallax.com/showthread.php?139410-How-can-I-share-data-in-between-cogs-in-PASM

    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.
Sign In or Register to comment.