From 3bec5fedb9261bc7787297beb5d222340aff61e5 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Sun, 15 Mar 2026 13:49:13 +0100 Subject: [PATCH] agc reset fix --- .../patches/zephyr/0003-lora-sx126x-native.patch | 7 ++++++- zephcore/src/Dispatcher.cpp | 16 ++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/zephcore/patches/zephyr/0003-lora-sx126x-native.patch b/zephcore/patches/zephyr/0003-lora-sx126x-native.patch index 3994d04..ecf28c3 100644 --- a/zephcore/patches/zephyr/0003-lora-sx126x-native.patch +++ b/zephcore/patches/zephyr/0003-lora-sx126x-native.patch @@ -403,7 +403,7 @@ index 7b0b67f89d5..7154eb074ce 100644 /* Start transmission with 10 second timeout */ ret = sx126x_set_tx(dev, 10000); if (ret < 0) { -@@ -1038,6 +1260,121 @@ static int sx126x_lora_test_cw(const struct device *dev, uint32_t frequency, +@@ -1038,6 +1260,126 @@ static int sx126x_lora_test_cw(const struct device *dev, uint32_t frequency, return 0; } @@ -519,6 +519,11 @@ index 7b0b67f89d5..7154eb074ce 100644 + sx126x_set_rx_gain(dev, true); + } + ++ /* Chip is now in STANDBY. Update state so lora_recv_async() can ++ * transition back to RX — without this, the CAS(REST→RX) fails ++ * because state was still SX126X_STATE_RX from before the reset. */ ++ atomic_set(&data->state, SX126X_STATE_IDLE); ++ + k_mutex_unlock(&data->lock); +} + diff --git a/zephcore/src/Dispatcher.cpp b/zephcore/src/Dispatcher.cpp index 45c8641..fd9d3f6 100644 --- a/zephcore/src/Dispatcher.cpp +++ b/zephcore/src/Dispatcher.cpp @@ -133,15 +133,19 @@ void Dispatcher::maintenanceLoop() /* Noise floor calibration — one EMA tick per housekeeping cycle */ _radio->triggerNoiseFloorCalibrate(getInterferenceThreshold()); - /* RX mode watchdog — detect if radio is stuck outside RX */ - bool is_recv = _radio->isInRecvMode(); - if (is_recv != prev_isrecv_mode) { - prev_isrecv_mode = is_recv; - if (!is_recv) { + /* RX mode watchdog — detect if radio is stuck in neither RX nor TX. + * Count TX time as "active" so rapid consecutive relays on a busy + * repeater don't falsely trigger the flag: the housekeeping timer + * (5 s) can miss brief RX windows between TXes, leaving + * radio_nonrx_start stale and firing the watchdog spuriously. */ + bool is_active = _radio->isInRecvMode() || !_radio->isSendComplete(); + if (is_active != prev_isrecv_mode) { + prev_isrecv_mode = is_active; + if (!is_active) { radio_nonrx_start = (uint32_t)_ms->getMillis(); } } - if (!is_recv && (uint32_t)_ms->getMillis() - radio_nonrx_start > 8000) { + if (!is_active && (uint32_t)_ms->getMillis() - radio_nonrx_start > 8000) { _err_flags |= ERR_EVENT_STARTRX_TIMEOUT; }