Use of getreg(addr_hub, addr_cog, cnt) and use of REG[addr] to access cog memory?
Phonos
Posts: 45
I am trying to improve my understanding of hub/cog memory addressing and am not getting the results I expect from these two spin2 routines. Can anyone help me with the rules of usage?
Comments
I've only used the setregs() method, but it did what I needed. In this case I need to pass a bunch of hub variables into the cog. Instead of using locals in the method, I just copied them directly to the PR0..PR7 registers. This was faster than using locals and the routine works as before.
You're not showing your code. Is your order of parameters correct? Are you using the correct cog address? (must be direct value, does not use @ or #)
(French accent)A few moments later(/French Accent)
I hate leaving things to theory -- so I did a very quick test. I hooked up a button board to the header that starts at P32 and ran a bit of code. The results are as expected. I did this capture while pressing my 0 button.
It is a bit circular, and broken.
I think the thing I am missing is setreg/getreg only work within the actual cog ram that the spin interpreter is running in?
I just remembered that Chip helped me with an OLED driver that I embedded in cog memory.
The first line loads my driver code. The second line loads the pin numbers into the driver. As you can see, you need to change @my_var (which is a hub address) to #my_var which is a cog address.
This is the code that gets loaded into the cog and updated.
But now that I think about it for a minute, I believe setregs() and getregs() work with the interpreter's cog, not a custom cog. For the latter you would have to use some kind of flag command and use rdlong or wrlong to move into or out of the custom cog to the hub.
I think you're right.
Correct. Launching machine code into a new cog is done with COGINIT().
The dim bulb is starting to glow a little brighter. Thanks for the help. The same scenario applies to the REG[addr] then?
Never used it but, yup, has to be a register of the currently executing cog.