Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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

[isr_rules]: https://docs.micropython.org/en/latest/reference/isr_rules.html
5 changes: 2 additions & 3 deletions micropython/lora/lora-async/lora/async_modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ async def _wait(self, will_irq, idx, timeout_ms):
if _DEBUG:
print(f"wait complete")

def _callback(self, _):
# IRQ callback from BaseModem._radio_isr. Hard IRQ context unless _DEBUG
# is on.
def _callback(self):
# IRQ callback from BaseModem._radio_isr. May be in Hard IRQ context.
#
# Set both RX & TX flag. This isn't necessary for "real" interrupts, but may be necessary
# to wake both for the case of a "soft" interrupt triggered by sleep() or standby(), where
Expand Down
2 changes: 1 addition & 1 deletion micropython/lora/lora-async/manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metadata(version="0.1.0")
metadata(version="0.1.1")
require("lora")
package("lora")
22 changes: 6 additions & 16 deletions micropython/lora/lora/lora/modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,16 @@ def get_time_on_air_us(self, payload_len):
#
# ISR implementation is relatively simple, just exists to signal an optional
# callback, record a timestamp, and wake up the hardware if
# needed. ppplication code is expected to call poll_send() or
# needed. Application code is expected to call poll_send() or
# poll_recv() as applicable in order to confirm the modem state.
#
# This is a MP hard irq in some configurations, meaning no memory allocation is possible.
#
# 'pin' may also be None if this is a "soft" IRQ triggered after a receive
# timed out during a send (meaning no receive IRQ will fire, but the
# receiver should wake up and move on anyhow.)
def _radio_isr(self, pin):
# This is a MP hard irq in some configurations.
def _radio_isr(self, _):
self._last_irq = time.ticks_ms()
if self._irq_callback:
self._irq_callback(pin)
self._irq_callback()
if _DEBUG:
# Note: this may cause a MemoryError and fail if _DEBUG is enabled in this base class
# but disabled in the subclass, meaning this is a hard irq handler
try:
print("_radio_isr pin={}".format(pin))
except MemoryError:
pass
print("_radio_isr")

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

def _get_last_irq(self):
Expand Down
2 changes: 1 addition & 1 deletion micropython/lora/lora/manifest.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
metadata(version="0.1.0")
metadata(version="0.1.1")
package("lora")