From 14f33c963781daee6e899db6674385d8dd7c17d1 Mon Sep 17 00:00:00 2001 From: fredmcc Date: Sun, 13 Jul 2025 19:15:40 +1000 Subject: [PATCH] Removed potential lock up conditions when sending a packet if the TX buffer is full or transmission does not complete --- src/ESP32SJA1000.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/ESP32SJA1000.cpp b/src/ESP32SJA1000.cpp index 309e030..02adb02 100644 --- a/src/ESP32SJA1000.cpp +++ b/src/ESP32SJA1000.cpp @@ -168,9 +168,9 @@ int ESP32SJA1000Class::endPacket() return 0; } - // wait for TX buffer to free - while ((readRegister(REG_SR) & 0x04) != 0x04) { - yield(); + // return if TX buffer is not free + if ((readRegister(REG_SR) & 0x04) != 0x04) { + return 0; } int dataReg; @@ -203,15 +203,6 @@ int ESP32SJA1000Class::endPacket() modifyRegister(REG_CMR, 0x1f, 0x01); } - // wait for TX complete - while ((readRegister(REG_SR) & 0x08) != 0x08) { - if (readRegister(REG_ECC) == 0xd9) { - modifyRegister(REG_CMR, 0x1f, 0x02); // error, abort - return 0; - } - yield(); - } - return 1; }