View Full Version : Cognew questions...
01-30-2008, 01:42 AM
1.· Can you COGNEW a routine in an included object?· I tried it and it worked, but then rebooted!
··· I'm playing a wav file in the background...· This code works as expected:
'play wav file in background using a cog
'play a wave and return status after playing
··· but, if I try the commented line in "PlayBackgroundWav", the file plays and then the system reboots...
··· I tried making the stack very big, but it didn't help...
2.· Can I use the stack space to return some values by storing things there at the end of the proceedure that the CogNew calls?· Anybody tried this?
01-30-2008, 01:48 AM
1) no, cognew only works for methods within the same object.
2) Never tried
Paul Baker (mailto:email@example.com)
Propeller Applications Engineer
Parallax, Inc. (http://www.parallax.com)
01-30-2008, 02:36 AM
Can I use the stack space to return some values by storing things there at the end of the proceedure that the CogNew calls? Anybody tried this?
You can do this ...
long stack[ 1024 ]
CogNew( RunsInOwnCog, @stack+4 )
tv.Out( $01 )
tv.Str( String( "Count : " )
tv.Dec( long[ @stack ] )
PRI RunsInOwnGog | stackBase
stackBase := @return - ?
long[ stackBase ] := long[ stackBase ] + 1
The @stack+N in the CogNew allocates a common passing area for the separately running cog. The only thing I can't remember is how to determine the stackbase. I recall it's simply a matter of 'stackBase := @return - X' but cannot remember what X is !
Put a "long[ $7FF0 ] := @return" in RunsInOwnCog then print "long[ $7FF0 ] - @stack" in the main and you'll be able to determine the X.
01-30-2008, 03:41 AM
The only thing I can't remember is how to determine the stackbase.
It's more or less @stackBase. I think the stack contains returnn address, parameters, then local variables. When calling without any parameters this offset can easily be determined by looking into the stack (I shall give you the offset in 10 minutes...)
As the stack is used for internal operations I do not see how to work with such things dangerlessly....
What you can do - but for what reason? - is
PUB main | aStack
PUB aRoutine | theStack
theStack := 4711
Now 4711 can easily be retrieved in "aStack".
Post Edited (deSilva) : 1/29/2008 7:55:10 PM GMT
01-30-2008, 03:46 AM
I was thinking that perhaps the stack was only used starting and during the cognew'd routine...· At the very end of this routine, how about:
aStack := 4711
just before the cog is stopped?
01-30-2008, 03:52 AM
Especially the FIRST elements will contain most relevant internal data.
01-30-2008, 04:19 AM
Well, I just tried it a bit and it appears that stack holds the cog# and stack holds something else terribly important..
But, it doesn't seem to mind me setting stack...
CON 'Constants Section
_clkmode = xtal1 + pll16x 'using 5 MHz crystal in pll16x mode
_xinfreq = 5_000_000 'to achieve 80 Mhz clock frequency
OBJ 'Objects Section
'We need the VGA (or TV) text driver
text : "vga_text" 'For NTSC TV Video: Comment out this line...
'text1 : "tv_text" 'and un-comment this line (need to change pin parameter for text.start(pin) command below too).
text.start(16) 'Start the VGA/TV text driver (uses another cog)
'The parameter (16) is the base pin used by demo and proto boards for VGA output
'Change (16) to (12) when using "tv_text" driver with demo board as it uses pin#12 for video
PUB HelloWorld 'the first PUB routine is assumed the be the main one
text.str(string("Hello World")) 'Output the string !
'Note that the Spin interpreter will halt on this last line,
' but, the text driver will continue to display on screen