Stack monitor
Phil Pilgrim (PhiPi)
Posts: 23,514
I've had some difficulty determining how large to make the stacks that cognew requires. Here's a Spin object that monitors any selected stack and displays its maximum depth on the development board's LEDs. Just be sure to start with a large stack at first to do the monitoring. Then you can determine how big it really needs to be, adding a margin for safety, of course!
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 3/20/2006 4:16:43 AM GMT
[i][b]'' Stack Monitor: Displays maximum stack depth on the eval board's LEDs.[/b][/i]
[i][b]''[/b][/i]
[i][b]'' To start, call this BEFORE launching the cog that uses the stack being monitored:[/b][/i]
[i][b]''[/b][/i]
[i][b]'' stack_monitor.start(@stack, stack_size_in_longs)[/b][/i]
[i][b]''[/b][/i]
[i][b]'' This will fill the stack buffer with a filler pattern. Then it will launch a cog that monitors[/b][/i]
[i][b]'' how many non-filler longs exist in the buffer at any time and display that value in binary with the LEDs.[/b][/i]
[i][b]''[/b][/i]
[i][b]'' Copyright 2006 Phil Pilgrim[/b][/i]
[i][b]''[/b][/i]
[i][b]'' Anyone is free to use, copy, modify, and distribute this program. There is NO WARRANTY, period.[/b][/i]
[i][b]'' Please retain this boilerplate in any copies distributed.[/b][/i]
[b]CON[/b]
filler = $5aa5a55a
[b]VAR[/b]
[b]word[/b] my_stack[noparse][[/noparse]32]
[b]PUB[/b] start(addr, size)
[b]longfill[/b](addr, filler, size)
[b]return[/b] [b]cognew[/b](monitor(addr, size), @my_stack) => 0
[b]PUB[/b] monitor(addr, size) | used, i
[b]dira[/b] := $FF0000
[b]outa[/b] := 0
[b]repeat[/b]
used := 0
[b]repeat[/b] i [b]from[/b] addr to addr + size * 4 step 4
used -= [b]long[/b][noparse][[/noparse]i] <> filler
[b]outa[/b] := used << 16
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 3/20/2006 4:16:43 AM GMT

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 3/20/2006 2:25:04 PM GMT