Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit dab0f31

Browse files
peterhinchdpgeorge
authored andcommitted
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.
1 parent 742d8bd commit dab0f31

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/reference/isr_rules.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ the flag. The memory allocation occurs in the main program code when the object
110110
The MicroPython library I/O methods usually provide an option to use a pre-allocated buffer. For
111111
example ``pyb.i2c.recv()`` can accept a mutable buffer as its first argument: this enables its use in an ISR.
112112

113+
A means of creating an object without employing a class or globals is as follows:
114+
115+
.. code:: python
116+
117+
def set_volume(t, buf=bytearray(3)):
118+
buf[0] = 0xa5
119+
buf[1] = t >> 4
120+
buf[2] = 0x5a
121+
return buf
122+
123+
The compiler instantiates the default ``buf`` argument when the function is
124+
loaded for the first time (usually when the module it's in is imported).
125+
113126
Use of Python objects
114127
~~~~~~~~~~~~~~~~~~~~~
115128

@@ -300,3 +313,20 @@ that access to the critical variables is denied. A simple example of a mutex may
300313
but only for the duration of eight machine instructions: the benefit of this approach is that other interrupts are
301314
virtually unaffected.
302315

316+
Interrupts and the REPL
317+
~~~~~~~~~~~~~~~~~~~~~~~
318+
319+
Interrupt handlers, such as those associated with timers, can continue to run
320+
after a program terminates. This may produce unexpected results where you might
321+
have expected the object raising the callback to have gone out of scope. For
322+
example on the Pyboard:
323+
324+
.. code:: python
325+
326+
def bar():
327+
foo = pyb.Timer(2, freq=4, callback=lambda t: print('.', end=''))
328+
329+
bar()
330+
331+
This continues to run until the timer is explicitly disabled or the board is
332+
reset with ``ctrl D``.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy