diff --git a/hal/src/main/java/edu/wpi/first/hal/InterruptJNI.java b/hal/src/main/java/edu/wpi/first/hal/InterruptJNI.java index 9fe0c6e43c..8574a25bca 100644 --- a/hal/src/main/java/edu/wpi/first/hal/InterruptJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/InterruptJNI.java @@ -25,9 +25,9 @@ public class InterruptJNI extends JNIWrapper { public static native void disableInterrupts(int interruptHandle); - public static native double readInterruptRisingTimestamp(int interruptHandle); + public static native long readInterruptRisingTimestamp(int interruptHandle); - public static native double readInterruptFallingTimestamp(int interruptHandle); + public static native long readInterruptFallingTimestamp(int interruptHandle); public static native void requestInterrupts(int interruptHandle, int digitalSourceHandle, int analogTriggerType); diff --git a/hal/src/main/native/athena/Interrupts.cpp b/hal/src/main/native/athena/Interrupts.cpp index 450599ea5f..c661da4caf 100644 --- a/hal/src/main/native/athena/Interrupts.cpp +++ b/hal/src/main/native/athena/Interrupts.cpp @@ -165,26 +165,26 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle, anInterrupt->manager->disable(status); } -double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, - int32_t* status) { - auto anInterrupt = interruptHandles->Get(interruptHandle); - if (anInterrupt == nullptr) { - *status = HAL_HANDLE_ERROR; - return 0; - } - uint32_t timestamp = anInterrupt->anInterrupt->readRisingTimeStamp(status); - return timestamp * 1e-6; -} - -double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle, +int64_t HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, int32_t* status) { auto anInterrupt = interruptHandles->Get(interruptHandle); if (anInterrupt == nullptr) { *status = HAL_HANDLE_ERROR; return 0; } + uint32_t timestamp = anInterrupt->anInterrupt->readRisingTimeStamp(status); + return timestamp; +} + +int64_t HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle, + int32_t* status) { + auto anInterrupt = interruptHandles->Get(interruptHandle); + if (anInterrupt == nullptr) { + *status = HAL_HANDLE_ERROR; + return 0; + } uint32_t timestamp = anInterrupt->anInterrupt->readFallingTimeStamp(status); - return timestamp * 1e-6; + return timestamp; } void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle, diff --git a/hal/src/main/native/cpp/jni/InterruptJNI.cpp b/hal/src/main/native/cpp/jni/InterruptJNI.cpp index e1c67489c3..2dd4abf711 100644 --- a/hal/src/main/native/cpp/jni/InterruptJNI.cpp +++ b/hal/src/main/native/cpp/jni/InterruptJNI.cpp @@ -236,9 +236,9 @@ Java_edu_wpi_first_hal_InterruptJNI_disableInterrupts /* * Class: edu_wpi_first_hal_InterruptJNI * Method: readInterruptRisingTimestamp - * Signature: (I)D + * Signature: (I)J */ -JNIEXPORT jdouble JNICALL +JNIEXPORT jlong JNICALL Java_edu_wpi_first_hal_InterruptJNI_readInterruptRisingTimestamp (JNIEnv* env, jclass, jint interruptHandle) { @@ -248,7 +248,7 @@ Java_edu_wpi_first_hal_InterruptJNI_readInterruptRisingTimestamp << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle; int32_t status = 0; - jdouble timeStamp = HAL_ReadInterruptRisingTimestamp( + jlong timeStamp = HAL_ReadInterruptRisingTimestamp( (HAL_InterruptHandle)interruptHandle, &status); INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; @@ -259,9 +259,9 @@ Java_edu_wpi_first_hal_InterruptJNI_readInterruptRisingTimestamp /* * Class: edu_wpi_first_hal_InterruptJNI * Method: readInterruptFallingTimestamp - * Signature: (I)D + * Signature: (I)J */ -JNIEXPORT jdouble JNICALL +JNIEXPORT jlong JNICALL Java_edu_wpi_first_hal_InterruptJNI_readInterruptFallingTimestamp (JNIEnv* env, jclass, jint interruptHandle) { @@ -271,7 +271,7 @@ Java_edu_wpi_first_hal_InterruptJNI_readInterruptFallingTimestamp << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle; int32_t status = 0; - jdouble timeStamp = HAL_ReadInterruptFallingTimestamp( + jlong timeStamp = HAL_ReadInterruptFallingTimestamp( (HAL_InterruptHandle)interruptHandle, &status); INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; diff --git a/hal/src/main/native/include/hal/Interrupts.h b/hal/src/main/native/include/hal/Interrupts.h index bff1e17b5f..126b92c148 100644 --- a/hal/src/main/native/include/hal/Interrupts.h +++ b/hal/src/main/native/include/hal/Interrupts.h @@ -77,24 +77,28 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle, /** * Returns the timestamp for the rising interrupt that occurred most recently. * - * This is in the same time domain as HAL_GetFPGATime(). + * This is in the same time domain as HAL_GetFPGATime(). It only contains the + * bottom 32 bits of the timestamp. If your robot has been running for over 1 + * hour, you will need to fill in the upper 32 bits yourself. * * @param interruptHandle the interrupt handle - * @return timestamp in seconds since FPGA Initialization + * @return timestamp in microseconds since FPGA Initialization */ -double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, - int32_t* status); +int64_t HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, + int32_t* status); /** * Returns the timestamp for the falling interrupt that occurred most recently. * - * This is in the same time domain as HAL_GetFPGATime(). + * This is in the same time domain as HAL_GetFPGATime(). It only contains the + * bottom 32 bits of the timestamp. If your robot has been running for over 1 + * hour, you will need to fill in the upper 32 bits yourself. * * @param interruptHandle the interrupt handle - * @return timestamp in seconds since FPGA Initialization + * @return timestamp in microseconds since FPGA Initialization */ -double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle, - int32_t* status); +int64_t HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle, + int32_t* status); /** * Requests interrupts on a specific digital source. diff --git a/hal/src/main/native/sim/Interrupts.cpp b/hal/src/main/native/sim/Interrupts.cpp index 87792ba1c7..75247ca7c9 100644 --- a/hal/src/main/native/sim/Interrupts.cpp +++ b/hal/src/main/native/sim/Interrupts.cpp @@ -42,8 +42,8 @@ struct Interrupt { uint8_t index; HAL_AnalogTriggerType trigType; bool watcher; - double risingTimestamp; - double fallingTimestamp; + int64_t risingTimestamp; + int64_t fallingTimestamp; bool previousState; bool fireOnUp; bool fireOnDown; @@ -238,10 +238,10 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle, // True => false, Falling if (interrupt->previousState) { // Set our return value and our timestamps - interrupt->fallingTimestamp = hal::GetFPGATimestamp(); + interrupt->fallingTimestamp = hal::GetFPGATime(); return 1 << (8 + interrupt->index); } else { - interrupt->risingTimestamp = hal::GetFPGATimestamp(); + interrupt->risingTimestamp = hal::GetFPGATime(); return 1 << (interrupt->index); } } @@ -302,10 +302,10 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle, // True => false, Falling if (interrupt->previousState) { // Set our return value and our timestamps - interrupt->fallingTimestamp = hal::GetFPGATimestamp(); + interrupt->fallingTimestamp = hal::GetFPGATime(); return 1 << (8 + interrupt->index); } else { - interrupt->risingTimestamp = hal::GetFPGATimestamp(); + interrupt->risingTimestamp = hal::GetFPGATime(); return 1 << (interrupt->index); } } @@ -350,12 +350,12 @@ static void ProcessInterruptDigitalAsynchronous(const char* name, void* param, int32_t mask = 0; if (interrupt->previousState) { interrupt->previousState = retVal; - interrupt->fallingTimestamp = hal::GetFPGATimestamp(); + interrupt->fallingTimestamp = hal::GetFPGATime(); mask = 1 << (8 + interrupt->index); if (!interrupt->fireOnDown) return; } else { interrupt->previousState = retVal; - interrupt->risingTimestamp = hal::GetFPGATimestamp(); + interrupt->risingTimestamp = hal::GetFPGATime(); mask = 1 << (interrupt->index); if (!interrupt->fireOnUp) return; } @@ -385,12 +385,12 @@ static void ProcessInterruptAnalogAsynchronous(const char* name, void* param, int mask = 0; if (interrupt->previousState) { interrupt->previousState = retVal; - interrupt->fallingTimestamp = hal::GetFPGATimestamp(); + interrupt->fallingTimestamp = hal::GetFPGATime(); if (!interrupt->fireOnDown) return; mask = 1 << (8 + interrupt->index); } else { interrupt->previousState = retVal; - interrupt->risingTimestamp = hal::GetFPGATimestamp(); + interrupt->risingTimestamp = hal::GetFPGATime(); if (!interrupt->fireOnUp) return; mask = 1 << (interrupt->index); } @@ -486,8 +486,8 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle, } interrupt->callbackId = -1; } -double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, - int32_t* status) { +int64_t HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, + int32_t* status) { auto interrupt = interruptHandles->Get(interruptHandle); if (interrupt == nullptr) { *status = HAL_HANDLE_ERROR; @@ -496,8 +496,8 @@ double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, return interrupt->risingTimestamp; } -double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle, - int32_t* status) { +int64_t HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle, + int32_t* status) { auto interrupt = interruptHandles->Get(interruptHandle); if (interrupt == nullptr) { *status = HAL_HANDLE_ERROR; diff --git a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp index a8769aabd9..220043f915 100644 --- a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp +++ b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp @@ -96,18 +96,18 @@ double InterruptableSensorBase::ReadRisingTimestamp() { if (StatusIsFatal()) return 0.0; wpi_assert(m_interrupt != HAL_kInvalidHandle); int32_t status = 0; - double timestamp = HAL_ReadInterruptRisingTimestamp(m_interrupt, &status); + int64_t timestamp = HAL_ReadInterruptRisingTimestamp(m_interrupt, &status); wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); - return timestamp; + return timestamp * 1e-6; } double InterruptableSensorBase::ReadFallingTimestamp() { if (StatusIsFatal()) return 0.0; wpi_assert(m_interrupt != HAL_kInvalidHandle); int32_t status = 0; - double timestamp = HAL_ReadInterruptFallingTimestamp(m_interrupt, &status); + int64_t timestamp = HAL_ReadInterruptFallingTimestamp(m_interrupt, &status); wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); - return timestamp; + return timestamp * 1e-6; } void InterruptableSensorBase::SetUpSourceEdge(bool risingEdge, diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java index a0d3ef2da6..cc10fe1a86 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java @@ -215,7 +215,7 @@ public abstract class InterruptableSensorBase extends SendableBase { if (m_interrupt == 0) { throw new IllegalStateException("The interrupt is not allocated."); } - return InterruptJNI.readInterruptRisingTimestamp(m_interrupt); + return InterruptJNI.readInterruptRisingTimestamp(m_interrupt) * 1e-6; } /** @@ -229,7 +229,7 @@ public abstract class InterruptableSensorBase extends SendableBase { if (m_interrupt == 0) { throw new IllegalStateException("The interrupt is not allocated."); } - return InterruptJNI.readInterruptFallingTimestamp(m_interrupt); + return InterruptJNI.readInterruptFallingTimestamp(m_interrupt) * 1e-6; } /**