|
LevelMeter-Display
2.0
An ultrasonic Level Meter for Stormwater Cisterns
|
Contains Routines to check maximum Stack Usage. More...

Functions | |
| void | Stackchk (void) |
| Fills the stackchk Struct. More... | |
| static void | StackchkFill (void) |
| Do not call this function from anywhere! It is called automatically by the startup Routine. More... | |
Variables | |
| char | __bss_end |
| The lowest SRAM-Address not used for any Variable. More... | |
| StackchkStruct | stackchk |
| Stores the results of Stackchk(). Always call Stackchk() before using this values! More... | |
Contains Routines to check maximum Stack Usage.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
This module tries to estimate stack usage. This is done by filling the memory from __bss_end to RAMEND with a predefined value. Calls of Stackchk() find the first bytes that differs and fills the stackchk structure.
Note that this function need to check every single byte from __bss_end to the first difference and thus might take some milliseconds to complete. It should not be called from ISRs.
This is not a secure method since your application might push exactly this byte for an unlimited number of times without a chance to detect it but under normal conditions it would work. You can call this function regularly or just before you need the values and they will you give an idea how large your stack can grow. If you have only a few bytes reserve or there might be functions using large amount of stack space that have not been called yet, you should think about a better solution...
| void Stackchk | ( | void | ) |
Fills the stackchk Struct.
It walks through the free RAM to find the probable end of the heap and the beginning of the stack. Note that there is no guarantee that heap nor stack cannot grow more than this but it can give you an idea of how many spare bytes you have before heap and stack collide.
Heap end is detected if four consecutive fill bytes are found. In extreme cases this may happen inside the heap as well. Also, the last bytes on the stack may accidentally be the same than the fill byte and the real stack size would not be correctly found. You might want to use different fill bytes to get more exact results. You must decide yourself ho probable the fill byte is in your application.
You can calculate the reserve before heap and stack would collide as
stackchk.stackmin-stackchk.heapmax-1
References __bss_end, StackchkStruct::heapmax, stackchk, STACKCHKFILLBYTE, and StackchkStruct::stackmin.
Referenced by DoTflags(), and ShowScreen().

|
static |
Do not call this function from anywhere! It is called automatically by the startup Routine.
References __bss_end, StackchkStruct::heapmax, stackchk, STACKCHKFILLBYTE, and StackchkStruct::stackmin.
| char __bss_end |
The lowest SRAM-Address not used for any Variable.
Referenced by Stackchk(), and StackchkFill().
| StackchkStruct stackchk |
Stores the results of Stackchk(). Always call Stackchk() before using this values!
Referenced by ShowScreen(), Stackchk(), and StackchkFill().
1.8.15