Skip to content

Commit 4489e23

Browse files
Add interrupt section to docs (#6560)
* Add info about installing python3 on Mac, Linux The Mac requires special handholding to allow SSL connections for get.py, so document those for end users. * Add interrupt section to docs Adds a section on interrupts to the docs and lists the restrictions and warnings about running long tasks. Fixes #6428 * Update per review comments
1 parent c755771 commit 4489e23

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

doc/reference.rst

+36
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
Reference
22
=========
33

4+
Interrupts
5+
----------
6+
7+
Interrupts can be used on the ESP8266, but they must be used with care
8+
and have several limitations:
9+
10+
* Interrupt callback functions must be in IRAM, because the flash may be
11+
in the middle of other operations when they occur. Do this by adding
12+
the ``ICACHE_RAM_ATTR`` attribute on the function definition. If this
13+
attribute is not present, the sketch will crash when it attempts to
14+
``attachInterrupt`` with an error message.
15+
16+
.. code:: cpp
17+
18+
ICACHE_RAM_ATTR void gpio_change_handler(void *data) {...
19+
20+
* Interrupts must not call ``delay()`` or ``yield()``, or call any routines
21+
which internally use ``delay()`` or ``yield()`` either.
22+
23+
* Long-running (>1ms) tasks in interrupts will cause instabilty or crashes.
24+
WiFi and other portions of the core can become unstable if interrupts
25+
are blocked by a long-running interrupt. If you have much to do, you can
26+
set a volatile global flag that your main ``loop()`` can check each pass
27+
or use a scheduled function (which will be called outside of the interrupt
28+
context when it is safe) to do long-running work.
29+
30+
* Memory operations can be dangerous and should be avoided in interrupts.
31+
Calls to ``new`` or ``malloc`` should be minimized because they may require
32+
a long running time if memory is fragmented. Calls to ``realloc`` and
33+
``free`` must NEVER be called. Using any routines or objects which call
34+
``free`` or ``realloc`` themselves is also forbidden for the same reason.
35+
This means that ``String``, ``std::string``, ``std::vector`` and other
36+
classes which use contiguous memory that may be resized must be used with
37+
extreme care (ensuring strings aren't changed, vector elements aren't
38+
added, etc.).
39+
440
Digital IO
541
----------
642

0 commit comments

Comments
 (0)