View Full Version : explaination of PUB end

07-12-2009, 02:48 AM
I know it is probably pretty simple, but could someone explain how PUB end works exactly?
I'm having a hard time with
if cog
cogstop (cog ~ -1)

I'm probably reading too much into it

Mike Green
07-12-2009, 02:58 AM
What do you mean by PUB end?

You posted a pretty typical bit of code to stop an I/O driver's cog where the cog # + 1 is kept in a variable called cog. Read the description of COGNEW and COGSTOP and read the description of the unary post-fix "~" operator which is used to zero the variable cog after its value is used for the expression.

07-12-2009, 06:00 AM
This was out of the propeller fundementals lab book in an example using a start and a stop method. I didn't want to go any further until I knew exactly what it meant. Is the -1 just to keep the value in cog non - zero?

07-12-2009, 06:54 AM
Normally a PUB start will have cog := cognew(@PASM, @Parameters) + 1.
The cognew method can return 0 to 7, so 1 is added there. Then in PUB stop, one will only cogstop if cog is non-zero.
If cogstop(cog~ -1) is run, then the cog identifier or cognew return +1 from PUB start is used to stop the cog and the ~ will set cog back to zero.


Propalyzer: Propeller PC Logic Analyzer (http://www.brouhaha.com/~sdenson/Propalyzer)
http://forums.parallax.com/showthread.php?p=788230 (http://forums.parallax.com/showthread.php?p=788230)

Mike Green
07-12-2009, 06:55 AM
The start method adds one to the value returned by COGNEW/COGINIT so a cog start failure returns zero and success returns a value > 0. The stop method subtracts one to yield the actual cog number. Read the description of COGSTOP and COGNEW.

07-12-2009, 08:31 AM
Thanks for the help. The post-clear was what was throwing me off. It sets cog back to zero after the operation.