From 8eb30454518b30a2b5e875fe74a0ad462f8f4c17 Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 17 Apr 2020 18:49:54 -0700 Subject: [PATCH] Fix #85, we were stalling sometimes on send while in ISR which is NEVER legal --- src/rf95/CustomRF95.cpp | 5 +++++ src/rf95/RH_RF95.cpp | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rf95/CustomRF95.cpp b/src/rf95/CustomRF95.cpp index 5dc5d0bb9..62c4ff8b3 100644 --- a/src/rf95/CustomRF95.cpp +++ b/src/rf95/CustomRF95.cpp @@ -54,6 +54,11 @@ ErrorCode CustomRF95::send(MeshPacket *p) DEBUG_MSG("immediate send on mesh fr=0x%x,to=0x%x,id=%d\n (txGood=%d,rxGood=%d,rxBad=%d)\n", p->from, p->to, p->id, txGood(), rxGood(), rxBad()); + waitPacketSent(); // Make sure we dont interrupt an outgoing message + + if (!waitCAD()) + return false; // Check channel activity + startSend(p); return ERRNO_OK; } else { diff --git a/src/rf95/RH_RF95.cpp b/src/rf95/RH_RF95.cpp index d08de8b1d..c29929637 100644 --- a/src/rf95/RH_RF95.cpp +++ b/src/rf95/RH_RF95.cpp @@ -280,17 +280,14 @@ void RH_RF95::clearRxBuf() ATOMIC_BLOCK_END; } +/// Note: This routine might be called from inside the RF95 ISR bool RH_RF95::send(const uint8_t *data, uint8_t len) { if (len > RH_RF95_MAX_MESSAGE_LEN) return false; - waitPacketSent(); // Make sure we dont interrupt an outgoing message setModeIdle(); - if (!waitCAD()) - return false; // Check channel activity - // Position at the beginning of the FIFO spiWrite(RH_RF95_REG_0D_FIFO_ADDR_PTR, 0); // The headers