|My Propeller Transmitter Station|
Running KO7M CW Keyer Code
Jeff found a Prop Object that estimates and report Stack usage. Our initial reports indicated my Stack were growing as large as 48. My initial expectations were more like 16. As can be seen, my estimate was way off, and likely the cause of many of my programming problems and needless frustration.
The Stack Usage tools reports the Stack Size by bit-banging the report on one of the Prop pins that should be connected to a terminal. My problem is I do not have a easily accessible terminal in my Ubuntu environment connected to the Prop. With Ubuntu, the Prop UI wants to control the terminal I/O lines for EEPROM download, and a quick change of UNIX port would be necessary to make the switch (Yeah, I know, it's my problem, and that's what I deserve for using Ubuntu :-).
The Stack Usage tool finds the Stack size by writing a known pattern onto an empty stack. then later reports the count of over-written stack entries. The Stack Usage Object is a little complex and not very flexible for my use.
Well, I can do the same as the Tool (and maybe better), with a simple cut-n-paste routine (method) into any main Object.
My first typical PUB method appears as follows:
PUB Demo | stat StackLengthInit Init ' Which includes the LCD setup < normal program stuff goes here > ' Report Stack Length LCD.moveto(1,2) LCD.dec(StackLength) repeat pauseSec(1)
I inserted the following just below the first PUB method. Calling "StackLengthInit" sets it up, and then "StackLength" can be used at any point to report the usage.
DAT CON StackSizeMax = 256 StackPattern = 19823343 ' Some Random Pattern PRI StackLengthInit : i | S[StackSizeMax] i := 0 repeat StackSizeMax S[i++] := StackPattern -> 7 PRI StackLength : i | S[StackSizeMax] i := 0 repeat StackSizeMax if S[i++] == StackPattern -> 7 return i DAT
Note: I used the "StackPattern -> 7" expression to (maybe) help provide some bits in the upper bits of the saved stack space (maybe it is not really necessary, and just the StackPattern would surfice :-).
It seems to work very will for my Ubuntu Prop Development environment, and it is flexible enough that I can save or report the results as I desire, on my standard LCD or a Terminal (if connected).
From now on, I will be much more Stack Size Aware :-)
It's all fun with the Prop !