2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
#include <jni.h>
|
2018-05-13 17:09:56 -07:00
|
|
|
|
2015-12-17 16:19:44 -08:00
|
|
|
#include <atomic>
|
2018-05-13 17:09:56 -07:00
|
|
|
#include <cassert>
|
2015-12-17 16:19:44 -08:00
|
|
|
#include <thread>
|
2017-11-13 09:51:48 -08:00
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/SafeThread.h>
|
|
|
|
|
#include <wpi/mutex.h>
|
2017-11-13 09:51:48 -08:00
|
|
|
|
2015-11-01 09:11:52 -08:00
|
|
|
#include "HALUtil.h"
|
2018-09-20 21:59:46 -07:00
|
|
|
#include "edu_wpi_first_hal_InterruptJNI.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "hal/Interrupts.h"
|
2014-08-04 14:19:01 -04:00
|
|
|
|
2020-06-26 17:12:55 -07:00
|
|
|
using namespace hal;
|
2016-10-31 23:04:49 -07:00
|
|
|
|
2015-11-01 09:11:52 -08:00
|
|
|
extern "C" {
|
2014-01-06 09:27:51 -05:00
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_InterruptJNI
|
2014-01-06 09:27:51 -05:00
|
|
|
* Method: initializeInterrupts
|
2021-06-05 11:25:21 -07:00
|
|
|
* Signature: ()I
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-06-20 23:22:49 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_InterruptJNI_initializeInterrupts
|
2021-06-05 11:25:21 -07:00
|
|
|
(JNIEnv* env, jclass)
|
2018-05-13 17:09:56 -07:00
|
|
|
{
|
2015-12-17 16:19:44 -08:00
|
|
|
int32_t status = 0;
|
2021-06-05 11:25:21 -07:00
|
|
|
HAL_InterruptHandle interrupt = HAL_InitializeInterrupts(&status);
|
2014-08-04 14:19:01 -04:00
|
|
|
|
2016-09-29 20:18:40 -07:00
|
|
|
CheckStatusForceThrow(env, status);
|
2016-06-20 23:22:49 -07:00
|
|
|
return (jint)interrupt;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_InterruptJNI
|
2014-01-06 09:27:51 -05:00
|
|
|
* Method: cleanInterrupts
|
2018-05-13 17:09:56 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_InterruptJNI_cleanInterrupts
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint interruptHandle)
|
|
|
|
|
{
|
2024-09-07 13:58:15 -04:00
|
|
|
if (interruptHandle != HAL_kInvalidHandle) {
|
|
|
|
|
HAL_CleanInterrupts((HAL_InterruptHandle)interruptHandle);
|
|
|
|
|
}
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_InterruptJNI
|
2014-01-06 09:27:51 -05:00
|
|
|
* Method: waitForInterrupt
|
2022-10-13 17:25:54 -07:00
|
|
|
* Signature: (IDZ)J
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2022-10-13 17:25:54 -07:00
|
|
|
JNIEXPORT jlong JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_InterruptJNI_waitForInterrupt
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint interruptHandle, jdouble timeout,
|
|
|
|
|
jboolean ignorePrevious)
|
|
|
|
|
{
|
2015-12-17 16:19:44 -08:00
|
|
|
int32_t status = 0;
|
2022-10-13 17:25:54 -07:00
|
|
|
int64_t result = HAL_WaitForInterrupt((HAL_InterruptHandle)interruptHandle,
|
2016-09-06 00:01:45 -07:00
|
|
|
timeout, ignorePrevious, &status);
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2015-12-17 16:19:44 -08:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return result;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
2022-10-13 17:25:54 -07:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_hal_InterruptJNI
|
|
|
|
|
* Method: waitForMultipleInterrupts
|
|
|
|
|
* Signature: (IJDZ)J
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jlong JNICALL
|
|
|
|
|
Java_edu_wpi_first_hal_InterruptJNI_waitForMultipleInterrupts
|
|
|
|
|
(JNIEnv* env, jclass, jint interruptHandle, jlong mask, jdouble timeout,
|
|
|
|
|
jboolean ignorePrevious)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
int64_t result =
|
|
|
|
|
HAL_WaitForMultipleInterrupts((HAL_InterruptHandle)interruptHandle, mask,
|
|
|
|
|
timeout, ignorePrevious, &status);
|
|
|
|
|
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 09:27:51 -05:00
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_InterruptJNI
|
2016-07-09 01:12:37 -07:00
|
|
|
* Method: readInterruptRisingTimestamp
|
2018-11-15 21:22:03 -08:00
|
|
|
* Signature: (I)J
|
2014-10-05 17:17:59 -04:00
|
|
|
*/
|
2018-11-15 21:22:03 -08:00
|
|
|
JNIEXPORT jlong JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_InterruptJNI_readInterruptRisingTimestamp
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint interruptHandle)
|
|
|
|
|
{
|
2015-12-17 16:19:44 -08:00
|
|
|
int32_t status = 0;
|
2018-11-15 21:22:03 -08:00
|
|
|
jlong timeStamp = HAL_ReadInterruptRisingTimestamp(
|
2018-05-13 17:09:56 -07:00
|
|
|
(HAL_InterruptHandle)interruptHandle, &status);
|
2014-10-05 17:17:59 -04:00
|
|
|
|
2015-12-17 16:19:44 -08:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return timeStamp;
|
2014-10-05 17:17:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_InterruptJNI
|
2016-07-09 01:12:37 -07:00
|
|
|
* Method: readInterruptFallingTimestamp
|
2018-11-15 21:22:03 -08:00
|
|
|
* Signature: (I)J
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2018-11-15 21:22:03 -08:00
|
|
|
JNIEXPORT jlong JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_InterruptJNI_readInterruptFallingTimestamp
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint interruptHandle)
|
|
|
|
|
{
|
2015-12-17 16:19:44 -08:00
|
|
|
int32_t status = 0;
|
2018-11-15 21:22:03 -08:00
|
|
|
jlong timeStamp = HAL_ReadInterruptFallingTimestamp(
|
2018-05-13 17:09:56 -07:00
|
|
|
(HAL_InterruptHandle)interruptHandle, &status);
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2015-12-17 16:19:44 -08:00
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return timeStamp;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_InterruptJNI
|
2014-01-06 09:27:51 -05:00
|
|
|
* Method: requestInterrupts
|
2016-07-07 21:43:55 -07:00
|
|
|
* Signature: (III)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_InterruptJNI_requestInterrupts
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint interruptHandle, jint digitalSourceHandle,
|
|
|
|
|
jint analogTriggerType)
|
|
|
|
|
{
|
2015-12-17 16:19:44 -08:00
|
|
|
int32_t status = 0;
|
2018-05-13 17:09:56 -07:00
|
|
|
HAL_RequestInterrupts((HAL_InterruptHandle)interruptHandle,
|
|
|
|
|
(HAL_Handle)digitalSourceHandle,
|
|
|
|
|
(HAL_AnalogTriggerType)analogTriggerType, &status);
|
2015-12-17 16:19:44 -08:00
|
|
|
|
|
|
|
|
CheckStatus(env, status);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-09-20 21:59:46 -07:00
|
|
|
* Class: edu_wpi_first_hal_InterruptJNI
|
2014-01-06 09:27:51 -05:00
|
|
|
* Method: setInterruptUpSourceEdge
|
2018-05-13 17:09:56 -07:00
|
|
|
* Signature: (IZZ)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2018-09-20 21:59:46 -07:00
|
|
|
Java_edu_wpi_first_hal_InterruptJNI_setInterruptUpSourceEdge
|
2018-05-13 17:09:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint interruptHandle, jboolean risingEdge,
|
|
|
|
|
jboolean fallingEdge)
|
|
|
|
|
{
|
2015-12-17 16:19:44 -08:00
|
|
|
int32_t status = 0;
|
2018-05-13 17:09:56 -07:00
|
|
|
HAL_SetInterruptUpSourceEdge((HAL_InterruptHandle)interruptHandle, risingEdge,
|
|
|
|
|
fallingEdge, &status);
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2015-12-17 16:19:44 -08:00
|
|
|
CheckStatus(env, status);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
2015-11-01 09:11:52 -08:00
|
|
|
|
2020-02-18 20:41:42 -08:00
|
|
|
/*
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-01 09:11:52 -08:00
|
|
|
} // extern "C"
|