Shop OBEX P1 Docs P2 Docs Learn Events
end program — Parallax Forums

end program

guili_23guili_23 Posts: 11
edited 2010-08-13 13:26 in Propeller 1
Hi all,

I ´m new using the propeller chip and while I was learning who to use spin languages a doubt poped up. Is it a way to finish the main program in the middle of the running ? (for example because of a FALSE condition). And if it is so, what should I take in consideration to finish in a proper way ?

Thanks in advance.

BR !

Comments

  • T ChapT Chap Posts: 4,223
    edited 2010-08-10 19:41
    Hello guili

    When you say "end' the program, what exactly do you want the program to do upon a condition? There are a number of ways to stop what the program is doing, including shutting down the cog or restarting the Prop, or getting out of a repeat loop with : ABORT, QUIT, RETURN. You can see examples if each of these in the Propeller manual.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-08-10 20:05
    Or just go into a repeat loop if you want your outa pins to retain their state.

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-10 20:22
    Or just go into a repeat loop if you want your outa pins to retain their state.

    I thought that's what you use clkset(2, 0) for (SCNR).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-08-10 20:41
    That might not be dependable if XI is floating.

    -Phil
  • unixoidunixoid Posts: 17
    edited 2010-08-10 20:46
    Assuming the program runs on a single cog, cogstop(cogid) will stop it.
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-10 20:47
    That might not be dependable if XI is floating.

    It's the official suspend mode used in the boot loader when external sources have been exhausted. Besides, OSCENA is disabled so XI is not relevant at this point.

    Anyway, sorry for this OT discussion.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-08-10 22:02
    kuroneko,

    That's a new one on me! Where is it documented? My Prop manual shows a clkmode of 2 being equivalent to XINPUT.

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-10 22:13
    That's a new one on me! Where is it documented? My Prop manual shows a clkmode of 2 being equivalent to XINPUT.
    Mine too with a side note saying OSCENA must be '1' (so with %0000_0010 it's '0' meaning the circuitry is disabled). And in the ROM boot code we find this:
    mov     smode,#$02              'stop clock
    clkset  smode                   '(suspend until reset)
    
    That's official enough for me ;) Sorry, should have been more clear on the nature of official.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-08-10 22:22
    'Official enough for me, too. Thanks!

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-10 22:53
    So what do we have so far:
    1. revoke I/O assignments
      • single cog
        - cogstop(cogid)
        - Note that exiting the main method (first PUBlic method) in the top object will also stop the corresponding cog. The same is true for an uncaught abort.
      • multiple cogs
        ID := cogid - 7
        repeat 8           ' repeat count optional
          cogstop(ID++)    ' cogstop only looks at the bottom 3 bits
        
    2. keep outputs alive but stop execution (all active cogs)
      - clkset(%0000_0010, 0)
    3. reset (and re-boot) chip
      - clkset(%1000_0000, 0)
    As well as combinations of the above (e.g. shutdown selected cogs then enter suspend mode).

    Note, if you have drivers active which need to be shutdown properly then use the appropriate methods. Just forcing them to shutdown may lead to data loss.
  • guili_23guili_23 Posts: 11
    edited 2010-08-11 10:07
    So, Can I do something like this ?

    PUB Main
    ...
    if <condition>
    Program_finish
    ...
    <more code>
    ...

    PUB Program_finish
    clkset(%0000_0010, 0)
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-11 16:57
    guili_23 wrote: »
    So, Can I do something like this ?
    PUB Main
    ...     
         if <condition>
              Program_finish
    ...
    <more code>
    ...
    
    PUB Program_finish
         clkset(%0000_0010, 0)
    

    Sure, just be aware that all outputs stay outputs in this case.
  • guili_23guili_23 Posts: 11
    edited 2010-08-13 13:26
    ok, thank you very much !!! :)
Sign In or Register to comment.