mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Moves Interrupts over to Handles instead of pointers (#99)
This commit is contained in:
committed by
Peter Johnson
parent
74fc10999b
commit
046e043c4e
@@ -119,23 +119,22 @@ extern "C" {
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
|
||||
* Method: initializeInterrupts
|
||||
* Signature: (IZ)J
|
||||
* Signature: (Z)I
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterrupts(
|
||||
JNIEnv* env, jclass, jint interruptIndex, jboolean watcher) {
|
||||
JNIEnv* env, jclass, jboolean watcher) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI initializeInterrupts";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "interruptIndex = " << interruptIndex;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "watcher = " << (bool)watcher;
|
||||
|
||||
int32_t status = 0;
|
||||
void* interrupt = initializeInterrupts(interruptIndex, watcher, &status);
|
||||
HalInterruptHandle interrupt = initializeInterrupts(watcher, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << interrupt;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << interrupt;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
|
||||
CheckStatus(env, status);
|
||||
return (jlong)interrupt;
|
||||
return (jint)interrupt;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -145,16 +144,16 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterrupts(
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_cleanInterrupts(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer) {
|
||||
JNIEnv* env, jclass, jint interrupt_handle) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI cleanInterrupts";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
|
||||
int32_t status = 0;
|
||||
cleanInterrupts((void*)interrupt_pointer, &status);
|
||||
cleanInterrupts((HalInterruptHandle)interrupt_handle, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
|
||||
CheckStatus(env, status);
|
||||
// ignore status, as an invalid handle just needs to be ignored.
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -164,13 +163,13 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_cleanInterrupts(
|
||||
*/
|
||||
JNIEXPORT int JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_waitForInterrupt(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer, jdouble timeout,
|
||||
JNIEnv* env, jclass, jint interrupt_handle, jdouble timeout,
|
||||
jboolean ignorePrevious) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI waitForInterrupt";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
|
||||
int32_t status = 0;
|
||||
int result = waitForInterrupt((void*)interrupt_pointer, timeout,
|
||||
int result = waitForInterrupt((HalInterruptHandle)interrupt_handle, timeout,
|
||||
ignorePrevious, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
@@ -186,12 +185,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_waitForInterrupt(
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_enableInterrupts(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer) {
|
||||
JNIEnv* env, jclass, jint interrupt_handle) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI enableInterrupts";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
|
||||
int32_t status = 0;
|
||||
enableInterrupts((void*)interrupt_pointer, &status);
|
||||
enableInterrupts((HalInterruptHandle)interrupt_handle, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
|
||||
@@ -205,12 +204,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_enableInterrupts(
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_disableInterrupts(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer) {
|
||||
JNIEnv* env, jclass, jint interrupt_handle) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI disableInterrupts";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
|
||||
int32_t status = 0;
|
||||
disableInterrupts((void*)interrupt_pointer, &status);
|
||||
disableInterrupts((HalInterruptHandle)interrupt_handle, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
|
||||
@@ -224,12 +223,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_disableInterrupts(
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readRisingTimestamp(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer) {
|
||||
JNIEnv* env, jclass, jint interrupt_handle) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readRisingTimestamp";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
|
||||
int32_t status = 0;
|
||||
jdouble timeStamp = readRisingTimestamp((void*)interrupt_pointer, &status);
|
||||
jdouble timeStamp = readRisingTimestamp((HalInterruptHandle)interrupt_handle, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
CheckStatus(env, status);
|
||||
@@ -243,12 +242,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readRisingTimestamp(
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readFallingTimestamp(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer) {
|
||||
JNIEnv* env, jclass, jint interrupt_handle) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readFallingTimestamp";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
|
||||
int32_t status = 0;
|
||||
jdouble timeStamp = readFallingTimestamp((void*)interrupt_pointer, &status);
|
||||
jdouble timeStamp = readFallingTimestamp((HalInterruptHandle)interrupt_handle, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
CheckStatus(env, status);
|
||||
@@ -262,17 +261,17 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readFallingTimestamp(
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_requestInterrupts(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer, jbyte routing_module,
|
||||
JNIEnv* env, jclass, jint interrupt_handle, jbyte routing_module,
|
||||
jint routing_pin, jboolean routing_analog_trigger) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI requestInterrupts";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "routing module = " << (jint)routing_module;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "routing pin = " << routing_pin;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "routing analog trigger = "
|
||||
<< (jint)routing_analog_trigger;
|
||||
|
||||
int32_t status = 0;
|
||||
requestInterrupts((void*)interrupt_pointer, (uint8_t)routing_module,
|
||||
requestInterrupts((HalInterruptHandle)interrupt_handle, (uint8_t)routing_module,
|
||||
(uint32_t)routing_pin, routing_analog_trigger, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
@@ -287,10 +286,10 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_requestInterrupts(
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterruptHandler(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer, jobject handler,
|
||||
JNIEnv* env, jclass, jint interrupt_handle, jobject handler,
|
||||
jobject param) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI attachInterruptHandler";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
|
||||
jclass cls = env->GetObjectClass(handler);
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "class = " << cls;
|
||||
@@ -314,7 +313,7 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterruptHandler(
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "InterruptThreadJNI Ptr = " << intr;
|
||||
|
||||
int32_t status = 0;
|
||||
attachInterruptHandler((void*)interrupt_pointer, interruptHandler, intr,
|
||||
attachInterruptHandler((HalInterruptHandle)interrupt_handle, interruptHandler, intr,
|
||||
&status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
@@ -328,15 +327,15 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterruptHandler(
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_setInterruptUpSourceEdge(
|
||||
JNIEnv* env, jclass, jlong interrupt_pointer, jboolean risingEdge,
|
||||
JNIEnv* env, jclass, jint interrupt_handle, jboolean risingEdge,
|
||||
jboolean fallingEdge) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI setInterruptUpSourceEdge";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Rising Edge = " << (bool)risingEdge;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Falling Edge = " << (bool)fallingEdge;
|
||||
|
||||
int32_t status = 0;
|
||||
setInterruptUpSourceEdge((void*)interrupt_pointer, risingEdge, fallingEdge,
|
||||
setInterruptUpSourceEdge((HalInterruptHandle)interrupt_handle, risingEdge, fallingEdge,
|
||||
&status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
|
||||
@@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.InterruptJNI;
|
||||
import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
|
||||
|
||||
/**
|
||||
* Base for sensors to be used with interrupts.
|
||||
@@ -42,22 +42,13 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
/**
|
||||
* The interrupt resource.
|
||||
*/
|
||||
protected long m_interrupt = 0;
|
||||
protected int m_interrupt = InterruptJNI.HalInvalidHandle;
|
||||
|
||||
/**
|
||||
* Flags if the interrupt being allocated is synchronous.
|
||||
*/
|
||||
protected boolean m_isSynchronousInterrupt = false;
|
||||
|
||||
/**
|
||||
* The index of the interrupt.
|
||||
*/
|
||||
protected int m_interruptIndex;
|
||||
/**
|
||||
* Resource manager.
|
||||
*/
|
||||
protected static Resource m_interrupts = new Resource(8);
|
||||
|
||||
/**
|
||||
* Create a new InterrupatableSensorBase.
|
||||
*/
|
||||
@@ -138,15 +129,9 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* have to explicitly wait for the interrupt to occur.
|
||||
*/
|
||||
protected void allocateInterrupts(boolean watcher) {
|
||||
try {
|
||||
m_interruptIndex = m_interrupts.allocate();
|
||||
} catch (CheckedAllocationException ex) {
|
||||
throw new AllocationException("No interrupts are left to be allocated");
|
||||
}
|
||||
m_isSynchronousInterrupt = watcher;
|
||||
|
||||
m_interrupt =
|
||||
InterruptJNI.initializeInterrupts(m_interruptIndex, watcher);
|
||||
|
||||
m_interrupt = InterruptJNI.initializeInterrupts(watcher);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +144,6 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
}
|
||||
InterruptJNI.cleanInterrupts(m_interrupt);
|
||||
m_interrupt = 0;
|
||||
m_interrupts.free(m_interruptIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,32 +8,34 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
public class InterruptJNI extends JNIWrapper {
|
||||
public static final int HalInvalidHandle = 0;
|
||||
|
||||
public interface InterruptJNIHandlerFunction {
|
||||
void apply(int interruptAssertedMask, Object param);
|
||||
}
|
||||
|
||||
public static native long initializeInterrupts(int interruptIndex, boolean watcher);
|
||||
public static native int initializeInterrupts(boolean watcher);
|
||||
|
||||
public static native void cleanInterrupts(long interruptPointer);
|
||||
public static native void cleanInterrupts(int interruptHandle);
|
||||
|
||||
public static native int waitForInterrupt(long interruptPointer, double timeout,
|
||||
public static native int waitForInterrupt(int interruptHandle, double timeout,
|
||||
boolean ignorePrevious);
|
||||
|
||||
public static native void enableInterrupts(long interruptPointer);
|
||||
public static native void enableInterrupts(int interruptHandle);
|
||||
|
||||
public static native void disableInterrupts(long interruptPointer);
|
||||
public static native void disableInterrupts(int interruptHandle);
|
||||
|
||||
public static native double readRisingTimestamp(long interruptPointer);
|
||||
public static native double readRisingTimestamp(int interruptHandle);
|
||||
|
||||
public static native double readFallingTimestamp(long interruptPointer);
|
||||
public static native double readFallingTimestamp(int interruptHandle);
|
||||
|
||||
public static native void requestInterrupts(long interruptPointer, byte routingModule,
|
||||
public static native void requestInterrupts(int interruptHandle, byte routingModule,
|
||||
int routingPin, boolean routingAnalogTrigger);
|
||||
|
||||
public static native void attachInterruptHandler(long interruptPointer,
|
||||
public static native void attachInterruptHandler(int interruptHandle,
|
||||
InterruptJNIHandlerFunction handler,
|
||||
Object param);
|
||||
|
||||
public static native void setInterruptUpSourceEdge(long interruptPointer, boolean risingEdge,
|
||||
public static native void setInterruptUpSourceEdge(int interruptHandle, boolean risingEdge,
|
||||
boolean fallingEdge);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user