Shop OBEX P1 Docs P2 Docs Learn Events
Where does a PUB go to die? — Parallax Forums

Where does a PUB go to die?

If a "start" PUB is used to launch a few pasm cogs and nothing else, what does the cog running SPIN do after that? Is there a lower power way to put that cog to sleep, such as by doing an endless waitcnt? Should I actually release that cog? If I release that cog will the registers defined in VAR go away or be corrupted? Guess I'm not even sure how I'd release the boot cog.

Comments

  • JonnyMacJonnyMac Posts: 8,923
    edited 2016-12-31 22:09
    Yes, waitcount does put the cog into low-power mode This is what I do for "sleep."
      repeat
        waitcnt(0)
    

    Generally, you are starting other cogs from Spin which is loaded into cog 0 on boot-up. If you want to start another cog, and then kill the boot cog, you can. Here's a simple little demo. The launched cog is Spin, too, but that doesn't matter; notice how it uses cogstop(0) to kill the boot Spin cog.
    var
    
      long  stack[16]
                                                                
                                                                     
    pub main | t
    
      cognew(blink_27, @stack)
    
      dira[26] := 1
    
      t := cnt
      repeat
        !outa[26]
        waitcnt(t += clkfreq >> 2)                                                                 
    
    
    pub blink_27 | cog0, cycles, t
    
      dira[27] := 1
    
      cog0 := true
      cycles := 0
    
      t := cnt
      repeat
        !outa[27]
        waitcnt(t += clkfreq >> 2)
        if (cog0 == true) and (++cycles => 20)
          cogstop(0)
          cog0 := false
    

    Global vars will not be modified.
  • kwinnkwinn Posts: 8,697
    edited 2016-12-31 22:20
    Shouldn't the cog0 := false statement be before the cogstop(0) statement, or have I missed something?

    EDIT Not that it really matters unless cog0 will be re-used after it finishes.
  • AribaAriba Posts: 2,682
    edited 2016-12-31 22:22
    K2 wrote: »
    If a "start" PUB is used to launch a few pasm cogs and nothing else, what does the cog running SPIN do after that? Is there a lower power way to put that cog to sleep, such as by doing an endless waitcnt? Should I actually release that cog? ...

    The cog stops itself when it reaches the end of the methode, you need nothing special to do for that. More lowpower is not possible.
    If I release that cog will the registers defined in VAR go away or be corrupted?

    The VAR section is allocated in HubRam at compile time. It just stays allocated but is no longer accessed by this cog. Local Vars are on the stack so that memory will be reusable after termination.
    Spin does not use any Cog memory for variables.

    Andy

Sign In or Register to comment.