Skip to content

Conversation

@mcspr
Copy link
Collaborator

@mcspr mcspr commented Sep 17, 2018

Amending #1195 with new ESP.getFreeContStack
Definition instead of function, -6 lines

unsigned int getFreeStack() {
return cont_get_free_stack(&g_cont);
}
#else
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add elif here just like in https://github.com/xoseperez/espurna/pull/1208/files#diff-52135e36de9de9ff791c1184a170b897R50, this way for 2.5.0 we won't have that extern "C" and rest.
Sorry if this is a bumb comment, I recently start learning Arduino and stuff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much less things on the screen was the main reason.
i am not an expert on c++, just felt like a better approach :) and as it turns out from #1205 all that multiline constructs inside .ino broke compilation when on Windows. moving to header also helped with that

@mcspr
Copy link
Collaborator Author

mcspr commented Sep 20, 2018

After reading the source for cont_init and cont_get_free_stack I think getFreeStack() should be renamed to something like getTopUsedStack(), because it does not actually return currently used stack, but max amount used since startup.

Looking at postmortem code, current stack pointer can be retrieved via asm("a1") (and note the check for system / cont stack location). My basic understanding of this - sp/"a1" is "top", so just subtracting it with stack start will get used amount.
https://github.com/esp8266/Arduino/blob/master/cores/esp8266/core_esp8266_postmortem.c#L150-L159
Poking around tasmota code I did find section using it for exactly that:
https://github.com/arendst/Sonoff-Tasmota/blob/e4ebee738b437fcc101f80e2f8d7df119aea9f02/sonoff/xdrv_99_debug.ino#L219-
But I am not sure how this will behave with async libs.

@xoseperez xoseperez merged commit 493cb16 into xoseperez:dev Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants