From f3fe64a60ed9134de7a5c69d08dbf18c8f1db723 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 22 Oct 2014 13:36:17 -0400 Subject: [PATCH] Keep Notifier firing after FPGA rollover (fixes artf3582), simulation may still have an issue with counter rollover Change-Id: I11d86bd65c1e0db123d93aa143b8c8c3b823737a --- wpilibc/wpilibC++/include/Timer.h | 3 +++ wpilibc/wpilibC++Devices/src/Notifier.cpp | 6 +++++- wpilibc/wpilibC++Devices/src/Timer.cpp | 3 --- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/wpilibc/wpilibC++/include/Timer.h b/wpilibc/wpilibC++/include/Timer.h index 03e33b76e2..82db67a51a 100644 --- a/wpilibc/wpilibC++/include/Timer.h +++ b/wpilibc/wpilibC++/include/Timer.h @@ -35,6 +35,9 @@ public: static double GetFPGATimestamp(); static double GetPPCTimestamp(); static double GetMatchTime(); + + // The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0 + static constexpr double kRolloverTime = (1ll << 32) / 1e6; private: double m_startTime; diff --git a/wpilibc/wpilibC++Devices/src/Notifier.cpp b/wpilibc/wpilibC++Devices/src/Notifier.cpp index 46ac430535..6901b5ac3e 100644 --- a/wpilibc/wpilibC++Devices/src/Notifier.cpp +++ b/wpilibc/wpilibC++Devices/src/Notifier.cpp @@ -138,7 +138,7 @@ void Notifier::ProcessQueue(uint32_t mask, void *params) * Insert this Notifier into the timer queue in right place. * WARNING: this method does not do synchronization! It must be called from somewhere * that is taking care of synchronizing access to the queue. - * @param reschedule If false, the scheduled alarm is based on the curent time and UpdateAlarm + * @param reschedule If false, the scheduled alarm is based on the current time and UpdateAlarm * method is called which will enable the alarm if necessary. * If true, update the time by adding the period (no drift) when rescheduled periodic from ProcessQueue. * This ensures that the public methods only update the queue after finishing inserting. @@ -153,6 +153,10 @@ void Notifier::InsertInQueue(bool reschedule) { m_expirationTime = GetClock() + m_period; } + if (m_expirationTime > Timer::kRolloverTime) + { + m_expirationTime -= Timer::kRolloverTime; + } if (timerQueueHead == NULL || timerQueueHead->m_expirationTime >= this->m_expirationTime) { // the queue is empty or greater than the new entry diff --git a/wpilibc/wpilibC++Devices/src/Timer.cpp b/wpilibc/wpilibC++Devices/src/Timer.cpp index 48764f9dcf..e39cd40ac4 100644 --- a/wpilibc/wpilibC++Devices/src/Timer.cpp +++ b/wpilibc/wpilibC++Devices/src/Timer.cpp @@ -13,9 +13,6 @@ #include "Utility.h" #include -// The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0 -static const double kRolloverTime = (1ll << 32) / 1e6; - /** * Pause the task for a specified time. *