Help passing data from a cog to hub ram
Dr_Acula
Posts: 5,484
I'm working on some experiments with video and external ram chips and the first step has been to get something working slow in Spin and then port it over to Pasm.
But I cannot seem to be able to pass data from pasm to spin.
The code is fairly standard. Define a block of variables (either in VAR or in DAT - both work fine)
start up a cog
and change the first variable ramparam from 0 to 1 (it is initialized to zero)
And then change some pixels on the screen depending on the value passed back
This works fine.
But then I added some code to pass back values in a second variable, and everything has gone haywire. My first bit of code was this
Adding the second to last line means the screen goes blank. I've had a few dead ends - I tried declaring the parameters in the main program as a DAT array instead of a VAR array but no change.
The loop in spin that detects this is a tight spin loop, and maybe the prop can't handle this but I doubt this is the reason
I've got myself very confused between variables and pointers, but I think I have it correct. It is copied out of the propeller manual and also from some other working code examples.
So out of desperation I started writing more code.
There are some strange things here. There are three outcomes - the program changes the variable, the program does not change the variable or the whole program crashes and the screen goes blank.
The outcome is affected by the number of NOPs added. The outcome changes depending on the number of NOPs and the addition of other code even when the other code does not do anything. eg the 2nd to 5th lines don't do anything, yet adding them in changes the behaviour further down and the number of NOPs needed to get it to work.
Sometimes it works with 1 NOP, sometimes 3.
I suspect I am missing something really obvious here. Maybe I'm not stopping the cogs on a reboot. Maybe the hub variables are too near the top of ram (the video buffer is fairly large). Maybe something overwrites something critical.
Or most likely, I'm making a silly syntax error.
I've attached a copy that does work. If someone can spot the obvious error I'd be most grateful. If not, then this code is running with the TV on pins 24-26 and all the bits of code that read the external ram can be commented out as the issue here is why it works fine passing one variable but falls apart when passing two.
Any help would be most appreciated!
But I cannot seem to be able to pass data from pasm to spin.
The code is fairly standard. Define a block of variables (either in VAR or in DAT - both work fine)
VAR long ramparam1 long ramparam2
start up a cog
PUB Start(ramptr) : okay stop okay := cog := cognew(@entry, @ramptr) + 1 PUB stop '' Stop ram driver - frees a cog if cog cogstop(cog~ - 1)
and change the first variable ramparam from 0 to 1 (it is initialized to zero)
org entry mov p,par loop mov valreg,#1 ' change the value wrlong valreg,p 'value,address jmp #loop
And then change some pixels on the screen depending on the value passed back
PUB RamStatus | i ' read the status long of the ram driver i := ramparam1 if i == 0 blueline if i == 1 greenline
This works fine.
But then I added some code to pass back values in a second variable, and everything has gone haywire. My first bit of code was this
mov Mem,par ' get start of the parameter list mov statusptr1,Mem mov statusptr2,Mem add statusptr2,#4 ' next long hub ram location loop mov ValReg,#1 ' temp variable = 1 wrlong ValReg,statusptr1 ' store in hub value, address wrlong ValReg,statusptr2 ' blank screen, whole program crashes if add this line jmp #loop
Adding the second to last line means the screen goes blank. I've had a few dead ends - I tried declaring the parameters in the main program as a DAT array instead of a VAR array but no change.
The loop in spin that detects this is a tight spin loop, and maybe the prop can't handle this but I doubt this is the reason
repeat ramstatus ' change line color based on status value
I've got myself very confused between variables and pointers, but I think I have it correct. It is copied out of the propeller manual and also from some other working code examples.
So out of desperation I started writing more code.
org entry mov p,par rdlong statusptr1,p add p,#4 rdlong statusptr2,p mov p,par ' restore old value loop mov valreg,#1 ' change the value wrlong valreg,p 'value,address mov mem,p nop 'nop ' two nop and it works, three nops and there is a blank screen add mem,#4 wrlong valreg,mem jmp #loop
There are some strange things here. There are three outcomes - the program changes the variable, the program does not change the variable or the whole program crashes and the screen goes blank.
The outcome is affected by the number of NOPs added. The outcome changes depending on the number of NOPs and the addition of other code even when the other code does not do anything. eg the 2nd to 5th lines don't do anything, yet adding them in changes the behaviour further down and the number of NOPs needed to get it to work.
Sometimes it works with 1 NOP, sometimes 3.
I suspect I am missing something really obvious here. Maybe I'm not stopping the cogs on a reboot. Maybe the hub variables are too near the top of ram (the video buffer is fairly large). Maybe something overwrites something critical.
Or most likely, I'm making a silly syntax error.
I've attached a copy that does work. If someone can spot the obvious error I'd be most grateful. If not, then this code is running with the TV on pins 24-26 and all the bits of code that read the external ram can be commented out as the issue here is why it works fine passing one variable but falls apart when passing two.
Any help would be most appreciated!
zip
9K
Comments
I really love this propeller forum!
BTW how do you put "solved" next to a thread?
Mind you, I'm making some silly mistakes here.
This code works fine. But if I uncomment this line
The screen goes blank.
But variable t1 is not used anywhere else.
Adding a NOP in place of that line also crashes the program.
I think I still have more to learn with PASM.