diff --git a/src/helpers/radiolib/RadioLibWrappers.cpp b/src/helpers/radiolib/RadioLibWrappers.cpp index f6afbaaff..7e5e1acfb 100644 --- a/src/helpers/radiolib/RadioLibWrappers.cpp +++ b/src/helpers/radiolib/RadioLibWrappers.cpp @@ -194,6 +194,18 @@ int16_t RadioLibWrapper::performChannelScan() { bool RadioLibWrapper::isChannelActive() { if (isAS923_1_JP()) { + // Non-blocking backoff: if a prior busy detection armed a backoff wait, + // report busy and let Dispatcher::checkSend() re-poll on the next loop() + // pass instead of spin-waiting here (which used to block the Dispatcher + // loop for up to 16s). + if (_lbt_backoff_active) { + if ((int32_t)(millis() - _lbt_deadline) < 0) { + return true; // still waiting; re-checked next call + } + _lbt_backoff_active = false; + return isChannelActive(); // backoff elapsed -- re-sense (bounded, single-level recursion) + } + // ARIB STD-T108: 5ms continuous RSSI sensing, -80dBm absolute threshold uint32_t sense_start = millis(); while (millis() - sense_start < 5) { @@ -201,10 +213,8 @@ bool RadioLibWrapper::isChannelActive() { _busy_count++; uint32_t base_ms = 2000; uint32_t max_backoff = min(base_ms * (1u << _busy_count), (uint32_t)16000); - uint32_t backoff_until = millis() + random(max_backoff / 2, max_backoff); - while (millis() < backoff_until) { - YIELD_TASK(); - } + _lbt_deadline = millis() + random(max_backoff / 2, max_backoff); + _lbt_backoff_active = true; return true; } YIELD_TASK(); diff --git a/src/helpers/radiolib/RadioLibWrappers.h b/src/helpers/radiolib/RadioLibWrappers.h index 699b31223..b58ac8ab0 100644 --- a/src/helpers/radiolib/RadioLibWrappers.h +++ b/src/helpers/radiolib/RadioLibWrappers.h @@ -20,6 +20,9 @@ protected: int32_t _floor_sample_sum; uint8_t _preamble_sf; + bool _lbt_backoff_active; // non-blocking wait after RSSI busy detection (up to 16s) + uint32_t _lbt_deadline; + void idle(); void startRecv(); float packetScoreInt(float snr, int sf, int packet_len); @@ -27,7 +30,7 @@ protected: virtual void doResetAGC(); public: - RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board), _busy_count(0), _preamble_sf(0) { n_recv = n_sent = 0; } + RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board), _busy_count(0), _preamble_sf(0), _lbt_backoff_active(false), _lbt_deadline(0) { n_recv = n_sent = 0; } void begin() override; virtual void powerOff() { _radio->sleep(); }