Skip to content

Commit 93bf707

Browse files
projectgusdpgeorge
authored andcommitted
lora: Remove the pin parameter from IRQ callback.
It's not necessary to know which pin triggered the IRQ, and it saves some code size. Signed-off-by: Angus Gratton <[email protected]>
1 parent dc765ad commit 93bf707

File tree

5 files changed

+18
-27
lines changed

5 files changed

+18
-27
lines changed

micropython/lora/README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,12 @@ following different approaches:
10281028
`poll_send()` now?" check function if there's no easy way to determine
10291029
which interrupt has woken the board up.
10301030
* Implement a custom interrupt callback function and call
1031-
`modem.set_irq_callback()` to install it. The function will be called with a
1032-
single argument, which is either the `Pin` that triggered a hardware interrupt
1033-
or `None` for a soft interrupt. Refer to the documentation about [writing interrupt
1034-
handlers](https://docs.micropython.org/en/latest/reference/isr_rules.html) for
1035-
more information. The `lora-async` modem classes install their own callback here,
1036-
so it's not possible to mix this approach with the provided asynchronous API.
1031+
`modem.set_irq_callback()` to install it. The function will be called if a
1032+
hardware interrupt occurs, possibly in hard interrupt context. Refer to the
1033+
documentation about [writing interrupt handlers][isr_rules] for more
1034+
information. It may also be called if the driver triggers a soft interrupt.
1035+
The `lora-async` modem classes install their own callback here, so it's not
1036+
possible to mix this approach with the provided asynchronous API.
10371037
* Call `modem.poll_recv()` or `modem.poll_send()`. This takes more time
10381038
and uses more power as it reads the modem IRQ status directly from the modem
10391039
via SPI, but it also give the most definite result.
@@ -1154,3 +1154,5 @@ Usually, this means the constructor parameter `dio3_tcxo_millivolts` (see above)
11541154
must be set as the SX126x chip DIO3 output pin is the power source for the TCXO
11551155
connected to the modem. Often this parameter should be set to `3300` (3.3V) but
11561156
it may be another value, consult the documentation for your LoRa modem module.
1157+
1158+
[isr_rules]: https://docs.micropython.org/en/latest/reference/isr_rules.html

micropython/lora/lora-async/lora/async_modem.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ async def _wait(self, will_irq, idx, timeout_ms):
111111
if _DEBUG:
112112
print(f"wait complete")
113113

114-
def _callback(self, _):
115-
# IRQ callback from BaseModem._radio_isr. Hard IRQ context unless _DEBUG
116-
# is on.
114+
def _callback(self):
115+
# IRQ callback from BaseModem._radio_isr. May be in Hard IRQ context.
117116
#
118117
# Set both RX & TX flag. This isn't necessary for "real" interrupts, but may be necessary
119118
# to wake both for the case of a "soft" interrupt triggered by sleep() or standby(), where
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.1.0")
1+
metadata(version="0.1.1")
22
require("lora")
33
package("lora")

micropython/lora/lora/lora/modem.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,16 @@ def get_time_on_air_us(self, payload_len):
233233
#
234234
# ISR implementation is relatively simple, just exists to signal an optional
235235
# callback, record a timestamp, and wake up the hardware if
236-
# needed. ppplication code is expected to call poll_send() or
236+
# needed. Application code is expected to call poll_send() or
237237
# poll_recv() as applicable in order to confirm the modem state.
238238
#
239-
# This is a MP hard irq in some configurations, meaning no memory allocation is possible.
240-
#
241-
# 'pin' may also be None if this is a "soft" IRQ triggered after a receive
242-
# timed out during a send (meaning no receive IRQ will fire, but the
243-
# receiver should wake up and move on anyhow.)
244-
def _radio_isr(self, pin):
239+
# This is a MP hard irq in some configurations.
240+
def _radio_isr(self, _):
245241
self._last_irq = time.ticks_ms()
246242
if self._irq_callback:
247-
self._irq_callback(pin)
243+
self._irq_callback()
248244
if _DEBUG:
249-
# Note: this may cause a MemoryError and fail if _DEBUG is enabled in this base class
250-
# but disabled in the subclass, meaning this is a hard irq handler
251-
try:
252-
print("_radio_isr pin={}".format(pin))
253-
except MemoryError:
254-
pass
245+
print("_radio_isr")
255246

256247
def irq_triggered(self):
257248
# Returns True if the ISR has executed since the last time a send or a receive
@@ -264,8 +255,7 @@ def set_irq_callback(self, callback):
264255
# This is used by the AsyncModem implementation, but can be called in
265256
# other circumstances to implement custom ISR logic.
266257
#
267-
# Note that callback may be called in hard ISR context, meaning no
268-
# memory allocation is possible.
258+
# Note that callback may be called in hard ISR context.
269259
self._irq_callback = callback
270260

271261
def _get_last_irq(self):

micropython/lora/lora/manifest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
metadata(version="0.1.0")
1+
metadata(version="0.1.1")
22
package("lora")

0 commit comments

Comments
 (0)