From 0096f54ae9aa6f29bf0995a99ab0a7af4eeb04dd Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 30 Apr 2020 22:53:21 -0700 Subject: [PATCH] better debug output --- docs/software/nrf52-TODO.md | 2 +- src/mesh/MeshService.cpp | 3 ++- src/rf95/RF95Interface.cpp | 2 +- src/rf95/RadioLibInterface.cpp | 12 ++++++------ src/rf95/SX1262Interface.cpp | 5 +++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index fe4d7a614..323aa1e0e 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -5,7 +5,7 @@ Minimum items needed to make sure hardware is good. - add a hard fault handler -- at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug. keep packet sequence number in **attribute** ((section (".noinit"))) +- at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug. - use "variants" to get all gpio bindings - plug in correct variants for the real board - Use the PMU driver on real hardware diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 82d6921e1..6d8457aa0 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -61,7 +61,8 @@ static Periodic sendOwnerPeriod(sendOwnerCb); // FIXME, move this someplace better PacketId generatePacketId() { - static uint32_t i; + static uint32_t i __attribute__(( + section(".noinit"))); // We try to keep this in noinit so that hopefully it keeps increasing even across reboots i++; return (i % NUM_PACKET_ID) + 1; // return number between 1 and 255 diff --git a/src/rf95/RF95Interface.cpp b/src/rf95/RF95Interface.cpp index 988a95696..5cd6d6b03 100644 --- a/src/rf95/RF95Interface.cpp +++ b/src/rf95/RF95Interface.cpp @@ -89,8 +89,8 @@ void RF95Interface::setStandby() assert(err == ERR_NONE); isReceiving = false; // If we were receiving, not any more - completeSending(); // If we were sending, not anymore disableInterrupt(); + completeSending(); // If we were sending, not anymore } void RF95Interface::startReceive() diff --git a/src/rf95/RadioLibInterface.cpp b/src/rf95/RadioLibInterface.cpp index 21dc8271c..f067cd9fc 100644 --- a/src/rf95/RadioLibInterface.cpp +++ b/src/rf95/RadioLibInterface.cpp @@ -101,8 +101,8 @@ bool RadioLibInterface::canSleep() void RadioLibInterface::loop() { - PendingISR wasPending = pending; // atomic read - if (wasPending) { + PendingISR wasPending; + while ((wasPending = pending) != 0) { // atomic read pending = ISR_NONE; // If the flag was set, it is _guaranteed_ the ISR won't be running, because it masked itself if (wasPending == ISR_TX) @@ -130,8 +130,8 @@ void RadioLibInterface::startNextWork() void RadioLibInterface::handleTransmitInterrupt() { - DEBUG_MSG("handling lora TX interrupt\n"); - assert(sendingPacket); // Were we sending? + // DEBUG_MSG("handling lora TX interrupt\n"); + assert(sendingPacket); // Were we sending? - FIXME, this was null coming out of light sleep due to RF95 ISR! completeSending(); } @@ -140,6 +140,7 @@ void RadioLibInterface::completeSending() { if (sendingPacket) { txGood++; + DEBUG_MSG("Completed sending to=0x%x, id=%u\n", sendingPacket->to, sendingPacket->id); // We are done sending that packet, release it packetPool.release(sendingPacket); @@ -153,8 +154,6 @@ void RadioLibInterface::handleReceiveInterrupt() assert(isReceiving); isReceiving = false; - DEBUG_MSG("handling lora RX interrupt\n"); - // read the number of actually received bytes size_t length = iface->getPacketLength(); @@ -195,6 +194,7 @@ void RadioLibInterface::handleReceiveInterrupt() // parsing was successful, queue for our recipient mp->has_payload = true; rxGood++; + DEBUG_MSG("Lora RX interrupt from=0x%x, id=%u\n", mp->from, mp->id); deliverToReceiver(mp); } diff --git a/src/rf95/SX1262Interface.cpp b/src/rf95/SX1262Interface.cpp index af3e4603b..e69074e04 100644 --- a/src/rf95/SX1262Interface.cpp +++ b/src/rf95/SX1262Interface.cpp @@ -75,14 +75,15 @@ void SX1262Interface::setStandby() assert(err == ERR_NONE); isReceiving = false; // If we were receiving, not any more - completeSending(); // If we were sending, not anymore disableInterrupt(); + completeSending(); // If we were sending, not anymore } /** * Add SNR data to received messages */ -void SX1262Interface::addReceiveMetadata(MeshPacket *mp) { +void SX1262Interface::addReceiveMetadata(MeshPacket *mp) +{ mp->rx_snr = lora.getSNR(); }