Shop OBEX P1 Docs P2 Docs Learn Events
Best way to Communicate between cogs? — Parallax Forums

Best way to Communicate between cogs?

SpinHeadSpinHead Posts: 28
edited 2008-06-10 03:09 in Propeller 1
Ok, I think I understand exactly how to do this ( I am more of a hardware guy than software so bear with me.) from the main Cog I am going to define an object, Input, inside of Input is a start method that starts a method in a new cog loop that watches a variable defined in the dat area, I also have a Read method in Input that responds with the first byte of the variable Is this the best way to do this? This is my first time writing a new cog object instead of just logic inside the main cog.

Also, how would I return the first byte in an array and shift everything else over, i.e. nibble the data

Thanks!
·

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-10 03:09
    A method I have used, is the following. Define an object. In the object define an array and a flag in the DAT section. Define a start method that sets the flag to 0. A read method that waits until the flag is 1 and copys data from the array to a array passed as a parameter. A write method waits until the flag is 0, copys from an array parameter to the array
    Declare the object in 2 objects in are running in different cogs that want to communicate. 1 object calls read and the other calls write.
    Since the array is in DAT, there is 1 array shared between the 2 instances of the object. The read waits until a write is called and a write waits until any data in the array is read before writing.

    Edit: the attachment is a quick hack to show what I mean. It is hacked from existing code but probably has bugs sinces its untested in this form. You can extend it to double buffer, pass different size buffers, etc.

    Post Edited (Timmoore) : 6/10/2008 3:35:02 AM GMT
Sign In or Register to comment.