From 2a968df779207e506b367e7f8ee9c6a7b8334fde Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 18 Feb 2020 20:41:42 -0800 Subject: [PATCH] Add method for releasing a waiting interrupt (#2347) Useful for a new high level interrupt implementation. --- .../java/edu/wpi/first/hal/InterruptJNI.java | 4 +++- hal/src/main/native/athena/HAL.cpp | 12 +++++++++++- hal/src/main/native/athena/HALInternal.h | 15 +++++++++++++++ hal/src/main/native/athena/Interrupts.cpp | 19 ++++++++++++++++++- hal/src/main/native/cpp/jni/InterruptJNI.cpp | 17 ++++++++++++++++- hal/src/main/native/include/hal/HALBase.h | 2 +- hal/src/main/native/include/hal/Interrupts.h | 12 +++++++++++- hal/src/main/native/sim/HAL.cpp | 2 +- hal/src/main/native/sim/Interrupts.cpp | 7 ++++++- 9 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 hal/src/main/native/athena/HALInternal.h 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 8574a25bca..e370d5b6c3 100644 --- a/hal/src/main/java/edu/wpi/first/hal/InterruptJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/InterruptJNI.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -38,4 +38,6 @@ public class InterruptJNI extends JNIWrapper { public static native void setInterruptUpSourceEdge(int interruptHandle, boolean risingEdge, boolean fallingEdge); + + public static native void releaseWaitingInterrupt(int interruptHandle); } diff --git a/hal/src/main/native/athena/HAL.cpp b/hal/src/main/native/athena/HAL.cpp index 91214e538c..1cf6d81036 100644 --- a/hal/src/main/native/athena/HAL.cpp +++ b/hal/src/main/native/athena/HAL.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -24,6 +24,7 @@ #include #include "HALInitializer.h" +#include "HALInternal.h" #include "ctre/ctre.h" #include "hal/ChipObject.h" #include "hal/DriverStation.h" @@ -78,6 +79,15 @@ void InitializeHAL() { InitializeThreads(); } } // namespace init + +void ReleaseFPGAInterrupt(int32_t interruptNumber) { + if (!global) { + return; + } + int32_t status = 0; + global->writeInterruptForceNumber(static_cast(interruptNumber), + &status); +} } // namespace hal extern "C" { diff --git a/hal/src/main/native/athena/HALInternal.h b/hal/src/main/native/athena/HALInternal.h new file mode 100644 index 0000000000..e3033bf562 --- /dev/null +++ b/hal/src/main/native/athena/HALInternal.h @@ -0,0 +1,15 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2020 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +namespace hal { +void ReleaseFPGAInterrupt(int32_t interruptNumber); + +} // namespace hal diff --git a/hal/src/main/native/athena/Interrupts.cpp b/hal/src/main/native/athena/Interrupts.cpp index 78d518c38c..65882d0e88 100644 --- a/hal/src/main/native/athena/Interrupts.cpp +++ b/hal/src/main/native/athena/Interrupts.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -13,9 +13,11 @@ #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/ChipObject.h" #include "hal/Errors.h" +#include "hal/HALBase.h" #include "hal/handles/HandlesInternal.h" #include "hal/handles/LimitedHandleResource.h" @@ -268,4 +270,19 @@ void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle, anInterrupt->anInterrupt->writeConfig_FallingEdge(fallingEdge, status); } +void HAL_ReleaseWaitingInterrupt(HAL_InterruptHandle interruptHandle, + int32_t* status) { + auto anInterrupt = interruptHandles->Get(interruptHandle); + if (anInterrupt == nullptr) { + *status = HAL_HANDLE_ERROR; + return; + } + + uint32_t interruptIndex = + static_cast(getHandleIndex(interruptHandle)); + + hal::ReleaseFPGAInterrupt(interruptIndex); + hal::ReleaseFPGAInterrupt(interruptIndex + 8); +} + } // extern "C" diff --git a/hal/src/main/native/cpp/jni/InterruptJNI.cpp b/hal/src/main/native/cpp/jni/InterruptJNI.cpp index e3a783d85a..f32b126d49 100644 --- a/hal/src/main/native/cpp/jni/InterruptJNI.cpp +++ b/hal/src/main/native/cpp/jni/InterruptJNI.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -294,4 +294,19 @@ Java_edu_wpi_first_hal_InterruptJNI_setInterruptUpSourceEdge CheckStatus(env, status); } +/* + * Class: edu_wpi_first_hal_InterruptJNI + * Method: releaseWaitingInterrupt + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_hal_InterruptJNI_releaseWaitingInterrupt + (JNIEnv* env, jclass, jint interruptHandle) +{ + int32_t status = 0; + HAL_ReleaseWaitingInterrupt((HAL_InterruptHandle)interruptHandle, &status); + + CheckStatus(env, status); +} + } // extern "C" diff --git a/hal/src/main/native/include/hal/HALBase.h b/hal/src/main/native/include/hal/HALBase.h index f61d9e42c5..308788e1cc 100644 --- a/hal/src/main/native/include/hal/HALBase.h +++ b/hal/src/main/native/include/hal/HALBase.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ diff --git a/hal/src/main/native/include/hal/Interrupts.h b/hal/src/main/native/include/hal/Interrupts.h index 126b92c148..ff68d48ed6 100644 --- a/hal/src/main/native/include/hal/Interrupts.h +++ b/hal/src/main/native/include/hal/Interrupts.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -153,6 +153,16 @@ void HAL_AttachInterruptHandlerThreaded(HAL_InterruptHandle interruptHandle, void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle, HAL_Bool risingEdge, HAL_Bool fallingEdge, int32_t* status); + +/** + * Releases a waiting interrupt. + * + * This will release both rising and falling waiters. + * + * @param interruptHandle the interrupt handle to release + */ +void HAL_ReleaseWaitingInterrupt(HAL_InterruptHandle interruptHandle, + int32_t* status); #ifdef __cplusplus } // extern "C" #endif diff --git a/hal/src/main/native/sim/HAL.cpp b/hal/src/main/native/sim/HAL.cpp index 0dda617300..eb341c4c64 100644 --- a/hal/src/main/native/sim/HAL.cpp +++ b/hal/src/main/native/sim/HAL.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ diff --git a/hal/src/main/native/sim/Interrupts.cpp b/hal/src/main/native/sim/Interrupts.cpp index a7dd285da5..7760f06f17 100644 --- a/hal/src/main/native/sim/Interrupts.cpp +++ b/hal/src/main/native/sim/Interrupts.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -566,4 +566,9 @@ void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle, interrupt->fireOnDown = fallingEdge; interrupt->fireOnUp = risingEdge; } + +void HAL_ReleaseWaitingInterrupt(HAL_InterruptHandle interruptHandle, + int32_t* status) { + // Requires a fairly large rewrite to get working +} } // extern "C"