Passing Memory Address, I am stumped!
RS_Jim
Posts: 1,768
I have a program that I want to do that requires several cogs to read a global var while another cog updates that same var. Basicly a timer that is updated by one cog and read by several others. I used Jonny Mac's jm_etimer from OBEX and modified it so that the pasm routine loads the pointers to the timer from the init var I use in coginit.
Var
Long Timer[6]
okay := cog := cognew(@entry,@timer) + 1
DAT org 0
entry mov tmp1,PAR
mov mspntr,tmp1
add tmp1,#4
mov scpntr,tmp1
ETC
That all works Great. However when I attempt to pass the pointer from the top object, it fails.
top obj
VAR
mytimer
OBJ
et: "filename"
Pub Main
et.init(16,@mytimer)
filname
pub init(p,timer) | okay
'' Starts event timer driver
'' -- p is "heartbeat" pin (use -1 to disable)
finalize ' stop if already running
timer[5]:= clkfreq / 1_000 ' cnt ticks per millisecond
' if (p => 0) and (p =< 27) ' if valid pin (protect rx, tx, i2c)
hbmask := 1 << p ' create mask
' enable timer
okay := cog := cognew(@entry,timer) + 1 ' start timer cog
return okay
I did not use @timer because I under stood that in passing @mytimer that I had alread passed a pointer to the hub var mytimer. I modify the top program to just directly display the results of myvar assuming that cog "filename" has correctly written the results into mytimer. I observe two problems, first the heartbeat turns on and stays on and second the results printout in pst are all zeros. I am fairly comfortable in writing PSAM routines (more so than spin) but this global VAR passing has me stumped! I wished in his spin zone article where jonny mac talked about his joysticks where he passed the vars thusly : init:joy (dio,cio,clk,@joysticks) he had shown what the other end looked like Pub joy(d,c,k,VAR)
Here are my files that don't work
jm_etimer_demo - Archive [Date 2011.01.21 Time 06.22].zip
thanks for the help
RS_Jim
Var
Long Timer[6]
okay := cog := cognew(@entry,@timer) + 1
DAT org 0
entry mov tmp1,PAR
mov mspntr,tmp1
add tmp1,#4
mov scpntr,tmp1
ETC
That all works Great. However when I attempt to pass the pointer from the top object, it fails.
top obj
VAR
mytimer
OBJ
et: "filename"
Pub Main
et.init(16,@mytimer)
filname
pub init(p,timer) | okay
'' Starts event timer driver
'' -- p is "heartbeat" pin (use -1 to disable)
finalize ' stop if already running
timer[5]:= clkfreq / 1_000 ' cnt ticks per millisecond
' if (p => 0) and (p =< 27) ' if valid pin (protect rx, tx, i2c)
hbmask := 1 << p ' create mask
' enable timer
okay := cog := cognew(@entry,timer) + 1 ' start timer cog
return okay
I did not use @timer because I under stood that in passing @mytimer that I had alread passed a pointer to the hub var mytimer. I modify the top program to just directly display the results of myvar assuming that cog "filename" has correctly written the results into mytimer. I observe two problems, first the heartbeat turns on and stays on and second the results printout in pst are all zeros. I am fairly comfortable in writing PSAM routines (more so than spin) but this global VAR passing has me stumped! I wished in his spin zone article where jonny mac talked about his joysticks where he passed the vars thusly : init:joy (dio,cio,clk,@joysticks) he had shown what the other end looked like Pub joy(d,c,k,VAR)
Here are my files that don't work
jm_etimer_demo - Archive [Date 2011.01.21 Time 06.22].zip
thanks for the help
RS_Jim
Comments
In the attached demo a secondary Spin cog will flash an LED when the 1s digit of the seconds register is 5 and reset the timer at the 1 minute mark. The main cog is simply displaying the running time.
Note: I changed the etimer clear() method to reset().
See updated files below
One thing I noticed in your code in the init method is: should be changed to it looks like you are passing the pointer okay. You need to remember you are dealing with pointer on the other end.
Duane
Edit: I see Jon answered while I was reading you code. He has probably got it all fixed for you.
I tested Jon's new code and the blinkers are working fine. I did change the pin #s of the pins for dasblinker and that cog is running fine. However, the terminal obj is just printing garbage. I just realize by rereading the code that the printing method is reading directly but I cnt see it because I am printing garbage. will try and restart pst and see what happens
Jim
Had I let the Starbucks kick in I would have use my 1.1 timer code which reveals the address of the timer variables. After loading the object you can call the address method and use that from any Spin object. See attached files (I reset to 5MHz before attaching).
Jim
That's easily modified but only matters if the assembly code is going to be used with another language. If the object is used with Spin it's no problem.
How about propbasic?
* jm_etimer__v2_demo.spin
* jm_etimer_v2.spin
RS_Jim
This was so very helpful, how about posting V2 to obex? I did a hack on it that allowed the heartbeat to be every 10 ms as I am syncing an ADC to the hb. Works Great. Thanks again for the help, I have really been able to move forward on my pasm programing since this thread. I love those global VARS!
Jim