SPIN Method to detect what cogs are in operation?
cjrussell
Posts: 6
Hey all, first time poster, long time STAMP user. I recently upgraded to the Propeller chip (taking a step away from the BS2px) and was wondering if there's a way in SPIN to detect whether a specific cog is in use? Obviously I could set some variables when I launch a cog to state whether it's alive or not, but was hoping there was some other, more elegant way of doing it. Setting variables can be a pain, especially when using someone else's SPIN code (like the FullDuplexSerial spin in the library). Any thoughts? I looked through the documentation that comes with the editor and couldn't find it, so wasn't sure if such a method even existed.
Comments
Welcome to the Parallax forum!
First, let's examine your motives for wanting to do that. Why do you need to know which cogs are in use, rather than just how many are free?
-Phil
The motive behind the question is more for debugging I guess. I've been launching cogs to do very minor activities (watch a clock line, toggle a PWM, etc). I actually have a use for all 8 cogs at this point in my program I'm throwing together. I come from a more software based background then hardware (the STAMP's are a great way to cross that line!) and generally have to write code in my software to detect when a process has given up the ghost and terminated prematurely. I'm not sure how the Propeller handles a fatal error (if such a condition could exist), or if a cog could 'hang' and deadlock somewhere. So I was hoping to detect when a Cog was no longer functioning.
I guess the problem is that I'm assuming that on a fatal error, the cog just terminates but let's the other cogs continue operation. That would be a condition I'd need to test against. If the entire chip will hang up on a fatal, then it's fairly mute now that I think about it. I have an LCD Display plugged into the chip with one row dedicated to showing which Cogs are operational. Right now when I launch the cog, I just set a bit in a variable saying it's alive. But if it terminates...how would I know? Again, assuming that a cog could terminate prematurely.
Just getting in a little over my head and probably over-thinking this entire thing, but there yah go! Thanks again for the response!
-Cj
BTW, the reason I questioned your motives is that I wanted to make sure you weren't planning to use the information to start new cogs with coginit, cognew being the preferred method in virtually every case.
-Phil
But in the propeller there are no mechanisms to detect this. If you let your PASM code run into a data section, then it will execute whatever instruction will be decoded out of the data.
So, as Phil already said, only your program can stop a COG - either the code in the COG itself stops the COG or another COG stops it.... oh ... ok ... one and only exception is the reset which stops all COGs ;o)
Try that, to see if it returns the correct numbers of cogs being used.
-John