Simple, I think, question re start method in a referenced object
jstjohnz
Posts: 91
Is there any need to use this form:
As opposed to this form:
The first method declares it's own local copy of the parameter passed by spin, assigns the passed parameter to it, then uses this local copy in the COGNEW directive. Is this necessary or beneficial in any way, or is it OK to just pass the parameter in COGNEW as in the 2nd example?
VAR long _acme long cog PUB Start(acme) : okay _acme:=acme 'value to pass to ASM in PAR okay := cog := cognew(@entry, @_acme) + 1 'Start driver in new cog
As opposed to this form:
VAR long cog PUB Start(acme) : okay okay := cog := cognew(@entry, @acme) + 1 'Start driver in new cog
The first method declares it's own local copy of the parameter passed by spin, assigns the passed parameter to it, then uses this local copy in the COGNEW directive. Is this necessary or beneficial in any way, or is it OK to just pass the parameter in COGNEW as in the 2nd example?
Comments
In the first example the passed value is copied to a global variable whose extent is not limited to the function call (extent is the time window in which a variable is defined)
The second form would work if he ensured that the new cog was done using the stack variable "acme". He could either use a waitcnt after the cognew, or he could have the cog put a different value in acme, such as a zero,and wait for it to change before exiting the start method.
OK, somehow I put the @ signs in there, they weren't intended. I'm just trying to pass, in PAR, a pointer to a data structure in hub ram so that the PASM code can access that hubram data. And I'm trying to figure out if there's a need to create a local copy of the parameter (the pointer) that's passed to the start method before using cognew.
So my question should have been this:
First form with a local copy of the passed param (which is a pointer):
or 2nd form:
As I understand it now, either approach should work. However I'm not clear on your statement "If other functions in the same object need access to the parameter block then a copy needs to be made".
Say, for example, in the same object as the Start function you have other functions which update the COG driver parameter block. Then either the calling function would need to pass in the pointer or the object would need to keep a local copy.