Shop OBEX P1 Docs P2 Docs Learn Events
cogstop — Parallax Forums

cogstop

agfaagfa Posts: 295
edited 2008-08-03 04:18 in Propeller 1
i'm trying to use cogstop to stop a cog that is running an·infinite loop.··is that not possible·?

Comments

  • AleAle Posts: 2,363
    edited 2008-08-01 20:13
    sure it is, be sure to pass the right cogid...
  • agfaagfa Posts: 295
    edited 2008-08-01 20:41
    i believe i am.

    the cog will stop if its in a finite loop, but not in an infinite loop.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-01 20:57
    The cog will stop no matter what it's doing. The hardware for the cog gets turned off by the hub, the cog stops executing instructions and drops into a low power state.
  • agfaagfa Posts: 295
    edited 2008-08-01 21:02
    thats what i thought. i must have a problem with the way im using cogstop or cogid.
  • jazzedjazzed Posts: 11,803
    edited 2008-08-01 21:07
    Well, you could try re-starting the cog (after stopping it) if you believe stopping it is not working.
    I accidently used "stop" as a "variable" once when it was clearly define as a method to stop a my cog.
    That worked very well at stopping my pasm and causing me a great debug headache for a time [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-08-01 22:48
    Since·the cog is in an inifinite loop, I am assuming you are trying to shut down a cog externally. Cogid returns the cog number where executed, since this is external, it will not return the value you are looking for. The best way to get the cogid of cog that you want to stop is to grab the return value of cognew, it will be the cogid of the cog which was started up with the process pointed to in cognew. You can then use this number to stop the process at a later time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • scanlimescanlime Posts: 106
    edited 2008-08-02 00:37
    agfa said...
    i believe i am.

    the cog will stop if its in a finite loop, but not in an infinite loop.

    Does this mean the Propeller's hub controller can solve the halting problem? [noparse];)[/noparse]

    --Micah
  • agfaagfa Posts: 295
    edited 2008-08-02 01:46
    i wasn't thinking, of course the finite loop will stop.·

    still can't see what i'm doing wrong that i can't stop the cog in an infinite loop.

    jazzed, i don't understand·how restarting a cog that hasn't stopped will tell anything.

    paul, that is my intention. probably a syntax or indention problem.· i'll keep looking.
  • jazzedjazzed Posts: 11,803
    edited 2008-08-02 01:52
    >> jazzed, i don't understand how restarting a cog that hasn't stopped will tell anything.
    Only that you can regain control. You can use coginit to restart a cog without using cogstop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • agfaagfa Posts: 295
    edited 2008-08-02 02:08
    yes.· coginit instead of cogstop stopped it.· thanks.· now to see where control was lost.
  • jazzedjazzed Posts: 11,803
    edited 2008-08-02 03:18
    Hmm ... something doesn't sound right. Maybe it's time to post some code for peer review.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-02 04:15
    Yeah, I agree. If COGINIT stopped it, but not COGSTOP, somesing's feeshy!

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • agfaagfa Posts: 295
    edited 2008-08-02 12:51
    "feeshy" eh!

    not to sure about proper use of coginit
  • hippyhippy Posts: 1,981
    edited 2008-08-02 13:26
      cognew(drive,@stack)
      cog := cogid
    
    



    Shouldn't that be ...

      cog := cognew(drive,@stack)
    
    



    Otherwise you're getting the CogId of the one which launched 'drive' not CogId of 'drive'.
  • jazzedjazzed Posts: 11,803
    edited 2008-08-02 18:03
    Clearly, Hippy has highlighted your problem.

    You might consider looking at some of the library objects as examples to emulate.
    Here is a very simple flasher that uses start/stop following the library example.

    {{
    Very simple COG LED flasher object
    }}
    VAR
      long cog
      long stack[noparse][[/noparse]8]
     
    PUB main
      repeat
        waitcnt(clkfreq+cnt)
        stop    
        waitcnt(clkfreq+cnt)
        start
        
    PUB start
    {{
    Start the LED flashing
    }}
      stop ' many objects stop first to save the user trouble
      result := cog := cognew(flash(1),@stack) + 1
      waitcnt(clkfreq/10+cnt)
     
    PUB stop
    {{
    Stop the cog
    }}
      if cog
        cogstop(cog~ - 1)
     
    PRI flash(bit)
    {
    Flash LED at bit number about 10x/second
    }
      dira[noparse][[/noparse]bit]~~ ' ensure set to output by new cog
      repeat
        !outa[noparse][[/noparse]bit]
        waitcnt(clkfreq/10+cnt)
    
     
    



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • agfaagfa Posts: 295
    edited 2008-08-03 04:18
    thanks for all the help
Sign In or Register to comment.