Shop OBEX P1 Docs P2 Docs Learn Events
Passing Parms to Cogs — Parallax Forums

Passing Parms to Cogs

bdickensbdickens Posts: 110
edited 2007-10-22 17:58 in Propeller 1
Ok; I'm obviously missing the point on something. How do you pass a parameter from one cog to another ? I see some examples, but they seemed to be running it through a communication path. I was looking to have my controller cog request (and receive) a value from my sensor cog.

If the question is painfully stupid, point me at the article. I'm writing the code prior to getting the board so all this is a theoretical process so far.

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-22 17:50
    Since the cogs are independent processors, the only way they can communicate is via a shared resource and the only ones available are HUB memory and the I/O pins. Usually the I/O pins are tied up doing other things, so common variables in HUB memory are what is used.

    If the parameter is an initial value only, it can be passed using the COGNEW/COGINIT call (see the manual). If you're using an assembly routine, you can store the value in the assembled code before it gets copied to the cog's memory using the COGNEW/COGINIT. If it's not just an initial value, it depends on whether your routine is written in assembly or in Spin. In Spin, you just reference the same variable(s) from the two (or more) cogs. In assembly, you generally pass the address of a common area in main (HUB) memory to the assembly routine and the assembly routine uses RDLONG/WRLONG and their variants to access the value(s). Check out some of the I/O drivers in the Propeller Object Exchange. Many of them deal with this issue. Look at the Propeller Education Lab tutorials (see the "sticky" thread on these at the top of this forum's thread list).

    If you have complex information to communicate back and forth, you will need to look at the LOCKxxx instructions in the Propeller Manual. These are needed if two different cogs access the same variables at the same time. In special cases, like sharing a common buffer with one cog putting things in and the other taking things out, you probably don't need to use these (LOCKxxx), but, in most other cases, you will need to use them. See the manual for examples of their use.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-10-22 17:58
    Install the propeller tool and read a couple of the basic programs. I recommend keyboard.spin to see information being set up and keyboard_demo.spin to see information being used. Of particular interest in the later is this "sentence": term.hex(kb.getkey,3)

    Once you figure how that works, you will be well along the way.
Sign In or Register to comment.