2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
#include "Base.h"
|
2015-06-25 01:54:20 -07:00
|
|
|
#include "HAL/cpp/priority_mutex.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
typedef void (*TimerInterruptHandler)(void* param);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
void Wait(double seconds);
|
|
|
|
|
double GetClock();
|
|
|
|
|
double GetTime();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Timer objects measure accumulated time in seconds.
|
2015-06-25 15:07:55 -04:00
|
|
|
* The timer object functions like a stopwatch. It can be started, stopped, and
|
2016-05-20 17:30:37 -07:00
|
|
|
* cleared. When the timer is running its value counts up in seconds. When
|
|
|
|
|
* stopped, the timer holds the current value. The implementation simply records
|
|
|
|
|
* the time when started and subtracts the current time whenever the value is
|
|
|
|
|
* requested.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class Timer {
|
|
|
|
|
public:
|
|
|
|
|
Timer();
|
2015-06-25 01:54:20 -07:00
|
|
|
virtual ~Timer() = default;
|
2015-07-21 01:23:34 -07:00
|
|
|
|
|
|
|
|
Timer(const Timer&) = delete;
|
|
|
|
|
Timer& operator=(const Timer&) = delete;
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
double Get() const;
|
|
|
|
|
void Reset();
|
|
|
|
|
void Start();
|
|
|
|
|
void Stop();
|
|
|
|
|
bool HasPeriodPassed(double period);
|
|
|
|
|
|
|
|
|
|
static double GetFPGATimestamp();
|
|
|
|
|
static double GetPPCTimestamp();
|
|
|
|
|
static double GetMatchTime();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
// The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0
|
2015-04-26 19:19:57 -04:00
|
|
|
static const double kRolloverTime;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
2015-06-24 01:06:29 -07:00
|
|
|
double m_startTime = 0.0;
|
|
|
|
|
double m_accumulatedTime = 0.0;
|
|
|
|
|
bool m_running = false;
|
2015-06-25 01:54:20 -07:00
|
|
|
mutable priority_mutex m_mutex;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|