coginit vs cognew
Alexander (Sandy) Hapgood
Posts: 360
Is there a reason to call coginit rather than cognew? That was a question asked in another thread about some PASM code that someone was having problems with. Rather than hijacking that thread I thought I would start a new one since the coginit vs cognew subject has come up before and there's potential for discussion.
Coginit is the only way I've found to have PASM code running in all 8 cogs.
You have to load cog 0 last or you'll overwrite the spin code that's starting the cogs.
I remember other threads where people were advised that it wasn't possible to run PASM in all eight cogs since there had to be some spin code to kick the whole thing off. That's true but it can be replaced when it has completed it's task.
Coginit also gives you more control over what goes where so you can reassign cogs to other tasks on the fly. I can't think of a scenario where that would be necessary but I'm sure that someone will be able to think of something.
Sandy
Coginit is the only way I've found to have PASM code running in all 8 cogs.
coginit(7, @PASM, pParameters7) coginit(6, @PASM, pParameters6) coginit(5, @PASM, pParameters5) coginit(4, @PASM, pParameters4) coginit(3, @PASM, pParameters3) coginit(2, @PASM, pParameters2) coginit(1, @PASM, pParameters1) coginit(0, @PASM, pParameters0)
You have to load cog 0 last or you'll overwrite the spin code that's starting the cogs.
I remember other threads where people were advised that it wasn't possible to run PASM in all eight cogs since there had to be some spin code to kick the whole thing off. That's true but it can be replaced when it has completed it's task.
Coginit also gives you more control over what goes where so you can reassign cogs to other tasks on the fly. I can't think of a scenario where that would be necessary but I'm sure that someone will be able to think of something.
Sandy
Comments
Currently I have a project going that uses PASM for everything except display. Once I get the whole thing finished I'll write a PASM LCD driver to replace the current spin driver. Why? Because I can. I think.
Back in the early 1980s I remember writing very simple programs on my Apple II using just hex codes. The programs didn't do much but what they did do they did really fast. I found the whole process fascinating.
Besides, if you use Spin you have to fiddle around and calculate the amount of stack space required.
Sandy
In general a piece of Spin code that intends to replace itself with a PASM program in the same COG should find out which COG it is running on (COGID) and use that ID to load the PASM into with COGINT.
Sandy