How to run two cogs in Prop-2 assembly language?
JonTitus
Posts: 193
in Propeller 2
I want to run a cog that transmits data and another cog that will independently receive the data and display it on LEDs. Think of two separate UARTs. I have no idea how to set up two independent cogs in assembly language for the Propeller 2 and would appreciate some sort of simple example that shows how to do it. Thank you. --Jon
Comments
* You don't need the second COGINIT because cog 1 will keep executing after the COGINITs. In fact, it's likely cog 1 that's running your transmit code, not cog 2 (for the same reason that receive isn't working).
* For each block of code you are going to run in cogexec mode with COGINIT, you should have an ORG 0 at the beginning of the block.
Ok. I had a bit more time to look over the code this morning. A few suggestions:
It should start cog 1 (first free cog) and return the cogid of the started cog into id. If it works then output id to the pins instead of $55 to see that it did indeed start cog 1.
sync_receive needs to be moved after the cog 0. It would otherwise be getting the address in cog just after the jmp #.loop instruction. ie its int the wrong cog space.
That shouldn't matter here because it's the hub address of sync_receive that he needs, right?
Ok, so when you added the second "ORG 0", you reset the cog address counter, including for "sync_tx_mode" and "clock_mode". Simply move them above "sync_receive" (technically, above the second "ORG 0"), so that their addressing is relative to the first block of cog code.
Also, I recommend following @Cluso99's advice about dynamically allocating the receive cog. As you re-use code snippets, this keeps you from having to manually adjust cog allocation.
Later this afternoon I discovered something similar with loading LUT. A few gotchas around placing the labels in the right position for it to work properly.
I'm glad you were able to get it working! Is this your first multi-cog program? I still remember my feeling of elation the first time I went multi-cog. Admittedly, that was on the P1, but that feeling has never really diminished.