Shop OBEX P1 Docs P2 Docs Learn Events
explaination of PUB end — Parallax Forums

explaination of PUB end

ksamksam Posts: 19
edited 2009-07-12 01:31 in Propeller 1
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-11 19:58
    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.
  • ksamksam Posts: 19
    edited 2009-07-11 23:00
    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?
  • jazzedjazzed Posts: 11,803
    edited 2009-07-11 23:54
    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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-11 23:55
    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.
  • ksamksam Posts: 19
    edited 2009-07-12 01:31
    Thanks for the help. The post-clear was what was throwing me off. It sets cog back to zero after the operation.

    Thanks
Sign In or Register to comment.