Shop OBEX P1 Docs P2 Docs Learn Events
How to restart cog zero? — Parallax Forums

How to restart cog zero?

william chanwilliam chan Posts: 1,326
edited 2008-09-16 00:08 in Propeller 1
It seems that COGINIT needs a method and a stack address.
But COG zero (1st COG) does not need a starting method or a stack address.

So how to coginit the first cog?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-15 15:39
    Cog zero does need a starting method and a stack address. If you're asking how things get started initially, there's an assembly language routine in ROM that handles downloading. The reset hardware forces a COGINIT instruction with the proper register contents to start this routine. After downloading a program from either a PC or from EEPROM, the download routine in ROM executes a COGINIT instruction that replaces itself with the Spin interpreter with the starting method address and stack address furnished by the bootloader (from the downloaded program).
  • william chanwilliam chan Posts: 1,326
    edited 2008-09-15 15:50
    Hi Mike,

    My watchdog cog is cog number 2.
    So how does the watchdog cog restart cog zero if it detects a problem?

    Should it be

    
    coginit(0,@main,0)
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-15 16:15
    William,

    If you've created a watchdog and need to restart your main program, the best way to do that is to reset the chip. Ohterwise, your main program will create additional running copies of your watchdog and other cogs that it starts via COGNEW. (You do use COGNEW, don't you, and not COGINIT?)

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!

    Post Edited (Phil Pilgrim (PhiPi)) : 9/15/2008 8:19:32 PM GMT
  • hippyhippy Posts: 1,981
    edited 2008-09-15 19:12
    There's the REBOOT command and it's also possible to just restart Cog 0 using ( I think ) ...

    CogInit( 0, $F004, $0004 )

    You'd have to design for this likelihood as stack space used could be different the second time round depending on what program paths are taken, variables won't be reset to zero, and cogs which are continuing to run will be using whatever space they had.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-15 20:24
    As Hippy states, use REBOOT if your watchdog is written in Spin. Otherwise, the following assembly code will reset the chip:

            clkset  reeboot
            ...
    reeboot long    $80
    
    
    


    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • william chanwilliam chan Posts: 1,326
    edited 2008-09-15 22:56
    Unfortunately the watchdog cog is also the Real Time Clock.
    So if i reboot the whole chip, the date/time is lost.

    Hippy,

    Are you sure the stack location for Cog zero is $0004 ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-15 23:02
    I believe the stack location is stored in $4, so you'd use WORD[noparse][[/noparse] $4 ]
    I think you'd have to get the starting location of the program in the same way from the 1st 16 bytes of memory.
    I don't have the info handy, but there's a description of this header information in one of the threads off Graham
    Stabler's Good Thread Index in the "sticky" threads.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-15 23:15
    William,

    Why not use your main cog as a combination realtime clock, watchdog, and supervisor? That way if you need to restart a cog, you can do it with COGSTOP, and then use COGNEW the same way you launched it to begin with. That would be less awkward than trying to reload a parent cog via one of its offspring. Plus you don't run into the problem of the restarted main cog trying to reload your watchdog/realtime clock.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-15 23:30
    or make the main cog watchdog/rtc and have the supervisor a separate cog, then its easy for the watchdog to stop/start the supervisor.
  • hippyhippy Posts: 1,981
    edited 2008-09-16 00:08
    william chan said...
    Hippy, Are you sure the stack location for Cog zero is $0004 ?

    It's not, but then you are not starting a Spin method which needs a stack, you're starting a PASM routine which is in ROM ( the Spin Interpreter ) which uses the 'program header' parameter block to initialise and run your top-level program.

    The $F004 is the starting address of the Spin Interpreter, $0004-$00F is the parameter block.
Sign In or Register to comment.