Shop OBEX P1 Docs P2 Docs Learn Events
COG question . . . . calling routines — Parallax Forums

COG question . . . . calling routines

donnpangydonnpangy Posts: 49
edited 2010-11-15 12:14 in Propeller 1
I have a question about different cogs calling up a routine started by a different cog.

I am running the Servo32v7, and am having a strange problem. It is probably just due to my understanding of Cog routines.

This is what I did . . . .

Main program starts with the servo32v7 startup
servo32v7.start
the main routine then calls a different file routine that starts 4 new cogs.

Now . . . . Can these new cogs still call the original servo32v7 routine, with something like this
Servo.set(1,1500)

That command runs from the main routine, but not from the spin code in the addtional 4 cogs.

thanks,
Don

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-11-13 19:19
    donnpangy wrote: »
    Now . . . . Can these new cogs still call the original servo32v7 routine, with something like this
    Servo.set(1,1500)

    I don't see an issue with the call itself (provided the servo object is visible to the method which is running in a different cog). Problem is that e.g. the set method reports dira to the PASM cog (ServoPinDirection := dira). This register is local to each cog so calling set in the context of cog N would effectively void any changes made by previous calls from different cogs.
  • donnpangydonnpangy Posts: 49
    edited 2010-11-14 10:36
    Thanks kuroneko, for your response
    kuroneko wrote: »
    I don't see an issue with the call itself (provided the servo object is visible to the method which is running in a different cog).

    I have the following in the main function and on the extra 5 cogs that were started. Would this be enough allow the servo set call to work?
    OBJ
    SERVO : "Servo32v7.spin"

    kuroneko wrote: »
    Problem is that e.g. the set method reports dira to the PASM cog (ServoPinDirection := dira). This register is local to each cog so calling set in the context of cog N would effectively void any changes made by previous calls from different cogs.

    How do I get past this, so that I can call the set function from a different cog other than the one that called the servo.start function?

    thanks for any help,
    Don
  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-14 10:59
    Servo32v7 would have to be changed to allow calling the Set routine from several different cogs. It could be done relatively easily, but would take some work to make sure it works ok.

    There are two problems. One, Servo32v7 uses DIRA as a place to keep track of which I/O pins are in use for servos. The assembly routine that actually generates the servo pulses has it's own DIRA register since it runs in a different cog and the Set routine communicates with the assembly routine so the assembly routine can update its copy of DIRA. The Set routine uses DIRA for convenience since the individual bits are addressable. There's no inherent reason why the Set routine has to use DIRA, but that's the way it and the SetRamp routines were written.

    The second problem is that, with two cogs potentially calling Set and/or SetRamp, those calls have to have interlocks (LOCKxxx) so the shared variables get set properly. Again, this isn't a huge amount of work, but it's more than changing one or two lines of code.
  • donnpangydonnpangy Posts: 49
    edited 2010-11-15 12:14
    Thanks Mike,

    I will look into changing the DIRA, so that it can be accessed from another cog.

    Thank,
    Don
Sign In or Register to comment.