Shop OBEX P1 Docs P2 Docs Learn Events
what about calls from a cog — Parallax Forums

what about calls from a cog

ChuckTChuckT Posts: 12
edited 2008-12-22 23:41 in Propeller 1
If inside a cog I call a method from another object where does it execute? Inside the cog that called it. but without the local variable support? is this correct?

I think if the cog is called from an object then it has access to the variables from the parent obj.
But if a cog calls outside its parent object then how can the called method know its local variables.

I cant get my driver to work when it is called from another cog. do I need to supply it with all its local variables.

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-12-22 23:08
    The phrase that helps me is: spin lives in the hub. If it's in spin, an object has access to local variables regardless of which cog it is being executed in. An object is not necessarily directly related to a cog. You can have multiple cogs for one object, or multiple objects for a single cog.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-22 23:41
    If you have a method (routine) executing in a cog and that method calls another method whether it's in the same object or another object, the same cog is what executes the new method.

    One object does not have access to the variables of another object no matter what cog is executing.· You can pass the address of a variable or block of variables from one object to another and that second object can access the variables indirectly.· Again, it doesn't matter what cog is running.

    You run into two issues when more than one cog is executing your code:

    1) Each cog has its own special registers (OUTA, DIRA, PHSA, FRQA, CTRA, etc.)· This is particularly an issue when one cog sets up an I/O pin as an output, but another cog tries to set the output state (high or low) without initializing the DIRA bit.

    2) If two cogs attempt to change a variable, they might do it at essentially the same time even though the actual write operation is managed by the hub logic so there's no conflict.· One cog might copy the value to the stack and modify it before writing it back and the 2nd cog could change the value between the copy and the write.

    If you want specific suggestions for your driver, you'll have to post it as an attachment, otherwise all we can make are general suggestions.
Sign In or Register to comment.