Skip to content

Commit 33d5f98

Browse files
Update per review comments
1 parent 29dc460 commit 33d5f98

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

doc/reference.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,33 @@ and have several limitations:
99

1010
* Interrupt callback functions must be in IRAM, because the flash may be
1111
in the middle of other operations when they occur. Do this by adding
12-
the ``ICACHE_RAM_ATTR`` attribute on the function definition.
13-
14-
* Interrupts should not perform delay() or any long-running (>1ms) task.
15-
WiFi and other portiong of the code can become unstable if interrupts
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
1625
are blocked by a long-running interrupt. If you have much to do, you can
1726
set a volatile global flag that your main ``loop()`` can check each pass
18-
or use a scheduled function (which will be called by the OS when it is
19-
safe, and not at IRQ level) to do the work.
20-
21-
* Memory operations can be dangerous and avoided in interrupts. Calls to
22-
``new`` or ``malloc`` should be minimized, and calls to ``realloc`` and
23-
``free`` must NEVER be used.
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.).
2439

2540
Digital IO
2641
----------

0 commit comments

Comments
 (0)