-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Place FunctionalInterrupt into IRAM #5780
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
Conversation
@hreintke could you please take a look at this? |
@OttoWinter @devyte In order to make the implementation full consistent with other attachInterrupts,
should also get the IRAM attribute. |
@OttoWinter |
@OttoWinter Sorry, overlooked that line. |
It should probably be written somewhere in the docs that the lambda expression must also be placed in iram to ensure correct operation if the compiler doesn't optimize it away; attachInterrupt(pin, []() ICACHE_RAM_ATTR {
// do something
}, mode); Not sure how this is for std::bind. Also I'm a bit wary if the std::function call operator must also be placed in iram. The function is called through that operator so technically it must also be in iram. |
#5922 is merged. Is there a MCVE to test this PR ? |
@d-a-v Yes, see attached issue - copying it here too: void setup() {
// doesn't work reliably, my guess the function is pre-cached somehow and so
// no interrupt for reading it into cache needs to be called?
// I don't have the experience to say.
attachInterrupt(D1, [](){}, CHANGE);
} and get a high frequency signal on that pin, for example 50% duty cycle PWM from another ESP. |
If this is merged, then the std::function constructor and destructor need to be moved as well. Probably assignment too. |
@OttoWinter I tried your sketch. See the below sketch, using
What can be easily done is calling
|
@d-a-v Great, now, to keep the related information together in one place - one get's confused - is this the pertaining test for the
|
@d-a-v And if so, then
Cross-check:
gives |
@d-a-v In plain words, I don't understand what std::function<any(...)>::operator()() const is or does or what relevance the operator() has - the fact of the matter seems to be, that the lambda's code is not I IRAM, and isn't that what it is all about? |
It seems we recognize only |
I put this symbol into the linker file and the lambda is moved to IRAM. |
The linker moves lambda/std::bind into IRAM basically by a simple REGEX in the linker file. So for std::bind which has a limited set of signatures (mangled names, basically) we added those to the IRAM section. Lambdas can probably be detected by name mangling rules and moved into IRAM, but the problem is that then all lambda functions, even ones used in regular app code (the vast majority) will be pushed into IRAM and you'll end up not being able to link anymore. I'm with @d-a-v, it's not a feasible option for the 8266. The root of the problem is that in GCC you can't put a section on lambdas (well, you can, but GCC ignores it and doesn't emit code with the changed section). Not sure there's much that can be done here. |
@earlephilhower @d-a-v |
See #5779
I have yet to test this, so using the new draft PR feature.
Also made functional
attachInterrupt
functions usable in ISR (consistent with non-functionalattachInterrupt
)Should
cleanupFunctional
also be placed in IRAM? (called from__attachInterrupt
)