Load Same Code into All Cogs
Humanoido
Posts: 5,770
I need to load the same code into all cogs, at the same time if possible. Is there a simple coginit extension to specify the initialization and loading of all cogs 0 through 7?
Humanoido
Humanoido
Comments
No there isn't. Besides, the load-from-hub magic is tied to the hub window anyway so you don't gain anything compared to running 8 coginitA commands in sequence (assuming PASM).
A make that 7 cognew's and one coginit mumblesorrymumblephilmumble
Humanoido
Humanoido
That is something I had not realized before and could probably save a lot of debugging time one day. Generally it is not a problem as the code that is being loaded to COG sits around in memory permanently anyway. BUT if you start a COGINIT/NEW and then assume it is done when it returns you are going to get into a mess if you want to immediately recycle the COG code memory space for something else.
Humanoido: I think it's the other way around:
1) Let's say you have a loader starting in COG 0 at start up.
2) The loader starts up some chunk of code on seven other COGs with COGNEW.
3) The loader starts that same chunk of code on COG 0 using COGINIT specifying 0 as the COG. Thus replacing the running loader with the chunk.
4) Now you have 8 COGs all running the same chunk of code.
Now you should not assume that the loader is running on COG 0 in step 3). But that's OK a COG knows it's own ID from COGID. So use that instead.
I have done something similar in the ZOG loader (run_zog.spin) where it starts an instance of the ZOG interpreter in the COG that is running the loader. In this way ZOG takes over the COG from the loader and poof, there is no more Spin running in the Prop anywhere.
The loader in run_zog.spin is written PASM as it moves things around in memory prior to starting ZOG which might trample on any Spin code. But I guess in your case you can do it from Spin.
Each of the seven COGNEWs starts a COG on some method in your Spin object.
When they are up just call the same method. BINGO all COG's are running the same method.
I seem to remember that there is an example of this in the Propeller manual.
You didn't specify whether you use SPIN or PASM but in SPIN you want something like this
and PASM (untested)
Humanoido