Shop OBEX P1 Docs P2 Docs Learn Events
All 8 cogs at once — Parallax Forums

All 8 cogs at once

alienmindsincalienmindsinc Posts: 2
edited 2009-07-15 17:57 in Propeller 1
Good afternoon, guys,

I've been searching the net all morning, but I can't find any examples of how to call assembly code from an already running cog.

Basically, I'm running all of the cogs at once, and 7 of the 8 start just fine, but the 8th already contains the code to run the other 7, and after it starts the other 7 I would like it to run the same code as the other 7.

The code looks like:

OBJ
 
  wait    : "gpl"        ' The wait cycle object
 
PUB start

  
  'start each cog
  wait.start(0,1,10,0, PW)          ' delay is set per link location
  wait.start(2,3,15,1,PW)                                         
  wait.start(4,5,5,2,PW)
  wait.start(6,7,100,3,PW)
  wait.start(8,9,100,4,PW)
  wait.start(10,11,100,5,PW)
  wait.start(12,13,100,6,PW)

DAT                                 {{ ASM Code to do the delay circuit }} 
                        org  0                                                                                        
entry
                        or dira, out            ' Set the correct output pin

---------- lots more code--------

This is just the main part of the code that I'm running. What it does is each "wait" object runs a PWM/delay setup to remove the comm link propagation delay of our entire rig.

What I would like to do is call the entry routine·after cog 6 starts, or just switch the current cog to the routine all of the others are running. What I've tried is stopping·the current cog, and restarting,·coginit, and creating a new cog. Nothing seems to work, and there doesn't seem to be a documented way to use spin·code and then jump to assembly code.

So, what am I missing here?

Thanks,
-M
·

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2009-07-15 17:20
    Have another call in the object that does everything .start() does, EXCEPT a start - something like:


    PUB run(arg1,..,argN)
    ' do stuf

    PUB start(arg1,...,argN)
    cognew(@run,@args)


    Then in the calling object:

    wait.start(cog1...)
    ...
    wait.start(cog6...)
    wait.run(....) <-- your initial cog runs the code



    alienmindsinc said...
    Good afternoon, guys,


    I've been searching the net all morning, but I can't find any examples of how to call assembly code from an already running cog.



    Basically, I'm running all of the cogs at once, and 7 of the 8 start just fine, but the 8th already contains the code to run the other 7, and after it starts the other 7 I would like it to run the same code as the other 7.



    The code looks like:




    OBJ
     
      wait    : "gpl"        ' The wait cycle object
     
    PUB start 
    [noparse][[/noparse]code]  
      'start each cog
      wait.start(0,1,10,0, PW)          ' delay is set per link location
      wait.start(2,3,15,1,PW)                                         
      wait.start(4,5,5,2,PW)
      wait.start(6,7,100,3,PW)
      wait.start(8,9,100,4,PW)
      wait.start(10,11,100,5,PW)
      wait.start(12,13,100,6,PW)
    [noparse][[/noparse]code]DAT                                 {{ ASM Code to do the delay circuit }} 
                            org  0                                                                                        
    entry
                            or dira, out            ' Set the correct output pin
    [noparse][[/noparse]code]---------- lots more code--------
    


    This is just the main part of the code that I'm running. What it does is each "wait" object runs a PWM/delay setup to remove the comm link propagation delay of our entire rig.



    What I would like to do is call the entry routine after cog 6 starts, or just switch the current cog to the routine all of the others are running. What I've tried is stopping the current cog, and restarting, coginit, and creating a new cog. Nothing seems to work, and there doesn't seem to be a documented way to use spin code and then jump to assembly code.



    So, what am I missing here?



    Thanks,

    -M
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com - my site 6.250MHz custom Crystals for running Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
    Morpheus & Mem+ Advanced dual Propeller SBC with XMM and 256 Color VGA
    Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
  • KyeKye Posts: 2,200
    edited 2009-07-15 17:22
    Um, you don't need to stop the cog.

    If your launching all the other cogs through spin, then its most likely that cog zero is doing this.

    You just need to call cogint on cog zero with the asm code it should load.

    The cog then will reload itself with the new asm code. You don't need to stop the cog however.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • alienmindsincalienmindsinc Posts: 2
    edited 2009-07-15 17:48
    I have no clue why, but for SnG, I uncommented the line I had in with the CogInit, and it worked just fine. No other changes to the code were made.

    Thanks for taking the time to reply!
    -M
  • ericballericball Posts: 774
    edited 2009-07-15 17:57
    alienmindsinc said...

    I've been searching the net all morning, but I can't find any examples of how to call assembly code from an already running cog.

    Basically, I'm running all of the cogs at once, and 7 of the 8 start just fine, but the 8th already contains the code to run the other 7, and after it starts the other 7 I would like it to run the same code as the other 7.

    What I would like to do is call the entry routine·after cog 6 starts, or just switch the current cog to the routine all of the others are running. What I've tried is stopping·the current cog, and restarting,·coginit, and creating a new cog. Nothing seems to work, and there doesn't seem to be a documented way to use spin·code and then jump to assembly code.
    First, there's no (easy) way for SPIN code to invoke PASM code as a subroutine.· The normal way to do things is for the SPIN code to invoke COGNEW( @cogstart, longptr ) and the PASM code then runs asychronously from the SPIN code.· The SPIN code could wait for the PASM code to set some flag before continuing, but be aware that COGNEW takes ~8000 CLK cycles to load the PASM code into the cog.

    If you want the SPIN code to invoke the PASM code using the same cog (so the SPIN code stops, and the PASM code starts), you'd use COGINIT( COGID, @cogstart, longptr ).· Again, there's a ~8000 CLK delay before the PASM code starts executing.· Note: use COGID rather than assuming cog #0.

    PASM also has a COGINIT instruction (which can also start an unused cog like COGNEW), but it can only start PASM code (and you will need to figure out a way to get the hub addresses).· People have figured out how to kickstart SPIN after reloading HUB RAM (same as the built-in bootloader), but I don't think anyone has figured out how to invoke a SPIN object/method from PASM or return to the SPIN code.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: Forum
    OnePinTVText driver: ObEx Forum
Sign In or Register to comment.