/** * Start the timer running. * Just set the running flag to true indicating that all time requests should be * relative to the system clock. */ void Timer::Start() { std::lock_guard<priority_mutex> sync(m_mutex); if (!m_running) { m_startTime = GetFPGATimestamp(); m_running = true; } }
/** * Start the timer running. * Just set the running flag to true indicating that all time requests should be * relative to the system clock. */ void Timer::Start() { Synchronized sync(m_semaphore); if (!m_running) { m_startTime = GetFPGATimestamp(); m_running = true; } }
/** * Get the current time from the timer. If the clock is running it is derived from * the current system clock the start time stored in the timer class. If the clock * is not running, then return the time when it was last stopped. * * @return unsigned Current time value for this timer in seconds */ double Timer::Get() { double result; double currentTime = GetFPGATimestamp(); Synchronized sync(m_semaphore); if(m_running) { // This math won't work if the timer rolled over (71 minutes after boot). // TODO: Check for it and compensate. result = (currentTime - m_startTime) + m_accumulatedTime; } else { result = m_accumulatedTime; } return result; }
/** * Get the current time from the timer. If the clock is running it is derived * from * the current system clock the start time stored in the timer class. If the * clock * is not running, then return the time when it was last stopped. * * @return Current time value for this timer in seconds */ double Timer::Get() const { double result; double currentTime = GetFPGATimestamp(); std::lock_guard<priority_mutex> sync(m_mutex); if (m_running) { // If the current time is before the start time, then the FPGA clock // rolled over. Compensate by adding the ~71 minutes that it takes // to roll over to the current time. if (currentTime < m_startTime) { currentTime += kRolloverTime; } result = (currentTime - m_startTime) + m_accumulatedTime; } else { result = m_accumulatedTime; } return result; }
/** * Get the current time from the timer. If the clock is running it is derived from * the current system clock the start time stored in the timer class. If the clock * is not running, then return the time when it was last stopped. * * @return Current time value for this timer in seconds */ double Timer::Get() { double result; double currentTime = GetFPGATimestamp(); Synchronized sync(m_semaphore); if(m_running) { // If the current time is before the start time, then the FPGA clock // rolled over. Compensate by adding the ~71 minutes that it takes // to roll over to the current time. if(currentTime < m_startTime) { currentTime += kRolloverTime; } result = (currentTime - m_startTime) + m_accumulatedTime; } else { result = m_accumulatedTime; } return result; }
/** * Reset the timer by setting the time to 0. * * Make the timer startTime the current time so new requests will be relative to * now */ void Timer::Reset() { std::lock_guard<priority_mutex> sync(m_mutex); m_accumulatedTime = 0; m_startTime = GetFPGATimestamp(); }
/** * Reset the timer by setting the time to 0. * * Make the timer startTime the current time so new requests will be relative to now */ void Timer::Reset() { Synchronized sync(m_semaphore); m_accumulatedTime = 0; m_startTime = GetFPGATimestamp(); }