COG question . . . . calling routines
donnpangy
Posts: 49
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
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
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.
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"
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
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.
I will look into changing the DIRA, so that it can be accessed from another cog.
Thank,
Don