1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-08 17:02:26 +03:00

Add function to measure stack high water mark (thanks @g3gg0)

This commit is contained in:
Ivan Grokhotkov
2015-12-23 10:13:01 +03:00
parent 66a88ac8d2
commit 60baf802e1
2 changed files with 23 additions and 0 deletions

View File

@ -30,6 +30,12 @@ void ICACHE_RAM_ATTR cont_init(cont_t* cont) {
cont->stack_guard2 = CONT_STACKGUARD;
cont->stack_end = cont->stack + (sizeof(cont->stack) / 4);
cont->struct_start = (unsigned*) cont;
// fill stack with magic values to check high water mark
for(int pos = 0; pos < sizeof(cont->stack) / 4; pos++)
{
cont->stack[pos] = CONT_STACKGUARD;
}
}
int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
@ -38,6 +44,19 @@ int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
return 0;
}
int ICACHE_RAM_ATTR cont_get_free_stack(cont_t* cont) {
uint32_t *head = cont->stack;
int freeWords = 0;
while(*head == CONT_STACKGUARD)
{
head++;
freeWords++;
}
return freeWords * 4;
}
bool ICACHE_RAM_ATTR cont_can_yield(cont_t* cont) {
return !ETS_INTR_WITHINISR() &&
cont->pc_ret != 0 && cont->pc_yield == 0;