Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. |
| 3 | */ |
| 4 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 5 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | #pragma once |
| 8 | |
| 9 | #include "Base.h" |
| 10 | #include "HAL/cpp/priority_mutex.h" |
| 11 | |
| 12 | typedef void (*TimerInterruptHandler)(void *param); |
| 13 | |
| 14 | void Wait(double seconds); |
| 15 | double GetClock(); |
| 16 | double GetTime(); |
| 17 | |
| 18 | /** |
| 19 | * Timer objects measure accumulated time in seconds. |
| 20 | * The timer object functions like a stopwatch. It can be started, stopped, and |
| 21 | * cleared. When the |
| 22 | * timer is running its value counts up in seconds. When stopped, the timer |
| 23 | * holds the current |
| 24 | * value. The implementation simply records the time when started and subtracts |
| 25 | * the current time |
| 26 | * whenever the value is requested. |
| 27 | */ |
| 28 | class Timer { |
| 29 | public: |
| 30 | Timer(); |
| 31 | virtual ~Timer() = default; |
| 32 | |
| 33 | Timer(const Timer&) = delete; |
| 34 | Timer& operator=(const Timer&) = delete; |
| 35 | |
| 36 | double Get() const; |
| 37 | void Reset(); |
| 38 | void Start(); |
| 39 | void Stop(); |
| 40 | bool HasPeriodPassed(double period); |
| 41 | |
| 42 | static double GetFPGATimestamp(); |
| 43 | static double GetPPCTimestamp(); |
| 44 | static double GetMatchTime(); |
| 45 | |
| 46 | // The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0 |
| 47 | static const double kRolloverTime; |
| 48 | |
| 49 | private: |
| 50 | double m_startTime = 0.0; |
| 51 | double m_accumulatedTime = 0.0; |
| 52 | bool m_running = false; |
| 53 | mutable priority_mutex m_mutex; |
| 54 | }; |