Prepackaged Cogs
M.Earnshaw
Posts: 6
Hi all,
I was just wondering if its possible to write a dedicated object in spin/asm, store it in eeprom, and load it in and initialise a cog with it on demand, with access to the variables already in hub?
If all the individual cog 'images' have identical opening sections (Con, Obj, Var), with the variables layed out identically, would this allow it?
In theory, the way I see it, as long as the hub variables are placed in the same place then a cog image would just write to the variable.
E.g.
Each cog image has the same opening section: (Semi-Pseudo code)
This is run on Cog 0.
Object B is created, using the same header, but this time reads from b, subtracts 10, and then writes to a. This object is stored in eeprom.
The Hub ram is then blanked after the variables onwards.
If Cog 1 is then loaded with Object B from eeprom, will the 2 cogs be able to communicate even though they are 2 seperate objects?
I think thats the best way I can explain it, its been driving me mad for the past day trying to figure out if its possible. The theory sounds fine to me in principle, but I might be missing something.
I was just wondering if its possible to write a dedicated object in spin/asm, store it in eeprom, and load it in and initialise a cog with it on demand, with access to the variables already in hub?
If all the individual cog 'images' have identical opening sections (Con, Obj, Var), with the variables layed out identically, would this allow it?
In theory, the way I see it, as long as the hub variables are placed in the same place then a cog image would just write to the variable.
E.g.
Each cog image has the same opening section: (Semi-Pseudo code)
Con (Some constants) Obj Object 1 Object 2 Var Long a, b, c Word d, e, f Byte g, h, iObject A is then created using the above header, that reads from a, adds 10, and writes it to b.
This is run on Cog 0.
Object B is created, using the same header, but this time reads from b, subtracts 10, and then writes to a. This object is stored in eeprom.
The Hub ram is then blanked after the variables onwards.
If Cog 1 is then loaded with Object B from eeprom, will the 2 cogs be able to communicate even though they are 2 seperate objects?
I think thats the best way I can explain it, its been driving me mad for the past day trying to figure out if its possible. The theory sounds fine to me in principle, but I might be missing something.
Comments
Assembly code is a different issue. This is initially placed in hub memory, then transferred to a cog by the COGINIT/COGNEW instruction which takes about 100us to execute completely. Once the code is copied to the cog, the area where the code was stored is no longer needed. The COGINIT/COGNEW instruction can pass the address of a hub variable area to the new cog and this can be different for each cog that's started.
Seeing as how all the cogs will have the same variables in the exact same order, and the compiler always placing vars in the order: Long, Word Byte, that it might be possible.
Cheers for the help.