Hub exec - the basics [solved]
wmosscrop
Posts: 409
I'm just trying to get my head around hub exec. To me the following code should work (both led's lit on a P2 eval board):
I'm obviously missing something.
Edit:
I'm using Pnut, v 34o.
Added the repeat to the Start() method. No change in results.
PUB Start() coginit(32 + 16, @init_hub, 0) repeat DAT org 0 ' COG init_cog drvl #56 cog_loop jmp #cog_loop DAT orgh $400 ' HUB init_hub drvl #57 jmp #init_cogBut only the led on pin 57 lights.
I'm obviously missing something.
Edit:
I'm using Pnut, v 34o.
Added the repeat to the Start() method. No change in results.
Comments
I think your start routine needs to either end in infinite loop or shut down the cog.
Otherwise it may be doing random stuff...
I think what you'd need to do is copy that cog code into the Spin2 cog.
Right now, it's just in HUB memory...
The only way init_cog can execute is with another coginit or as evanh suggested use inline assembly.
For Spin2, inline assembly somehow copies that code to lower cog ram and runs it.
So I would want the hub to execute first, loading the cog ram if needed, and then branching into the cog. Otherwise I don't see any way to copy the code into the cog before starting it. Right?
How do I find the address of the cog's data? I've tried @ & @@. So far all I've done is made it worse.
I have searched for an example of mixed hub/cog execution and can't find any. I think there must be some out there I just can't find it.
I tried it PNut and I see 1 LED light up .
And then jump back, of course...
That works
Yes, and it works for me! Thanks everyone for your input. There's so much power here, and so many new levers to push and pull to get to that power. It's knowing the lever positions that's key.
And there really are a lot of levers. Smart pins especially. I originally was disappointed due to the omission of the P1's counters but now see how much better it is on the P2.
Again, thanks!