Shop OBEX P1 Docs P2 Docs Learn Events
Passing a Hub variable down to cog? — Parallax Forums

Passing a Hub variable down to cog?

SteelSteel Posts: 313
edited 2007-08-07 22:31 in Propeller 1
I have an assembly routine running on a cog.

I would like a value in that routine to be updated by a variable stored in the 'hub' in Spin.

Is this possible?

I want to be able to change the variable in Spin (Increment from 0 to 255), and have the Hub its routine based on the change that was made in the SPIN.

Please let me know.
Thanks
Shaun

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-03 19:58
    Only the assembly code in the cog can change a value in the assembly routine. There is no way for any other cog to access another cog's memory or registers. The only way to do what you want is for the assembly routine in the cog to periodically read the hub memory location and change its behavior as a result of what it reads. Do you know about the PAR register and how it is used to pass information to an assembly program? That's typically how this kind of intercog communication is done. The PAR register is set (using the original COGNEW/COGINIT) to contain a hub address, usually of some initialization information. Included in the same block of data can be some variables that can be changed by other cogs. Your assembly routine just has to use PAR to read that data from hub memory.
  • SteelSteel Posts: 313
    edited 2007-08-07 21:55
    So I am assuming PAR is short for Parameter, which contains the hub 'address' for any SPIN variable...so if I have a variable in Spin, Say "PASS_ME", I can access that value by "MOV X, PAR"....which moves the Address(Value) of "PASS_ME" into my assembly 'X' Variable?

    Sorry if that sounds confusing...but that is the only way I think I can describe it.

    Is it possible to have 2 Parameters?

    Shaun
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-07 22:02
    You're mostly correct however since you are doing hub accessing you need to use rd(long/word/byte) x, par. To access more than one you have them equivalent in size (ie a set of longs, or words or bytes but not a mixture of different types) and declare them next to each other, then use par+offset (in bytes) to accesses the following parameters. So lets say you have the following part in your spin:

    VAR
      LONG firstparam
      LONG secondparam
     
    PUB start
      cognew(@entry, @firstparam)
    

    to read the two parameters, you'd have the following code
    entry   mov ptr, par
            rdlong first, ptr
            add ptr, #4
            rdlong second, ptr
    ...
     
    ptr   long 0
    first long 0
    second long 0
    



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 8/7/2007 10:12:28 PM GMT
  • SteelSteel Posts: 313
    edited 2007-08-07 22:31
    Thank you thank you thank you!!!!
Sign In or Register to comment.