What's interrupt-safe?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
jugglerchris
Posts: 1
Joined: Wed May 14, 2014 7:53 pm

What's interrupt-safe?

Post by jugglerchris » Wed May 14, 2014 8:13 pm

Hi,

I'm trying to understand what you can do in a Python interrupt routine. The only documentation I've found (http://wiki.micropython.org/pyb-Pin) just says you can do anything as long as you don't allocate memory (because of the GC). Sorry if I've missed anything!

However, this doesn't sound like the whole story, and I have some questions. :-)

First group - what's safe to do in normal code, to variables which might also be accessed from interrupt code?
* Is assigning to a global variable safe?
* Assigning to a variable visible from an interrupt via closure variables?
* Assigning to a list item? Dict key?
* Appending to a list which interrupt code might read/write from?
* Modifying a dict? (eg a module dict)
* etc. - I think it's important to be sure of the rules.

Second group - what help is there for writing safe interrupt code?
* Will the compiler/runtime raise an error if a function happens to allocate during interrupt code, or just crash randomly when you're unlucky enough to do so during GC?
* I guess there will be gotchas - eg an integer counter works fine until it hits 2^31, when the variable suddenly doesn't fit in a tagged integer.

Thanks,

Chris

Post Reply