MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / CanSenderLoop

Function CanSenderLoop

src/CAN/CanInterface.cpp:488–566  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486
487// This task picks up motion messages and sends them
488extern "C" [[noreturn]] void CanSenderLoop(void *) noexcept
489{
490 for (;;)
491 {
492#if SUPPORT_REMOTE_COMMANDS
493 if (inExpansionMode)
494 {
495 // In expansion mode this task just send notifications when the states of input handles change
496 CanMessageBuffer buf;
497 auto msg = buf.SetupRequestMessageNoRid<CanMessageInputChangedNew>(CanInterface::GetCanAddress(), CanInterface::GetCurrentMasterAddress());
498 msg->states = 0;
499 msg->numHandles = 0;
500
501#if HAS_STALL_DETECT
502 // Start by adding any stall detect endstops pending. Do this first so that it must succeed.
503 const uint16_t stallNotifications = SmartDrivers::driverStallsToNotify.exchange(0);
504 if (stallNotifications != 0)
505 {
506 constexpr RemoteInputHandle h(RemoteInputHandle::typeStallEndstop, 0, 0);
507 (void)msg->AddEntry(h.asU16(), (uint32_t)stallNotifications, true);
508 }
509#endif
510 const uint32_t timeToWait = InputMonitor::AddStateChanges(msg);
511 if (msg->numHandles != 0)
512 {
513 buf.dataLength = msg->GetActualDataLength();
514 SendCanMessage(TxBufferIndexUrgent, MaxUrgentSendWait, &buf);
515 reprap.GetPlatform().OnProcessingCanMessage();
516 }
517 TaskBase::TakeIndexed(NotifyIndices::CanSender, timeToWait); // wait until we are woken up because a message is available, or we time out
518 }
519 else
520#endif
521 {
522 // In main board mode this task sends urgent messages concerning motion
523 for (;;)
524 {
525 CanMessageBuffer * const urgentMessage = CanMotion::GetUrgentMessage();
526 if (urgentMessage != nullptr)
527 {
528 SendCanMessage(TxBufferIndexUrgent, MaxUrgentSendWait, urgentMessage);
529 }
530 else if (pendingMotionBuffers != nullptr)
531 {
532 CanMessageBuffer *buf;
533 {
534 TaskCriticalSectionLocker lock;
535 buf = pendingMotionBuffers;
536 pendingMotionBuffers = buf->next;
537#if 0 //unused
538 --numPendingMotionBuffers;
539#endif
540 }
541
542 // Send the message
543 SendCanMessage(TxBufferIndexMotion, MaxMotionSendWait, buf);
544 reprap.GetPlatform().OnProcessingCanMessage();
545

Callers

nothing calls this directly

Calls 7

GetCanAddressFunction · 0.85
GetCurrentMasterAddressFunction · 0.85
SendCanMessageFunction · 0.85
debugPrintfFunction · 0.85
AddEntryMethod · 0.60
DebugPrintMethod · 0.45

Tested by

no test coverage detected