-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Documentation: added suggested introduction to interrupt handlers #1691
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
Wow, thanks! I'll have to read through it properly but it looks good. "Why can't I allocate in an ISR" is a very common problem, and this should help (or at least provide a place to refer people to). Eventually it'll be nice to have "soft ISR" where response is less fast but you can allocate on the heap (as per a discussion elsewhere); and/or actually be able to allocate during a hardware ISR; and/or OS-level threads. But I still think this discussion about restrictions on ISRs is useful, especially for people new to embedded stuff, and especially because uPy uses a heap more than traditional C. |
All reactions
Sorry, something went wrong.
self.led.toggle() | ||
|
||
red = Foo(pyb.Timer(4, freq=1), pyb.LED(1)) | ||
greeen = Foo(pyb.Timer(2, freq=0.8), pyb.LED(2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there needs to be a paragraph here which describes the code above, what the interrupts are and what they call. Would also be good to explain that self.cb is a bound method which is how different state is passed around.
Sorry, something went wrong.
All reactions
After reading this interrupts sound pretty scary! I really think we need to implement "soft interrupts" which would alleviate almost all problems outlined in this document. But of course still allow hard interrupts when they are needed. I think the text needs a section "Tips and recommended practices" which is a sort of TL/DR section stating things like:
On a separate but related note, I will make a document describing things that do and don't allocate on the heap. That will help a lot to know what code you can write in a hard isr. |
All reactions
Sorry, something went wrong.
I've attempted to address these points. Is the concept of a "soft interrupt" detailed anywhere? It sounds intriguing. |
All reactions
Sorry, something went wrong.
Thank you! Merged in 521759e. |
All reactions
Sorry, something went wrong.
The new docs seem to lack links to this section. An entry under "The MicroPython language" and a link from tutorial section "5. The Switch, callbacks and interrupts" would help people find it. |
All reactions
Sorry, something went wrong.
The link under "The MP Language" is already there, just maybe it wasn't built correctly when you looked at it. And I just added a link from section 5 of the pyboard tutorial, in 1d191fd. Thanks for the tip! |
All reactions
Sorry, something went wrong.
NOT TESTED! Just compiles Fixes micropython#1691
Successfully merging this pull request may close these issues.
File added docs/reference/isr_rules.rst
Regular questions in the forum indicated the need for a basic introduction to the topic of writing interrupt callbacks, and this proposed addition stems from this discussion
http://forum.micropython.org/viewtopic.php?f=6&t=1156
The text can be viewed here http://hinch.me.uk/html/reference/isr_rules.html