Sharng variables in another cog
BTX
Posts: 674
Hi everyone !!
I can't believe it, after so long time using the pchip, Im stucked again with some simple code.
Here's an example of which is my problem now.
Inside the "object code" is the specific question, or, what I can't do now.
I can't explain it easy in English, that's why I post this example to ask you.
Thank you in advance, for your help. !!
This is my main code.
And this is Object code:
I can't believe it, after so long time using the pchip, Im stucked again with some simple code.
Here's an example of which is my problem now.
Inside the "object code" is the specific question, or, what I can't do now.
I can't explain it easy in English, that's why I post this example to ask you.
Thank you in advance, for your help. !!
This is my main code.
''************************************************ ''* Test for the use of variable in other cog. * ''************************************************ '' CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 TEST_LED = 19 'demo board pin OBJ Control : "Control_Test" VAR ' INPUTS byte Input_1 ' byte Input_2 ' ' OUTPUTS byte Out_1 byte Out_2 'Aditional byte Variable_1 byte Variable_2 PUB start ' Starts a new cog with these three variables to share. Control.Start(@Input_1, @Out_1, @Variable_1) ' Inputs Input_1 :=0 Input_2 :=0 ' Outputs Out_1 :=0 Out_2 :=0 ' Aditional Variable_1 :=0 Variable_2 :=0 dira[TEST_LED]~~ ' Demo Board LED outa[TEST_LED]~ ' Checking the state of the Out_2 output, showing in a LED of the demo board. repeat if Out_2 outa[TEST_LED]~~ else outa[TEST_LED]~
And this is Object code:
''************************************ ''* Control Test CODE * ''************************************ ' CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR byte Out_1 byte Out_2 long cog long Stack[60] PUB Start(Inputs, Outputs, Aditional) : Success Stop Success := (Cog := cognew(Control(Inputs, Outputs, Aditional), @Stack) + 1) Out_1 := byte [Outputs][0] Out_2 := byte [Outputs][1] PUB Stop {{Stop toggling process, if any.}} if Cog cogstop(Cog~ - 1) PUB Control(Inputs, Outputs, Aditional) 'This work I know, but I need to control the outputs inside in a PUB or PRI rutine. ' repeat ' byte [Outputs][1] := 1 ' waitcnt(clkfreq/2 +cnt) ' byte [Outputs][1] := 0 ' waitcnt(clkfreq/2 +cnt) ' How to do work this kind of code??? repeat Turn_On waitcnt(clkfreq/2 +cnt) Turn_Off waitcnt(clkfreq/2 +cnt) PUB Turn_On 'byte [Outputs][1] := 1 ' By this way, shows an error Out_2 := 1 ' How to do work this ? PUB Turn_Off 'byte [Outputs][1] := 0 ' By this way, shows an error Out_2 := 0 ' How to do work this ?
Comments
In your start method store the address to these word variables.
Whenever you want to store a byte for the other cog to see, use (for example):
Let me know if I understood well the problem, basically I used "bytes" instead "words" (not in my example code here, but I've tried some similar code as you do above, without luck using "bytes" ....) (I didn't post that code in this question, it's clear)
I suppose that managing inputs, I shlould do it with words instead bytes too ?
Thank you again. !!
Anytime you're storing memory addresses, you'll want to use at least a word sized variable.
One thing that still trips me up is forgetting to only pass the address of a long, using par, when starting a PASM cog.
My code is full working now !!!.