mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[hal,wpilib] Rename FPGA clock to monotonic clock (#8672)
- Remove status return from HAL level (clock getting should never fail) - Remove 32-bit timestamp expand function - Make monotonic_clock.hpp (formerly fpga_clock.hpp) header-only and move to root hal include directory
This commit is contained in:
@@ -22,7 +22,7 @@ import org.wpilib.units.measure.Voltage;
|
||||
|
||||
/** Contains functions for roboRIO functionality. */
|
||||
public final class RobotController {
|
||||
private static LongSupplier m_timeSource = RobotController::getFPGATime;
|
||||
private static LongSupplier m_timeSource = RobotController::getMonotonicTime;
|
||||
|
||||
private RobotController() {
|
||||
throw new UnsupportedOperationException("This is a utility class!");
|
||||
@@ -69,9 +69,9 @@ public final class RobotController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the microsecond timestamp. By default, the time is based on the FPGA hardware clock in
|
||||
* microseconds since the FPGA started. However, the return value of this method may be modified
|
||||
* to use any time base, including non-monotonic and non-continuous time bases.
|
||||
* Read the microsecond timestamp. By default, the time is based on the monotonic clock. However,
|
||||
* the return value of this method may be modified to use any time base, including non-monotonic
|
||||
* and non-continuous time bases.
|
||||
*
|
||||
* @return The current time in microseconds.
|
||||
*/
|
||||
@@ -80,9 +80,9 @@ public final class RobotController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the microsecond timestamp. By default, the time is based on the FPGA hardware clock in
|
||||
* microseconds since the FPGA started. However, the return value of this method may be modified
|
||||
* to use any time base, including non-monotonic and non-continuous time bases.
|
||||
* Read the microsecond timestamp. By default, the time is based on the monotonic clock. However,
|
||||
* the return value of this method may be modified to use any time base, including non-monotonic
|
||||
* and non-continuous time bases.
|
||||
*
|
||||
* @return The current time in a measure.
|
||||
*/
|
||||
@@ -91,21 +91,21 @@ public final class RobotController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the microsecond timer from the FPGA.
|
||||
* Read the microsecond monotonic timer.
|
||||
*
|
||||
* @return The current time in microseconds according to the FPGA.
|
||||
* @return The current monotonic time in microseconds.
|
||||
*/
|
||||
public static long getFPGATime() {
|
||||
return HALUtil.getFPGATime();
|
||||
public static long getMonotonicTime() {
|
||||
return HALUtil.getMonotonicTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the microsecond timer in a measure from the FPGA.
|
||||
* Read the microsecond monotonic timer in a measure.
|
||||
*
|
||||
* @return The current time according to the FPGA in a measure.
|
||||
* @return The current monotonic time in a measure.
|
||||
*/
|
||||
public static Time getMeasureFPGATime() {
|
||||
return Microseconds.of(HALUtil.getFPGATime());
|
||||
public static Time getMeasureMonotonicTime() {
|
||||
return Microseconds.of(HALUtil.getMonotonicTime());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,9 +17,9 @@ import org.wpilib.units.measure.Time;
|
||||
*/
|
||||
public class Timer {
|
||||
/**
|
||||
* Return the clock time in seconds. By default, the time is based on the FPGA hardware clock in
|
||||
* seconds since the FPGA started. However, the return value of this method may be modified to use
|
||||
* any time base, including non-monotonic time bases.
|
||||
* Return the clock time in seconds. By default, the time is the time returned by
|
||||
* getMonotonicTimestamp(). However, the return value of this method may be modified to use any
|
||||
* time base, including non-monotonic time bases.
|
||||
*
|
||||
* @return Robot running time in seconds.
|
||||
*/
|
||||
@@ -28,13 +28,12 @@ public class Timer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the system clock time in seconds. Return the time from the FPGA hardware clock in
|
||||
* seconds since the FPGA started.
|
||||
* Return the monotonic clock time in seconds.
|
||||
*
|
||||
* @return Robot running time in seconds.
|
||||
* @return Monotonic time in seconds.
|
||||
*/
|
||||
public static double getFPGATimestamp() {
|
||||
return RobotController.getFPGATime() / 1000000.0;
|
||||
public static double getMonotonicTimestamp() {
|
||||
return RobotController.getMonotonicTime() / 1000000.0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Tracer {
|
||||
|
||||
/** Restarts the epoch timer. */
|
||||
public final void resetTimer() {
|
||||
m_startTime = RobotController.getFPGATime();
|
||||
m_startTime = RobotController.getMonotonicTime();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ public class Tracer {
|
||||
* @param epochName The name to associate with the epoch.
|
||||
*/
|
||||
public void addEpoch(String epochName) {
|
||||
long currentTime = RobotController.getFPGATime();
|
||||
long currentTime = RobotController.getMonotonicTime();
|
||||
m_epochs.put(epochName, currentTime - m_startTime);
|
||||
m_startTime = currentTime;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class Tracer {
|
||||
* @param output the stream that the output is sent to
|
||||
*/
|
||||
public void printEpochs(Consumer<String> output) {
|
||||
long now = RobotController.getFPGATime();
|
||||
long now = RobotController.getMonotonicTime();
|
||||
if (now - m_lastEpochsPrintTime > kMinPrintPeriod) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
m_lastEpochsPrintTime = now;
|
||||
|
||||
@@ -100,7 +100,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
* @return The time in seconds since the watchdog was last fed.
|
||||
*/
|
||||
public double getTime() {
|
||||
return Timer.getFPGATimestamp() - m_startTime;
|
||||
return Timer.getMonotonicTimestamp() - m_startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
* @param timeout The watchdog's timeout in seconds with microsecond resolution.
|
||||
*/
|
||||
public void setTimeout(double timeout) {
|
||||
m_startTime = Timer.getFPGATimestamp();
|
||||
m_startTime = Timer.getMonotonicTimestamp();
|
||||
m_tracer.clearEpochs();
|
||||
|
||||
m_queueMutex.lock();
|
||||
@@ -184,7 +184,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
|
||||
/** Enables the watchdog timer. */
|
||||
public void enable() {
|
||||
m_startTime = Timer.getFPGATimestamp();
|
||||
m_startTime = Timer.getMonotonicTimestamp();
|
||||
m_tracer.clearEpochs();
|
||||
|
||||
m_queueMutex.lock();
|
||||
@@ -247,7 +247,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
long curTime = HALUtil.getFPGATime();
|
||||
long curTime = HALUtil.getMonotonicTime();
|
||||
|
||||
m_queueMutex.lock();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user