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

Function CanClockLoop

src/CAN/CanInterface.cpp:568–670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

566}
567
568extern "C" [[noreturn]] void CanClockLoop(void *) noexcept
569{
570 CanMessageBuffer buf;
571 uint32_t lastWakeTime = xTaskGetTickCount();
572 uint32_t lastTimeSent = 0;
573 uint32_t lastRealTimeSent = 0;
574#if !SAME70
575 uint16_t lastTimeSyncTxPreparedStamp = 0;
576#endif
577
578 for (;;)
579 {
580 CanMessageTimeSync * const msg = buf.SetupBroadcastMessage<CanMessageTimeSync>(CanInterface::GetCanAddress());
581 msg->lastTimeSent = lastTimeSent;
582 msg->lastTimeAcknowledgeDelay = 0; // assume we don't have the transmit delay available
583
584 currentTimeSyncMarker = ((currentTimeSyncMarker + 1) & 0x0F) | 0xA0;
585 buf.marker = currentTimeSyncMarker;
586 buf.reportInFifo = 1;
587
588 if (gotTimeSyncTxTimeStamp)
589 {
590 // Calculate the delay in sending the last time sync message, in step clocks
591# if SAME70
592 // On the SAME70 the step clock is also the external time stamp counter
593 const uint32_t timeSyncTxDelay = (timeSyncTxTimeStamp - (uint16_t)lastTimeSent) & 0xFFFF;
594# else
595 // On the SAME5x the time stamp counter counts CAN bit times. The step clock is the CAN clock divided by 64.
596 const uint32_t timeSyncTxDelay = ((uint32_t)((timeSyncTxTimeStamp - lastTimeSyncTxPreparedStamp) & 0xFFFF) * CanInterface::GetTimeStampPeriod()) >> 6;
597# endif
598 if (timeSyncTxDelay > peakTimeSyncTxDelay)
599 {
600 peakTimeSyncTxDelay = timeSyncTxDelay;
601 }
602
603 // Occasionally on the SAME70 we get very large delays reported. These delays are not genuine.
604 if (timeSyncTxDelay < MaxTimeSyncDelay)
605 {
606 msg->lastTimeAcknowledgeDelay = timeSyncTxDelay;
607 }
608 gotTimeSyncTxTimeStamp = false;
609 }
610
611 msg->isPrinting = reprap.GetGCodes().IsReallyPrinting();
612
613 // Send the real time just once a second unless we also need to send the movement delay
614 const uint32_t realTime = (uint32_t)reprap.GetPlatform().GetDateTime();
615 const StepTimer::Ticks newMovementDelay = StepTimer::CheckMovementDelayIncreased();
616 if (newMovementDelay != 0)
617 {
618 msg->realTime = realTime;
619 lastRealTimeSent = realTime;
620 msg->movementDelay = newMovementDelay;
621 }
622 else if (realTime != lastRealTimeSent)
623 {
624 msg->realTime = realTime;
625 lastRealTimeSent = realTime;

Callers

nothing calls this directly

Calls 5

GetCanAddressFunction · 0.85
SendCanMessageFunction · 0.85
UpdateLedFunction · 0.85
IsReallyPrintingMethod · 0.80
GetDateTimeMethod · 0.80

Tested by

no test coverage detected