more than 15 parameters to pass to a cog?
I need to pass more than 15 parameters to a cog. Can this be done?
Cog.start (_ff, _Tf, _X0, _X1, _Y0, _Y1, _Vr2, _aR1, _aR2, _Pb1, _Pb2, _Pb3, _Ab1, _Ab2, _Ab3,_kb1, _kb2, _kb3, _max, _min, _all)
Comments
pub start(_ff, _Tf, _X0, _X1, _Y0, _Y1, _Vr2, _aR1, _aR2, _Pb1, _Pb2, _Pb3, _Ab1, _Ab2, _Ab3,_kb1, _kb2, _kb3, _max, _min, _all) cognew(@pasm, @_ff) dat pasm org 0 ' ...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propeller Tools
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
VAR long _ff, _Tf, _X0, _X1, _Y0, _Y1, _Vr2, _aR1, _aR2, _Pb1, _Pb2, _Pb3, _Ab1, _Ab2, _Ab3, _kb1 long _kb2, _kb3, _max, _min, _all PUB mainMethod cog.start(@_ff)
PUB start(address) cognew(@pasm,address) DAT org 0 pasm: mov temp,PAR ' Hub address of parameters movd move,#table ' Cog address of copy of parameters mov count,#21 ' Number of parameters move: rdlong 0-0,temp ' Read one parameter add move,destIncr ' Increment destination address add temp,#4 ' Increment source address djnz count,#move ' Repeat for all parameters ' Here we continue with other code ... destIncr long $200 ' Add one to destination field count res 1 temp res 1 table res 21
You can also copy the parameters in the Spin start method like:
PUB start(address) longmove(@table,address,21) cognew(@pasm,0) DAT org 0 ' Here we continue with other code ... table long 0[noparse][[/noparse]21] ' Allocate space for a copy of all the parameters ' You can't use RES here because the table has to occupy hub space (so it can be copied)
Post Edited (Mike Green) : 8/25/2009 7:24:42 PM GMT
Either way you go, it will be painful though ... unless your interface parameters lose weight [noparse]:)[/noparse]
You could use a generic buffer instead and provide methods to do get/set on the parameters.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propeller Tools
Bad, bad, bad, no, no, no!
You are passing the long address of a set of parameters on the stack. By the time the cog has loaded the spin routine will have returned and possibly damaged the stack contents. Don't do this.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lt's not particularly silly, is it?
But I'd be much more inclined just to do a longmove from @_ff to a parallel area in the DAT section before doing the cognew.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 8/26/2009 1:40:15 AM GMT
I usually add a delay after cognew or poll for the cog to finish in my code to make sure the cog loads before i try to use it. For example, even doing the RightThing(tm) as in FullDuplexSerial and not waiting for it to load before calling fd.str(string("Hello")) pretty much guarantees output failure. Shrug shoulders [noparse]:)[/noparse]
So, Is Python really named after Monty Python?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propeller Tools