Weird COG issues - is it stack space?
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
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR byte cog PUB main | x start dira[27] := 1 'x := 1 repeat outa[27] := !outa[27] waitcnt(clkfreq/4 + cnt) PUB start : Pass stop 'stops cog if already started Pass := (cog := cognew(@LCDgen, 0) + 1) > 0 'this passes the ADDRESS of tiles[0] PUB stop if cog cogstop(cog~ - 1) 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 movi ctra, #%000010_010 'config counterA PLL - divisor of 32 movs ctra, #1 'output PLL on p1 mov FREQa, _FREQa 'load freq register (but not FRQa yet) mov LEDmask, _LEDmask 'load masks.... mov flipAllmask, _flipAllmask mov FCLmask, _FCLmask mov FCLoffMask, _FCLoffMask mov YCLmask, _YCLmask mov LSBmask, #1 mov flipAllmask, _flipAllmask mov blank, _blank mov testCLR, _testCLR mov test1, _test1 mov pixels, _pixels 'load with 0,1,2,3.... or outa, LEDmask 'turn on LED newFrame xor outa, LEDmask or outa, FCLmask 'turn on FCL - rising edge indicates frame start mov tB, #120 'Scanline count scanLine mov tA, #40 '40 chars/scanline charOut mov colors, test1 mov frqa, FREQa 'set frequency of CTRa and start running waitvid colors, pixels 'Start the data output.... While it's doing that get next char scanline djnz tA, #charOut NewLine waitvid colors, testCLR 'dummy waidvid to allow data output to finish b4 flashing clks mov frqa, #0 'stop CTRa or outa, YCLmask 'turn on YCL and outa, YCLoffMask 'turn off YCL and outa, FCLoffMask 'turn off FCL djnz tB, #scanLine jmp #newFrame _test1 long $51_51_51_55 'thinLines _testCLR long $FF_FF_FF_FF 'test pattern to produce clear screen _blank long 0 _pixels long %0000_0000_0000_0000_0000_0000_1110_0100 '0,1,2,3 from right, rest are 'don't care' _outpins long %0000_0000_0000_0000_0000_0000_1111_1111 'data active, data and clk's - XCL by other COG _activeMask long %1000_0000_1000_0000_1000_0000_1000_0000 'signal to denote data is being output _VSCLset long %0000_0001_____0000_0000_0100 '1clk/pixel 4clks/frame (4 'colors' to send) _YCLmask long %0000_1000 _YCLoffMask long $FF_FF_FF_F7 _FCLmask long %0010_0000 _FCLoffMask long $FF_FF_FF_DF _FREQa long $1000_0000 'PLL freq = 16*(80MHz x $1000_0000)/2^32 = 80MHz _ROMoffset long $8000 'offset needed to reach tile map in ROM _flipAllmask long $FF_FF_FF_FF 'mask to flip all bits using XOR _LEDmask long %0000_0000_0000_0000_0000_0000_1000_0000 _delay long 80_000_000 tA res 1 tB res 1 pixels res 1 colors res 1 VSCLset res 1 FREQa res 1 activeMask res 1 Ascii res 1 'var to hold tile Ascii value -> gets converted to tilemap address in ROM TMpointer res 1 'pointer to Ascii tile map time res 1 delay res 1 flipAllmask res 1' FCLmask res 1 YCLmask res 1 YCLoffMask res 1 FCLoffMask res 1 LSBmask res 1 LEDmask res 1 startAddrOff res 1 'offset from start address of char tile map in ROM blank res 1 testCLR res 1 tScanline res 1 test1 res 1
Thanks.