Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline getFreeStack and mention 2.5.0 helper method #1208

Merged
merged 1 commit into from
Sep 20, 2018

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