Send object as parameter?
Mflamer
Posts: 2
I am having alot of fun learning spin and this site as been very helpfull. Most of my programming experience is with C#. I am pretty sure the answer to the title of this post is NO. Is the only way to use an object to create another instance of it? I am using the uMFPU3.1 and a pre-written driver from the obex. This driver starts another cog. How can I utilize the FPU from other objects without having to create another instance of the driver? It's hard to get my head around after using C# which allows passing objects, Inheritance ect.. Thanks for any help!
Comments
if you put the variables with which you communicate with the driver into the DAT section you can use it from different cogs
but you have to add a lock/unlock mechanism that dataaccess from different cogs do not collide with each other
There is a serial driver called serial mirror in the object-exchange which does use this technique
doing it that way you pass the pointers of the DAT-variables to each cog
as long as different methods from the SAME objects use the driver you need only one instance
these methods can run on DIFFERENT cogs but have to be in the SAME object.
As the cogs are running completly independent from each other you have to implement
a lock/unlock-mechanism too. You can do this by a long variable
Writing/reading ONE single long is really mutually exclusive as the HUB gives access to the HUB-RAM
for mimimum one ASM-command. This works even in SPIN as the SPIN-interpreter is written in ASM
So FIRST thing to is checking if the lock-variable is in state unlock and then lock it immediatly
and LAST thing is to unlock the lock-variable
Anyway I would do intensivly testing the lock/unlock mechanism
all 8 cogs calling different functions of the FPU-driver at the same time
to make sure that the lock/unlock mechanism works reliable in all situations
best regards
Stefan
I forgot to mention that there are
four lock commands (LOCKNEW, LOCKRET, LOCKSET, and LOCKCLR) used to
manage resources that are user-defined and deemed mutually-exclusive.
see usermanual page 228ff.
best regards
Stefan