diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-06-14 18:56:51 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-06-14 18:56:51 +0300 |
commit | 22044dd6e76fc8f4f568a6235b22045744d8e3d5 (patch) | |
tree | 6a59294bcb5e5afcd5b06dbbb7bd7c7ee4713430 | |
parent | a7fde45b618c76c03516696d670dd665282873da (diff) |
Changed interface to CanDevice in CoreN2G to count Tx errs per buffer
Also adjusted some CAN timeouts
-rw-r--r-- | src/CAN/CanInterface.cpp | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/src/CAN/CanInterface.cpp b/src/CAN/CanInterface.cpp index 710f14e9..daf73f13 100644 --- a/src/CAN/CanInterface.cpp +++ b/src/CAN/CanInterface.cpp @@ -36,11 +36,11 @@ const unsigned int NumCanBuffers = 2 * MaxCanBoards + 10; -constexpr uint32_t MaxMotionSendWait = 100; // milliseconds +constexpr uint32_t MaxMotionSendWait = 20; // milliseconds constexpr uint32_t MaxUrgentSendWait = 20; // milliseconds constexpr uint32_t MaxTimeSyncSendWait = 2; // milliseconds -constexpr uint32_t MaxResponseSendWait = 50; // milliseconds -constexpr uint32_t MaxRequestSendWait = 50; // milliseconds +constexpr uint32_t MaxResponseSendWait = 200; // milliseconds +constexpr uint32_t MaxRequestSendWait = 200; // milliseconds constexpr uint16_t MaxTimeSyncDelay = 300; // the maximum normal delay before a can time sync message is sent #define USE_BIT_RATE_SWITCH 0 @@ -125,6 +125,9 @@ static uint32_t can0Memory[Can0Config.GetMemorySize()] __attribute__ ((section ( static CanDevice *can0dev = nullptr; +static unsigned int txTimeouts[Can0Config.numTxBuffers + 1] = { 0 }; +static uint32_t lastCancelledId = 0; + #if SAME70 && defined(DUAL_CAN) constexpr CanDevice::Config Can1Config = @@ -359,6 +362,17 @@ uint16_t CanInterface::GetTimeStampPeriod() noexcept #endif +// Send a message on the CAN FD channel and reord any errors +static void SendCanMessage(CanDevice::TxBufferNumber whichBuffer, uint32_t timeout, CanMessageBuffer *buffer) noexcept +{ + const uint32_t cancelledId = can0dev->SendMessage(whichBuffer, timeout, buffer); + if (cancelledId != 0) + { + ++txTimeouts[(unsigned int)whichBuffer]; + lastCancelledId = cancelledId; + } +} + //TODO can we get rid of the CanSender task if we send movement messages via the Tx FIFO? // This task picks up motion messages and sends them extern "C" [[noreturn]] void CanSenderLoop(void *) noexcept @@ -371,7 +385,7 @@ extern "C" [[noreturn]] void CanSenderLoop(void *) noexcept CanMessageBuffer * const urgentMessage = CanMotion::GetUrgentMessage(); if (urgentMessage != nullptr) { - can0dev->SendMessage(TxBufferIndexUrgent, MaxUrgentSendWait, urgentMessage); + SendCanMessage(TxBufferIndexUrgent, MaxUrgentSendWait, urgentMessage); } else if (pendingMotionBuffers != nullptr) { @@ -386,7 +400,7 @@ extern "C" [[noreturn]] void CanSenderLoop(void *) noexcept } // Send the message - can0dev->SendMessage(TxBufferIndexMotion, MaxMotionSendWait, buf); + SendCanMessage(TxBufferIndexMotion, MaxMotionSendWait, buf); #ifdef CAN_DEBUG // Display a debug message too @@ -474,7 +488,7 @@ extern "C" [[noreturn]] void CanClockLoop(void *) noexcept } #endif msg->timeSent = lastTimeSent; - can0dev->SendMessage(TxBufferIndexTimeSync, 0, &buf); + SendCanMessage(TxBufferIndexTimeSync, 0, &buf); ++timeSyncMessagesSent; } @@ -674,7 +688,7 @@ GCodeResult CanInterface::SendRequestAndGetCustomReply(CanMessageBuffer *buf, Ca // This code isn't re-entrant and it can get called from a task other than Main to shut the system down, so we need to use a mutex MutexLocker lock(transactionMutex); - can0dev->SendMessage(TxBufferIndexRequest, MaxRequestSendWait, buf); + SendCanMessage(TxBufferIndexRequest, MaxRequestSendWait, buf); const uint32_t whenStartedWaiting = millis(); unsigned int fragmentsReceived = 0; for (;;) @@ -754,7 +768,7 @@ GCodeResult CanInterface::SendRequestAndGetCustomReply(CanMessageBuffer *buf, Ca // Send a response to an expansion board and free the buffer void CanInterface::SendResponseNoFree(CanMessageBuffer *buf) noexcept { - can0dev->SendMessage(TxBufferIndexResponse, MaxResponseSendWait, buf); + SendCanMessage(TxBufferIndexResponse, MaxResponseSendWait, buf); } // Send a broadcast message and free the buffer @@ -762,7 +776,7 @@ void CanInterface::SendBroadcastNoFree(CanMessageBuffer *buf) noexcept { if (can0dev != nullptr) { - can0dev->SendMessage(TxBufferIndexBroadcast, MaxResponseSendWait, buf); + SendCanMessage(TxBufferIndexBroadcast, MaxResponseSendWait, buf); } } @@ -771,7 +785,7 @@ void CanInterface::SendMessageNoReplyNoFree(CanMessageBuffer *buf) noexcept { if (can0dev != nullptr) { - can0dev->SendMessage(TxBufferIndexBroadcast, MaxResponseSendWait, buf); + SendCanMessage(TxBufferIndexBroadcast, MaxResponseSendWait, buf); } } @@ -1101,31 +1115,41 @@ GCodeResult CanInterface::ReadRemoteHandles(CanAddress boardAddress, RemoteInput void CanInterface::Diagnostics(MessageType mtype) noexcept { - unsigned int messagesQueuedForSending, messagesReceived, txTimeouts, messagesLost, busOffCount; - uint32_t lastCancelledId; - can0dev->GetAndClearStats(messagesQueuedForSending, messagesReceived, txTimeouts, messagesLost, busOffCount, lastCancelledId); + unsigned int messagesQueuedForSending, messagesReceived, messagesLost, busOffCount; + can0dev->GetAndClearStats(messagesQueuedForSending, messagesReceived, messagesLost, busOffCount); reprap.GetPlatform().MessageF(mtype, - "=== CAN ===\nMessages queued %u, send timeouts %u, received %u, lost %u, longest wait %" PRIu32 "ms for reply type %u" + "=== CAN ===\nMessages queued %u, received %u, lost %u, longest wait %" PRIu32 "ms for reply type %u" ", peak Tx sync delay %" PRIu32 ", free buffers %u (min %u)" //debug ", ts %u/%u/%u" //end debug "\n", - messagesQueuedForSending, txTimeouts, messagesReceived, messagesLost, longestWaitTime, longestWaitMessageType, + messagesQueuedForSending, messagesReceived, messagesLost, longestWaitTime, longestWaitMessageType, peakTimeSyncTxDelay, CanMessageBuffer::GetFreeBuffers(), CanMessageBuffer::GetAndClearMinFreeBuffers() //debug , timeSyncMessagesSent, goodTimeStamps, badTimeStamps //end debug ); + String<StringLength100> str; + char c = ' '; + for (unsigned int& txt : txTimeouts) + { + str.catf("%c%u", c, txt); + txt = 0; + c = ','; + } + if (lastCancelledId != 0) { CanId id; id.SetReceivedId(lastCancelledId); - reprap.GetPlatform().MessageF(mtype, "Last cancelled message type %u dest %u\n", (unsigned int)id.MsgType(), id.Dst()); + lastCancelledId = 0; + str.catf(" last cancelled message type %u dest %u\n", (unsigned int)id.MsgType(), id.Dst()); } + reprap.GetPlatform().MessageF(mtype, "Tx timeouts%s\n", str.c_str()); longestWaitTime = 0; longestWaitMessageType = 0; peakTimeSyncTxDelay = 0; |