[PASM] Can't get Coginit instruction to work
Wossname
Posts: 174
EDIT: This thread is solved and I've posted a demo program that is related to the discussion in this thread...
http://wardyprojects.blogspot.co.uk/2012/04/propeller-programming-8-cogs-running.html
I'm making Cog 0 run a "bootstrapper" written in PASM. So far so good, that works.
What I am having trouble with is starting another cog (cog 7 in fact, not that it's important) from within the bootstrapper code using the coginit instruction in PASM. The PASM code I want to put in cog 7 never runs so I must be constructing the bit fields incorrectly, so cog 7 never starts up.
I've carefully checked the field alignments and I believe them to be correct as per the Prop Manual. Therefore the numbers I'm passing in must be wrong within those bit fields.
I'd be most grateful if someone could have a quick look at my code please. Just put LEDs on P0 and P1 and run the code. In my broken code only P0's LED flashes, in working code they should both be flashing (and different speeds)...
The manual could REALLY do with a worked example of how to realistically use coginit in PASM (not just the spin version).
http://wardyprojects.blogspot.co.uk/2012/04/propeller-programming-8-cogs-running.html
I'm making Cog 0 run a "bootstrapper" written in PASM. So far so good, that works.
What I am having trouble with is starting another cog (cog 7 in fact, not that it's important) from within the bootstrapper code using the coginit instruction in PASM. The PASM code I want to put in cog 7 never runs so I must be constructing the bit fields incorrectly, so cog 7 never starts up.
I've carefully checked the field alignments and I believe them to be correct as per the Prop Manual. Therefore the numbers I'm passing in must be wrong within those bit fields.
I'd be most grateful if someone could have a quick look at my code please. Just put LEDs on P0 and P1 and run the code. In my broken code only P0's LED flashes, in working code they should both be flashing (and different speeds)...
CON '_clkmode = RCFAST _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB Main coginit(0, @BOOTSTRAPPER, 0) DAT org 0 'I want these 8 lines of cog config info to be stored in the HUB but *NOT* in the cog ram when the cogs start up 'I want the coginit call to pass these hub addresses to the cogs when they start up... 'IO PIN, loop delay cog7_config long 7, 80_000_000 cog6_config long 6, 79_000_000 cog5_config long 5, 78_000_000 cog4_config long 4, 77_000_000 cog3_config long 3, 76_000_000 cog2_config long 2, 75_000_000 cog1_config long 1, 74_000_000 cog0_config long 0, 73_000_000 fit org 0 BOOTSTRAPPER or dira, #1 'COGINIT instruction setup see Propeller Manual (PASM Instruction Set) for bit-field mov boot_settings, @cog7_config 'bad syntax??? andn boot_settings, #$03 shl boot_settings, #14 or boot_settings, #COG7_CODE 'bad syntax??? shl boot_settings, #2 andn boot_settings, #$0f or boot_settings, #7 'RUN IN COG SEVEN! coginit boot_settings '---------------------------------- FINISHED SETUP FOR COG7 mov boot_time, cnt add boot_time, #16 :loop waitcnt boot_time, boot_delay xor outa, #1 jmp #:loop 'WAIT IN THIS LOOP FOREVER, blinking LED on P0 boot_delay long 10_000_000 boot_settings res 1 boot_time res 1 fit '######################################################################## org 0 COG7_CODE 'DEBUGGING or dira, #2 mov c7_time, cnt add c7_time, #16 :debugloop waitcnt c7_time, C7_DEBUG_DELAY xor outa, #2 jmp #:debugloop mov c7_parptr, par rdlong c7_temp, c7_parptr 'fetch the IO pin number mov c7_ledPin, #1 'this 1 will be shifted into the right position shl c7_ledPin, c7_temp 'c7_ledPin now correctly nominates a single IO pin in OUTA or dira, c7_ledPin 'enable output on that nominated IO pin add c7_parptr, #4 'move the parameter pointer to the next LONG value in Hub RAM rdlong c7_delay, c7_parptr 'fetch the timer delay interval from that address mov c7_time, cnt add c7_time, #16 :loop waitcnt c7_time, c7_delay xor outa, c7_ledPin jmp #:loop C7_DEBUG_DELAY long 4_000_000 c7_parptr res 1 c7_ledPin res 1 c7_delay res 1 c7_time res 1 c7_temp res 1 fit '########################################################################
The manual could REALLY do with a worked example of how to realistically use coginit in PASM (not just the spin version).
Comments
This is just quick and dirty. I extended the table to include the code address (cog 7 only). I also pass the real (final) address of the table to the bootstrap cog. The bootstrap cog first calculates the offset by adding par to reference. Then it picks the right table entry and extracts the code address, adjusts the latter and constructs the coginit parameter in the normal way. As an example I flash the LED bar of the demo board with 0.5Hz.
I don't entirely understand the finer points of hub ram address allocations but I have worked your changes into my test app and now I have all 8 cogs running PASM and all of them taking their runtime parameters from the cog_config data table.
I'm going to tidy my code up a bit, cram it full of explanatory comments and then post it on my blog as a template for anyone else to use.
Thank you very much for your help!
(I'll post a link to my blog in a bit...)
http://wardyprojects.blogspot.co.uk/2012/04/propeller-programming-8-cogs-running.html
Thanks again Kuroneko, much appreciated