Skip to content

Bugfix: attach interrupt (#6049) #6048

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

Merged
merged 7 commits into from
Jul 4, 2019

Conversation

dok-net
Copy link
Contributor

@dok-net dok-net commented May 4, 2019

Fixes: #6049

  • BUG FIX: __attachInterruptArg is known in the field, but it's use fails due to incorrect delete of arg pointer via cleanupFunctional. This PR guards against this case.
  • Original author commented that ScheduledFunctions.(h|cpp) were added by mistake, and should be removed.
  • ICACHE_RAM_ATTR was previously applied to attachInterrupt() / detachInterrupt() functions, but reviewer of Fixes and implementation to expose attachInterruptArg in Arduino.h #6003 commented that this can be reverted to save some precious IRAM, as attaching / detachInterrupt from inside ISR are corner cases.
  • Properly expose attachInterruptArg() via Arduino.h

(Reference: PR #6047 implement all-C++ functional based interrupt service routine handling. Caveat: ICACHE_RAM_ATTR attributes maybe don't quite work on functional instances, like lambdas, yet)

@dok-net dok-net changed the title Bugfix: attach interrupt Bugfix: attach interrupt (#6049) May 4, 2019
Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

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

This PR shows lots of changes because of tab/space/style updates, making It hard to read.
Approving because

@dok-net
Copy link
Contributor Author

dok-net commented May 5, 2019

@d-a-v quote: "shows lots of changes because of tab/space/style updates" - yes, except that it doesn't :-)
Wrt. #5774, if you trust that 57bdbe1a9522c5091020da85290bb54d26257d7f does exactly that and nothing but, the changes are quite easily digestible.

@d-a-v
Copy link
Collaborator

d-a-v commented May 5, 2019

the changes are quite easily digestible

Indeed and I took time to digest them.
It is far more easy to check when style is not changed in a PR so the diff is clear to read.

#5774 is not meant to be used on some files but on all files at once (and will be checked by CI from that moment). In the meantime, doing that in a PR is not nice for reviewers.

@dok-net
Copy link
Contributor Author

dok-net commented May 6, 2019

@d-a-v I am really aware of that and quite sorry, but please trust me that all these smart code editors I use keep changing layouts all the time and having three proposals in the game, it began to seem to make sense to me to use the styling provided for in the repo sources already. The examples even get
rejected when they are not astyled - that might be for ESP32, though, things are getting confusing :-)
I hope you will find diff-reading #6049 to #6047 or #6038 to be a more pleasant experience for it.

@dok-net
Copy link
Contributor Author

dok-net commented May 13, 2019

@d-a-v This bug-fixing PR should be readable now (please use diff settings: hide whitespace changes).

@d-a-v
Copy link
Collaborator

d-a-v commented May 14, 2019

@dok-net
I understand this PR is the first of your PR serie. I think it can be merged, however I question myself about your removal of ICACHE_RAM_ATTR from __detachInterrupt. I think it is legal for an interrupt handler to detach itself no ?

@dok-net
Copy link
Contributor Author

dok-net commented May 14, 2019

@d-a-v If deleting
struct FunctionInfo
{
std::function<void(void)> reqFunction = nullptr;
std::function<void(InterruptInfo)> reqScheduledFunction = nullptr;
};
is guaranteed to not cause flash operations? std::function<void(InterruptInfo)> looks suspicious to me.
And I haven't even begun complaining about such long-running operations inside world-stopping ISRs :-)

@d-a-v
Copy link
Collaborator

d-a-v commented May 14, 2019

You are right, cleanupFunctional needs to be in iram too, and probably something like #5922 would need to put functional destructors into iram.
@earlephilhower what do you think ?

And I haven't even begun complaining about such long-running operations inside world-stopping ISRs :-)

Well it is true in such case where a handler stopping itself needs to destroy everything.

The other way would be to use a Scheduled function to do that job but then it would have to be managed with a bool in the interrupt handler to check wether the handler is in a destroy state.

I vote for putting iram back in detachInterrupt (not all interrupts have args, let's not break them too) and maybe creating a new "defer detachInterrupt in a Scheduled function" issue to address this case.

@dok-net
Copy link
Contributor Author

dok-net commented May 15, 2019

I think I reconsider my opinion on supporting detachInterrupt() from inside executing ISRs - does this not lead to object destruction on functional etc. occurring while the same are in the middle of executing? Is that well specified? From reading up on the IRAM size of the ESP8266, it would also seem to be unwise pinning all this code there out of convenience, given that the resulting inability to run applications at all will be most inconvenient ;-)

@dok-net
Copy link
Contributor Author

dok-net commented May 21, 2019

@earlephilhower So here I am asking you to speed up acceptance of this PR in order for me to update EspSoftwareSerial. It's getting quite tedious switching between my esp8266 branches, especially due to the SoftwareSerial submodule that keeps changing back and forth all the time due to this dependency.
I firmly believe in adding publicly the attachInterruptArg(), plus the bugfixes to detachInterrupt() that I have implemented. The chances in this PR are all rather pedestrian.

@devyte
Copy link
Collaborator

devyte commented May 21, 2019

@dok-net please open a gitter account and let me know here. I'll send an invite to discuss directly there.

@dok-net
Copy link
Contributor Author

dok-net commented May 23, 2019

@devyte I have an account there now.

@dok-net dok-net force-pushed the bugfix/attachInterrupt branch 2 times, most recently from e406754 to 9a6e9e5 Compare May 29, 2019 10:13
@dok-net
Copy link
Contributor Author

dok-net commented May 29, 2019

@d-a-v @devyte At the speed of Schedule merges, I'm getting jealous :-)

I vote for putting iram back in detachInterrupt (not all interrupts have args, let's not break them too) [...]

I've done this now. This one PR really doesn't change all that much, it just enables me to publish the proper next EspSoftwareSerial and we could go forward with discussing more seriously my other PRs after this.

@d-a-v
Copy link
Collaborator

d-a-v commented May 29, 2019

I think we can merge. @devyte was requesting a chat, I'll let him merge.

@d-a-v d-a-v requested a review from devyte May 29, 2019 11:10
@dok-net dok-net force-pushed the bugfix/attachInterrupt branch 3 times, most recently from 5812996 to 0ca7134 Compare June 10, 2019 22:45
@dok-net
Copy link
Contributor Author

dok-net commented Jun 12, 2019

@devyte I've a bug report against EspSoftwareSerial that I expect to fix within 24h, which will bring a new release of the package into focus. Is there anything standing in the way of a positive review and merge of this mostly-pure-bugfix PR? The additional exposing of attachInterruptArg() is just alignment with ESP32 and is also due, I'd like to add.

@dok-net dok-net force-pushed the bugfix/attachInterrupt branch 4 times, most recently from 69e56ed to b41d5c6 Compare June 21, 2019 12:08
@dok-net dok-net force-pushed the bugfix/attachInterrupt branch 2 times, most recently from 4bf3c05 to fac85ec Compare June 25, 2019 10:25
@dok-net dok-net force-pushed the bugfix/attachInterrupt branch 2 times, most recently from 2c6ca16 to ad3028d Compare June 26, 2019 06:17
dok-net added 4 commits June 27, 2019 20:26
(cherry picked from commit 15c0b5b356aad0c3032b96ed6db0ec70cbf719d3)

# Conflicts:
#	cores/esp8266/core_esp8266_wiring_digital.cpp
@dok-net dok-net force-pushed the bugfix/attachInterrupt branch from ad3028d to c3d359c Compare June 27, 2019 18:29
@dok-net
Copy link
Contributor Author

dok-net commented Jun 28, 2019

@devyte I was asked by d-a-v to close the lesser of those PRs fixing the same problem. #6047 supersedes this one, but is much more complex, where this here PR is just a few lines. So please understand that I personally would not close it and hope for an iterative approach - rebasing #6047 on this PR is not challenging.

@devyte devyte merged commit 93a52f9 into esp8266:master Jul 4, 2019
@dok-net dok-net deleted the bugfix/attachInterrupt branch July 4, 2019 05:37
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.

detachInterrupt crashes after using argument in __attachInterruptArg()
3 participants