Launch PASM into Cog 0 running SPIN interpreter
escher
Posts: 138
I don't have my equipment with me so I can't test this on my own, and searching forums/datasheet/manual haven't answered this:
Is is possible to launch PASM in Cog 0 which is loaded with the SPIN interpreter on startup? e.g.:
Or can you actually just call coginit from the Cog 0 SPIN interpreter, and the process of copying the instructions from hub RAM to overwrite the interpreter won't actually interrupt it?
I see in the API this statement for coginit:
That appears to answer my question, but then how would one start a SPIN interpreter cog from a PASM cog?
Thanks!
Is is possible to launch PASM in Cog 0 which is loaded with the SPIN interpreter on startup? e.g.:
coginit newcog ' Address to PAR Code address New CogID ' |---------------|--------------|-|---| newcog long %XXXXXXXXXXXXXX_XXXXXXXXXXXXXX_1_000
Or can you actually just call coginit from the Cog 0 SPIN interpreter, and the process of copying the instructions from hub RAM to overwrite the interpreter won't actually interrupt it?
I see in the API this statement for coginit:
Since COGINIT operates on a specific cog, as directed by the CogID parameter, it can be used to stop and restart an active cog in one step. This includes the current cog; i.e., a cog can use COGINIT to stop and restart itself to run, perhaps, completely different code.
That appears to answer my question, but then how would one start a SPIN interpreter cog from a PASM cog?
Thanks!
Comments
Given that the Spin interpreter code is in the ROM it must be possible to start it running using COGINIT.
Sorry I don't know the address of the Spin interpreter code. Somebody here will know it. Somehow one will have to pass the address of the Spin code it should run as well.
Andy
Is that really correct? It looks like there is 2 bits of overlap.
I think so, It's written like that to show the real addresses. The $0004 goes into PAR and the two lowest bits of this address must always be zero.
If you look at the booter PASM code you will see how to launch spin directly.
thanks,
Jonathan
Your Alley-oop is quite graceful
Interesting technique; I'm attempting it now. How did you calculate the "80 extra bytes" needed?
thanks,
Jonathan
http://forums.parallax.com/discussion/comment/1359516/#Comment_1359516
It's possible to have PASM running in all 8 cogs if you use coginit and load cog 0 last.
No need to load COG 0 last. One could imagine that 0 starts 1, 1 restarts 0, ... 1 starts 2.... Or whatever scheme you like.
With the slight complication I guess that if you want to start 8 cogs running PASM from a Spin object you had better know which COG is running that Spin object so that you kill of the right COG to run that 8th PASM part. And such like scenarios.
One could assume the Spin is always COG 0 but that might be a bit iffy sometimes.
I guess I assumed that calling coginit on yourself would result in a race condition... because there has to be some code running somewhere which transfers your targeted PASM code to overwrite the interpreter, and I assume that code has to be running via the interpreter itself.