PDA

View Full Version : All 8 cogs at once



alienmindsinc
07-16-2009, 12:55 AM
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
·

Bill Henning
07-16-2009, 01:20 AM
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
[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)
[code]DAT {{ ASM Code to do the delay circuit }}
org 0
entry
or dira, out ' Set the correct output pin
[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 (http://www.mikronauts.com) - my site 6.250MHz custom Crystals for running Propellers at 100MHz (http://mikronauts.com/products/mikronauts-625mhz-crystal/)
Las (http://mikronauts.com/products/las-largos-lmm-assembler/) - Large model assembler for the Propeller Largos (http://mikronauts.com/products/largos/) - a feature full nano operating system for the Propeller
Morpheus & Mem+ (http://mikronauts.com/products/morpheus/) 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

Kye
07-16-2009, 01:22 AM
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,

alienmindsinc
07-16-2009, 01:48 AM
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

ericball
07-16-2009, 01:57 AM
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 (http://forums.parallax.com/showthread.php?p=800114)
NTSC & PAL driver templates: Forum (http://forums.parallax.com/showthread.php?p=803904)
OnePinTVText driver: ObEx (http://obex.parallax.com/objects/480/) Forum (http://forums.parallax.com/showthread.php?p=822453)