Can a COG stop itself?
Basil
Posts: 380
Hi All
The subject pretty much says everything.
Provided there is no infinite loop in the COG, will it automatically stop once it has done whatever the object it was loaded with was meant to do?
(By stop, I mean become available to start again with COGNEW.)
Also, can I call COGSTOP(x) from COG x?
Thanks All!
The subject pretty much says everything.
Provided there is no infinite loop in the COG, will it automatically stop once it has done whatever the object it was loaded with was meant to do?
(By stop, I mean become available to start again with COGNEW.)
Also, can I call COGSTOP(x) from COG x?
Thanks All!
Comments
To stop a cog from within assembly use:
The rest is pretty stright forward.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007
Cogid := Cogid
COGSTOP(Cogid)??
cogstop(cogid) does work fine.
Thanks guys.
Well, I can do better than that: My example was 3 lines, with a bug in every line!!! cogid was an amazingly poor choice of variable name.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007
oh and check out pc linux if you want to know what a good os is supposed to look like. sorry, this is an unrelated post.. shame on me..
at least with the single line cogstop(cogid) your really lowering the lines of code and keeping it simple. i did also try to set cogid to a variable at first. Im not sure why but it dose seem like the first thing that comes t mind even though its over complicating things.
Ands it funny the build in features in anticipation of bugs...Windows Update?
Anywho, back on subject
Ok so thats an easy answer to that question.
And the other one? If a cog run's out of things to do (i.e its not stuck ina loop or waiting for something) does it stop.
Does the stack space become available again and the cog ready to be used when COGNEW is called?
Or does it wait to be COGSTOP'd?
That being the case, when the cog stops, either through a cogstop(cogid) or via the implicit stop, the 'stack' is NOT cleared -- is that right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.co.uk
You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
BTW: I type as I'm thinking, so please don't take any offense at my writing style
Of course the two functions AllowAmazingStuffToHappenForSomeTime and DoAmazingStuff have not been defined here, but their definition shouldn't be too hard.
So, the stack is NOT cleared, but that doesn't matter, because it hasn't been consumed or anything, and is available for further use in other functions.
Which leaves only the question you haven't asked:
How much space should you set aside for the stack?
The answer depends a bit on how complex your cog function is. There's a stack size helper object in the Object Exchange. Of course if the cog you start is an assembly cog, then you don't need a stack at all.
Any questions?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007
Just thinking about getting a prop so I am lurking...
Where is the program counter pushed for called subroutines and interrupts in assembly language if there is no stack?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
The destination field specifies a location where the program counter is to be stored in the source part of the location.
If the destination location is a JMP instruction, that acts as the return. The CALL / RET "macros" work that way with
the RET actually being a JMP instruction and the label for the RET being made from the CALL operand followed by "_ret".
I suggest you stop lurking and get yourself a Protoboard. You could also download GEAR and the Propeller Tool and try out
some simple programs with GEAR's simulator.