10000 Documentation: added suggested introduction to interrupt handlers by peterhinch · Pull Request #1691 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
wants to merge 5 commits into from
Closed

Conversation

peterhinch
Copy link
Contributor

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

@dpgeorge
Copy link
Member
dpgeorge commented Dec 8, 2015

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.

@dpgeorge dpgeorge mentioned this pull request Dec 24, 2015
2 tasks
self.led.toggle()

red = Foo(pyb.Timer(4, freq=1), pyb.LED(1))
greeen = Foo(pyb.Timer(2, freq=0.8), pyb.LED(2))
Copy link
Member

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.

@dpgeorge
Copy link
Member

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:

  • keep isrs short
  • don't allocate heap memory (eg no list append, dict inserts)
  • use preallocated bytearray (or array.array) objects to share data
  • use disable/enable irq in the main code to protect critical sections

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.

@peterhinch
Copy link
Contributor Author
8000

I've attempted to address these points. Is the concept of a "soft interrupt" detailed anywhere? It sounds intriguing.

@dpgeorge
Copy link
Member

Thank you! Merged in 521759e.

@dpgeorge dpgeorge closed this Dec 31, 2015
@peterhinch
Copy link
Contributor Author

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.

@dpgeorge
Copy link
Member
dpgeorge commented Jan 4, 2016

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!

tannewt added a commit to tannewt/circuitpython that referenced this pull request Aug 22, 2019
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
0