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 ESP::getCycleCount() to make it safe to call from ISRs #3165

Merged
merged 3 commits into from Sep 11, 2019

Conversation

dok-net
Copy link
Contributor

@dok-net dok-net commented Sep 1, 2019

As the subject line says, it has been found by users (of EspSoftwareSerial), that the function is not ISR-safe right now. Inlining should efficiently fix this, IMHO.

@me-no-dev
Copy link
Member

to make it safe, mark it as IRAM ;) now it is not safe, because it has to be loaded from flash. ESP32 != ESP8266

@dok-net
Copy link
Contributor Author

dok-net commented Sep 5, 2019

Is that an observation you can explain based on generated code? What part of inline, __attribute__((always_inline)), and inline assembly still allows for flash access here, when invoked from a code that resided in IRAM? I don't get it - what's the difference to ESP8266 then?

@dok-net
Copy link
Contributor Author

dok-net commented Sep 8, 2019

@me-no-dev I've looked at the output from objdump, seems like the code in question is always inlined. Whenever it's not (by changing the attributes, removing inline, moving the function into Esp.cpp, whatever), I get errors from the compiler from calling getCycleCount() in ISRs. To make a long story short, this PR expresses what the compiler optimizations affect right now anyway, and that's a good thing for the human reader, isn't it?

@me-no-dev
Copy link
Member

And how about you mark it as IRAM and make it easily understandable that it can be run in ISR?

@dok-net
Copy link
Contributor Author

dok-net commented Sep 11, 2019

Done.

@me-no-dev me-no-dev merged commit 7fe2812 into espressif:master Sep 11, 2019
@dok-net dok-net deleted the isr_safe_cyclecount branch September 11, 2019 18:28
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.

None yet

2 participants