Crate umsh_radio_loraphy

Crate umsh_radio_loraphy 

Source
Expand description

lora-phy-backed LoRa radio driver implementing umsh_hal::Radio.

Works with any chip that implements lora_phy::mod_traits::RadioKind (SX126x, LR11xx, etc.). Per-board parameters (frequency, modulation, preamble, TCXO, RF switch) are supplied by the caller — this crate only owns the RX/TX state machine.

§Architecture

Two concurrent actors share a Channels bundle:

  1. runner — an Embassy task that owns the lora_phy::LoRa instance. It loops between continuous RX and TX: when a TX request arrives on the TX channel it exits RX, transmits, signals the result, then re-enters RX. A request that arrives while a frame is being received is refused with TxError::CadTimeout (up to RX_GATE_MAX_STRIKES times) instead of tearing down the reception — the channel is busy either way, and the MAC already backs off and retries on that error.

  2. LoraphyRadio — a lightweight handle used by the MAC coordinator. It borrows &'static Channels for transmit() (sends request, awaits result signal) and poll_receive() (non-blocking probe of the RX channel with waker registration via AtomicWaker).

§Usage

use umsh_radio_loraphy::{Channels, LoraphyRadio};
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;

static RADIO_CH: Channels<ThreadModeRawMutex, 4, 2> = Channels::new();
// Spawn runner(lora, &RADIO_CH, mdltn, rx_pkt, tx_pkt, power_dbm).
// Pass LoraphyRadio::new(&RADIO_CH, t_frame_ms) to the MAC.

Structs§

Channels
Shared state between LoraphyRadio and runner. Place in a static.
DeviceControl
Control handle for device_runner: latest-wins settings updates and on-demand instantaneous-RSSI sampling. Place in a static next to the Channels.
DeviceSettings
Radio settings applied at runtime by the ULCP session.
LoraphyRadio
Implements umsh_hal::Radio over the shared Channels.
RxFrame
A received frame plus signal metadata.
TxRequest
A queued transmit request from the MAC to the runner task.

Enums§

CadPolicy
Channel-activity-detection (CAD) policy applied before a transmit.
TxError
Error returned by [Radio::transmit].

Constants§

MAX_PAYLOAD
Maximum SX1262 LoRa payload: 255 bytes.
MESHCORE_US_FREQUENCY_HZ
MeshCore US band frequency (confirmed from MeshCore source).
RX_GATE_MAX_STRIKES
Maximum consecutive TX requests refused with TxError::CadTimeout while a reception appears to be in progress (preamble seen, frame not finished).
UMSH_FREQUENCY_HZ
Frequency used by default for UMSH in the 915 MHz ISM band.

Functions§

airtime_ms
Conservative upper bound on LoRa on-air time in milliseconds.
bandwidth_from_hz
Convert a bandwidth in Hz (the ULCP representation) to the lora-phy enum. Returns None for unsupported values.
coding_rate_from_denom
Convert a coding-rate denominator (5 for 4/5 .. 8 for 4/8) to the lora-phy enum.
default_params
Build the default modulation and packet parameters for UMSH bringup.
device_runner
Device variant of runner: same RX/TX state machine, but the modulation parameters, frequency, and power come from an DeviceControl at runtime instead of being fixed at spawn.
meshcore_us_params
Build modulation + packet parameters matching MeshCore US (915 MHz band).
runner
Background loop: owns the lora_phy::LoRa instance, switches between continuous RX and TX as requests arrive. Never returns.
spreading_factor_from_u8
Convert a numeric spreading factor (5-12) to the lora-phy enum.