From fb116c73f50be294763d5c4b99cf188991fcab75 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Wed, 13 Jul 2022 15:36:39 +0100 Subject: Fixes for main board used as expansion --- src/CAN/CanInterface.cpp | 83 ++++++++++++++++++++++++-------------- src/InputMonitors/InputMonitor.cpp | 2 +- 2 files changed, 54 insertions(+), 31 deletions(-) diff --git a/src/CAN/CanInterface.cpp b/src/CAN/CanInterface.cpp index 4c3a6739..31c43bd2 100644 --- a/src/CAN/CanInterface.cpp +++ b/src/CAN/CanInterface.cpp @@ -25,13 +25,13 @@ #include #include - #if HAS_SBC_INTERFACE # include "SBC/SbcInterface.h" #endif #if SUPPORT_REMOTE_COMMANDS # include +# include #endif #include @@ -420,7 +420,7 @@ uint16_t CanInterface::GetTimeStampPeriod() noexcept #endif -// Send a message on the CAN FD channel and reord any errors +// Send a message on the CAN FD channel and record any errors static void SendCanMessage(CanDevice::TxBufferNumber whichBuffer, uint32_t timeout, CanMessageBuffer *buffer) noexcept { const uint32_t cancelledId = can0dev->SendMessage(whichBuffer, timeout, buffer); @@ -437,46 +437,69 @@ extern "C" [[noreturn]] void CanSenderLoop(void *) noexcept { for (;;) { - TaskBase::Take(Mutex::TimeoutUnlimited); - for (;;) +#if SUPPORT_REMOTE_COMMANDS + if (inExpansionMode) { - CanMessageBuffer * const urgentMessage = CanMotion::GetUrgentMessage(); - if (urgentMessage != nullptr) + // In expansion mode this task just send notifications when the states of input handles change + CanMessageBuffer buf(nullptr); + auto msg = buf.SetupStatusMessage(CanInterface::GetCanAddress(), CanInterface::GetCurrentMasterAddress()); + msg->states = 0; + msg->zero = 0; + msg->numHandles = 0; + + const uint32_t timeToWait = InputMonitor::AddStateChanges(msg); + if (msg->numHandles != 0) { - SendCanMessage(TxBufferIndexUrgent, MaxUrgentSendWait, urgentMessage); + buf.dataLength = msg->GetActualDataLength(); + SendCanMessage(TxBufferIndexUrgent, MaxUrgentSendWait, &buf); } - else if (pendingMotionBuffers != nullptr) + TaskBase::Take(timeToWait); // wait until we are woken up because a message is available, or we time out + } + else +#endif + { + // In main board mode this task sends urgent messages concerning motion + for (;;) { - CanMessageBuffer *buf; + CanMessageBuffer * const urgentMessage = CanMotion::GetUrgentMessage(); + if (urgentMessage != nullptr) + { + SendCanMessage(TxBufferIndexUrgent, MaxUrgentSendWait, urgentMessage); + } + else if (pendingMotionBuffers != nullptr) { - TaskCriticalSectionLocker lock; - buf = pendingMotionBuffers; - pendingMotionBuffers = buf->next; + CanMessageBuffer *buf; + { + TaskCriticalSectionLocker lock; + buf = pendingMotionBuffers; + pendingMotionBuffers = buf->next; #if 0 //unused - --numPendingMotionBuffers; + --numPendingMotionBuffers; #endif - } + } - // Send the message - SendCanMessage(TxBufferIndexMotion, MaxMotionSendWait, buf); - reprap.GetPlatform().OnProcessingCanMessage(); + // Send the message + SendCanMessage(TxBufferIndexMotion, MaxMotionSendWait, buf); + reprap.GetPlatform().OnProcessingCanMessage(); #ifdef CAN_DEBUG - // Display a debug message too - debugPrintf("CCCR %08" PRIx32 ", PSR %08" PRIx32 ", ECR %08" PRIx32 ", TXBRP %08" PRIx32 ", TXBTO %08" PRIx32 ", st %08" PRIx32 "\n", - MCAN1->MCAN_CCCR, MCAN1->MCAN_PSR, MCAN1->MCAN_ECR, MCAN1->MCAN_TXBRP, MCAN1->MCAN_TXBTO, GetAndClearStatusBits()); - buf->msg.DebugPrint(); - delay(50); - debugPrintf("CCCR %08" PRIx32 ", PSR %08" PRIx32 ", ECR %08" PRIx32 ", TXBRP %08" PRIx32 ", TXBTO %08" PRIx32 ", st %08" PRIx32 "\n", - MCAN1->MCAN_CCCR, MCAN1->MCAN_PSR, MCAN1->MCAN_ECR, MCAN1->MCAN_TXBRP, MCAN1->MCAN_TXBTO, GetAndClearStatusBits()); + // Display a debug message too + debugPrintf("CCCR %08" PRIx32 ", PSR %08" PRIx32 ", ECR %08" PRIx32 ", TXBRP %08" PRIx32 ", TXBTO %08" PRIx32 ", st %08" PRIx32 "\n", + MCAN1->MCAN_CCCR, MCAN1->MCAN_PSR, MCAN1->MCAN_ECR, MCAN1->MCAN_TXBRP, MCAN1->MCAN_TXBTO, GetAndClearStatusBits()); + buf->msg.DebugPrint(); + delay(50); + debugPrintf("CCCR %08" PRIx32 ", PSR %08" PRIx32 ", ECR %08" PRIx32 ", TXBRP %08" PRIx32 ", TXBTO %08" PRIx32 ", st %08" PRIx32 "\n", + MCAN1->MCAN_CCCR, MCAN1->MCAN_PSR, MCAN1->MCAN_ECR, MCAN1->MCAN_TXBRP, MCAN1->MCAN_TXBTO, GetAndClearStatusBits()); #endif - // Free the message buffer. - CanMessageBuffer::Free(buf); - } - else - { - break; + // Free the message buffer. + CanMessageBuffer::Free(buf); + } + else + { + break; + } } + TaskBase::Take(Mutex::TimeoutUnlimited); } } } diff --git a/src/InputMonitors/InputMonitor.cpp b/src/InputMonitors/InputMonitor.cpp index 5f797606..d449e679 100644 --- a/src/InputMonitors/InputMonitor.cpp +++ b/src/InputMonitors/InputMonitor.cpp @@ -39,7 +39,7 @@ bool InputMonitor::Activate(bool useInterrupt) noexcept #if SAME5x !useInterrupt || port.SetAnalogCallback(CommonAnalogPortInterrupt, CallbackParameter(this), 1); #else - true; // SAME70 doesn't support SetAnalogCallback yet + false; // SAME70 doesn't support SetAnalogCallback yet #endif } active = true; -- cgit v1.2.3 From 2860cf15465ee5a0dacb8309e8580744e649f776 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Wed, 13 Jul 2022 19:21:00 +0100 Subject: More fixes for ACT LED on MB6HC --- src/CAN/CanInterface.cpp | 1 + src/CAN/CommandProcessor.cpp | 10 +++++----- src/Platform/Platform.cpp | 2 +- src/Platform/Tasks.cpp | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/CAN/CanInterface.cpp b/src/CAN/CanInterface.cpp index 31c43bd2..f3d1de15 100644 --- a/src/CAN/CanInterface.cpp +++ b/src/CAN/CanInterface.cpp @@ -452,6 +452,7 @@ extern "C" [[noreturn]] void CanSenderLoop(void *) noexcept { buf.dataLength = msg->GetActualDataLength(); SendCanMessage(TxBufferIndexUrgent, MaxUrgentSendWait, &buf); + reprap.GetPlatform().OnProcessingCanMessage(); } TaskBase::Take(timeToWait); // wait until we are woken up because a message is available, or we time out } diff --git a/src/CAN/CommandProcessor.cpp b/src/CAN/CommandProcessor.cpp index d27fa6aa..a91e8cd2 100644 --- a/src/CAN/CommandProcessor.cpp +++ b/src/CAN/CommandProcessor.cpp @@ -389,15 +389,15 @@ void CommandProcessor::ProcessReceivedMessage(CanMessageBuffer *buf) noexcept { if (buf->id.Src() != CanInterface::GetCanAddress()) // I don't think we should receive our own broadcasts, but in case we do... { + if (buf->id.Dst() != CanId::BroadcastAddress) + { + reprap.GetPlatform().OnProcessingCanMessage(); + } + const CanMessageType id = buf->id.MsgType(); #if SUPPORT_REMOTE_COMMANDS if (CanInterface::InExpansionMode()) { - if (id != CanMessageType::timeSync) - { - reprap.GetPlatform().OnProcessingCanMessage(); - } - String reply; const StringRef& replyRef = reply.GetRef(); GCodeResult rslt; diff --git a/src/Platform/Platform.cpp b/src/Platform/Platform.cpp index 5988dfd2..5d78759c 100644 --- a/src/Platform/Platform.cpp +++ b/src/Platform/Platform.cpp @@ -2511,7 +2511,7 @@ void Platform::EnableOneLocalDriver(size_t driver, float requiredCurrent) noexce { SmartDrivers::EnableDrive(driver, true); } -# if !defined(DUET3MINI) // no enable pins on 5LC +# if !defined(DUET3MINI) // no enable pins on 5LC else { digitalWrite(ENABLE_PINS[driver], enableValues[driver] > 0); diff --git a/src/Platform/Tasks.cpp b/src/Platform/Tasks.cpp index 8ef89076..0f8eb0c9 100644 --- a/src/Platform/Tasks.cpp +++ b/src/Platform/Tasks.cpp @@ -128,7 +128,7 @@ void *Tasks::GetNVMBuffer(const uint32_t *stk) noexcept [[noreturn]] void AppMain() noexcept { pinMode(DiagPin, (DiagOnPolarity) ? OUTPUT_LOW : OUTPUT_HIGH); // set up status LED for debugging and turn it off -#ifdef DUET3MINI +#if defined(DUET3MINI) || defined(DUET3_MB6XD) pinMode(ActLedPin, (ActOnPolarity) ? OUTPUT_LOW : OUTPUT_HIGH); // set up activity LED and turn it off #endif -- cgit v1.2.3