Weird COG issues - is it stack space?
homosapien
Posts: 147
I have been writing small ASM programs that use one cog, that I start from SPIN with a COGNEW command. Tonight I edited one of these ASM programs and it started acting all weird - if I deleted even one unused variable assignment (such as "LED res 1") the cog that was running the ASM program would not start. Then I noticed that even small changes in the SPIN methods of the calling programs would crash the cogs (in the code below, if I change the letter 'e' in the tile table, the cog will not start???????).
I am not allocating stack space - I only have the simple SPIN starting program and the rather short ASM program. Do I need to allocate stack space? Is there a primer on calculating and doing this that some one can point me to?
Attached is the SPIN code that partially fills a tile map and starts a display driver, but practically any small (trivial) edit to the program makes it not work.
Thanks -h
I am not allocating stack space - I only have the simple SPIN starting program and the rather short ASM program. Do I need to allocate stack space? Is there a primer on calculating and doing this that some one can point me to?
Attached is the SPIN code that partially fills a tile map and starts a display driver, but practically any small (trivial) edit to the program makes it not work.
Thanks -h
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 cols = 40 rows = 15 screensize = cols * rows VAR long tiles[screensize] 'var to hold longs of tile map. Each long will point to the start of char in ROM PUB start cognew(@LCDgen, @tiles) 'this passes the ADDRESS of tiles[0] fillMap PUB out(c, x) 'puts ascii code for character at pointer position in LCD tileMap tiles[x] := c PUB fillMap | i 'Fills first line of tile map. CHANGING THE 'e' TO ANY OTHER LETTER CRASHES PROGRAM??????????????? out("Y",0) out("o",1) out("u",2) out(" ",3) out("a",4) out("r",5) out("e",6) out(" ",7) out(" ",8) out(" ",9) out(" ",10) out(" ",11) out(" ",12) out(" ",13) out(" ",14) out(" ",15) out(" ",16) out(" ",17) out(" ",18) out(" ",19) out(" ",20) repeat i from 21 to 39 out(" ", i) DAT org 0 LCDgen mov dira, _outPins 'make outputs movd vcfg, #%000000_000 'pins 7..0 for video output movs vcfg, #%0_0101_0101 'mask to be used for video output - CLK pins blocked movi vcfg, #%0_01_1_0_0_000 'VCFG set to 8-bit, 4-color). mov VSCLset, _VSCLset mov vscl, VSCLset 'mov timing of video output to vscl register
Comments
You don't have a stack-problem. The first COG which runs after booting simply uses the whole free HUB-RAM as stack-space. PASM COGs don't even have a stack. So, the problem must be in the PASM code that you're hiding.
The weirdness continues - the attached code runs as expected; the ASM code running in its own cog is putting a test pattern on the LCD I am driving and flashing an LED at the frame rate, the spin code is simply flashing another LED (after starting the cog with ASM).
However, if I include the "x := 1" line in the 'main' function (commented out in the attached code), weird things happen - the timing of the LCD signals goes all screwy (eg, frame pulse instead of a 50ns pulse every 14ms becomes a square wave pulse with a period of 15ms) but both LEDs do continue to flash showing that both cogs (ASM and SPIN) are still running.
It is as if the SPIN cog is somehow altering the ASM cog, overwriting some common memory but I do not see how.
thanks in advance for any suggestions, code attached. -h
Thanks.