Files
allwpilib/hal/src/main/native/cpp/jni/InterruptJNI.cpp

174 lines
4.4 KiB
C++
Raw Normal View History

// 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.
#include <jni.h>
2018-05-13 17:09:56 -07:00
#include <atomic>
2018-05-13 17:09:56 -07:00
#include <cassert>
#include <thread>
#include <wpi/SafeThread.h>
#include <wpi/mutex.h>
#include "HALUtil.h"
#include "edu_wpi_first_hal_InterruptJNI.h"
#include "hal/Interrupts.h"
using namespace hal;
extern "C" {
2014-01-06 09:27:51 -05:00
/*
* Class: edu_wpi_first_hal_InterruptJNI
2014-01-06 09:27:51 -05:00
* Method: initializeInterrupts
* Signature: ()I
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_InterruptJNI_initializeInterrupts
(JNIEnv* env, jclass)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
HAL_InterruptHandle interrupt = HAL_InitializeInterrupts(&status);
CheckStatusForceThrow(env, status);
return (jint)interrupt;
2014-01-06 09:27:51 -05: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
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_InterruptJNI_cleanInterrupts
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint interruptHandle)
{
if (interruptHandle != HAL_kInvalidHandle) {
HAL_CleanInterrupts((HAL_InterruptHandle)interruptHandle);
}
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_InterruptJNI
2014-01-06 09:27:51 -05:00
* Method: waitForInterrupt
* Signature: (IDZ)J
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_hal_InterruptJNI_waitForInterrupt
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint interruptHandle, jdouble timeout,
jboolean ignorePrevious)
{
int32_t status = 0;
int64_t result = HAL_WaitForInterrupt((HAL_InterruptHandle)interruptHandle,
timeout, ignorePrevious, &status);
2014-01-06 09:27:51 -05:00
CheckStatus(env, status);
return result;
2014-01-06 09:27:51 -05: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
/*
* Class: edu_wpi_first_hal_InterruptJNI
2016-07-09 01:12:37 -07:00
* Method: readInterruptRisingTimestamp
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_hal_InterruptJNI_readInterruptRisingTimestamp
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint interruptHandle)
{
int32_t status = 0;
jlong timeStamp = HAL_ReadInterruptRisingTimestamp(
2018-05-13 17:09:56 -07:00
(HAL_InterruptHandle)interruptHandle, &status);
CheckStatus(env, status);
return timeStamp;
}
/*
* Class: edu_wpi_first_hal_InterruptJNI
2016-07-09 01:12:37 -07:00
* Method: readInterruptFallingTimestamp
* Signature: (I)J
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_hal_InterruptJNI_readInterruptFallingTimestamp
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint interruptHandle)
{
int32_t status = 0;
jlong timeStamp = HAL_ReadInterruptFallingTimestamp(
2018-05-13 17:09:56 -07:00
(HAL_InterruptHandle)interruptHandle, &status);
2014-01-06 09:27:51 -05:00
CheckStatus(env, status);
return timeStamp;
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_InterruptJNI
2014-01-06 09:27:51 -05:00
* Method: requestInterrupts
* Signature: (III)V
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_InterruptJNI_requestInterrupts
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint interruptHandle, jint digitalSourceHandle,
jint analogTriggerType)
{
int32_t status = 0;
2018-05-13 17:09:56 -07:00
HAL_RequestInterrupts((HAL_InterruptHandle)interruptHandle,
(HAL_Handle)digitalSourceHandle,
(HAL_AnalogTriggerType)analogTriggerType, &status);
CheckStatus(env, status);
2014-01-06 09:27:51 -05: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
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_InterruptJNI_setInterruptUpSourceEdge
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint interruptHandle, jboolean risingEdge,
jboolean fallingEdge)
{
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
CheckStatus(env, status);
2014-01-06 09:27:51 -05: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);
}
} // extern "C"