diff options
author | Peter Hinch <peter@hinch.me.uk> | 2016-09-06 11:20:22 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-09-07 17:12:42 +1000 |
commit | dab0f316d26f4c77c94d9e51c35d5f63ed118d3c (patch) | |
tree | 81b76dbdda6a20aaab59f3b8d1b2ab6534dd8fb5 | |
parent | 742d8bdbe46274401aa261881d14dee50a7618d5 (diff) | |
download | micropython-dab0f316d26f4c77c94d9e51c35d5f63ed118d3c.tar.gz micropython-dab0f316d26f4c77c94d9e51c35d5f63ed118d3c.zip |
docs/reference/isr_rules.rst: Two minor additions to docs for using ISR.
- Refers to the technique of instantiating an object for use in an ISR by
specifying it as a default argument.
- Footnote detailing the fact that interrupt handlers continue to be
executed at the REPL.
-rw-r--r-- | docs/reference/isr_rules.rst | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/docs/reference/isr_rules.rst b/docs/reference/isr_rules.rst index b33e4dd6f2..23dcfd01f4 100644 --- a/docs/reference/isr_rules.rst +++ b/docs/reference/isr_rules.rst @@ -110,6 +110,19 @@ the flag. The memory allocation occurs in the main program code when the object The MicroPython library I/O methods usually provide an option to use a pre-allocated buffer. For example ``pyb.i2c.recv()`` can accept a mutable buffer as its first argument: this enables its use in an ISR. +A means of creating an object without employing a class or globals is as follows: + +.. code:: python + + def set_volume(t, buf=bytearray(3)): + buf[0] = 0xa5 + buf[1] = t >> 4 + buf[2] = 0x5a + return buf + +The compiler instantiates the default ``buf`` argument when the function is +loaded for the first time (usually when the module it's in is imported). + Use of Python objects ~~~~~~~~~~~~~~~~~~~~~ @@ -300,3 +313,20 @@ that access to the critical variables is denied. A simple example of a mutex may but only for the duration of eight machine instructions: the benefit of this approach is that other interrupts are virtually unaffected. +Interrupts and the REPL +~~~~~~~~~~~~~~~~~~~~~~~ + +Interrupt handlers, such as those associated with timers, can continue to run +after a program terminates. This may produce unexpected results where you might +have expected the object raising the callback to have gone out of scope. For +example on the Pyboard: + +.. code:: python + + def bar(): + foo = pyb.Timer(2, freq=4, callback=lambda t: print('.', end='')) + + bar() + +This continues to run until the timer is explicitly disabled or the board is +reset with ``ctrl D``. |