2016-01-02 03:02:34 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2016. 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2014-01-06 09:27:51 -05:00
|
|
|
#include <assert.h>
|
2016-05-20 17:30:37 -07:00
|
|
|
#include <jni.h>
|
2016-07-14 00:17:29 -07:00
|
|
|
#include "HAL/cpp/Log.h"
|
2014-01-06 09:27:51 -05:00
|
|
|
|
|
|
|
|
#include "edu_wpi_first_wpilibj_hal_SPIJNI.h"
|
|
|
|
|
|
2016-05-24 00:58:10 -07:00
|
|
|
#include "HAL/SPI.h"
|
2015-11-01 09:11:52 -08:00
|
|
|
#include "HALUtil.h"
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2016-10-31 23:04:49 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2014-01-06 09:27:51 -05:00
|
|
|
// set the logging level
|
2014-05-30 10:08:29 -04:00
|
|
|
TLogLevel spiJNILogLevel = logWARNING;
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
#define SPIJNI_LOG(level) \
|
|
|
|
|
if (level > spiJNILogLevel) \
|
|
|
|
|
; \
|
|
|
|
|
else \
|
|
|
|
|
Log().Get(level)
|
2014-01-06 09:27:51 -05:00
|
|
|
|
2015-11-01 09:11:52 -08:00
|
|
|
extern "C" {
|
|
|
|
|
|
2014-01-06 09:27:51 -05:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiInitialize
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiInitialize(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiInitialize";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_InitializeSPI(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
2016-09-29 20:18:40 -07:00
|
|
|
CheckStatusForceThrow(env, status);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiTransaction
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (ILjava/nio/ByteBuffer;Ljava/nio/ByteBuffer;B)I
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiTransaction(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port, jobject dataToSend, jobject dataReceived,
|
2016-05-20 17:30:37 -07:00
|
|
|
jbyte size) {
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiTransaction";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
uint8_t *dataToSendPtr = nullptr;
|
|
|
|
|
if (dataToSend != 0) {
|
|
|
|
|
dataToSendPtr = (uint8_t *)env->GetDirectBufferAddress(dataToSend);
|
|
|
|
|
}
|
|
|
|
|
uint8_t *dataReceivedPtr =
|
|
|
|
|
(uint8_t *)env->GetDirectBufferAddress(dataReceived);
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr;
|
2017-05-09 12:12:46 -07:00
|
|
|
jint retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), dataToSendPtr, dataReceivedPtr, size);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal;
|
|
|
|
|
return retVal;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiWrite
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (ILjava/nio/ByteBuffer;B)I
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiWrite(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port, jobject dataToSend, jbyte size) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiWrite";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
uint8_t *dataToSendPtr = nullptr;
|
|
|
|
|
if (dataToSend != 0) {
|
|
|
|
|
dataToSendPtr = (uint8_t *)env->GetDirectBufferAddress(dataToSend);
|
|
|
|
|
}
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr;
|
2017-05-09 12:12:46 -07:00
|
|
|
jint retVal = HAL_WriteSPI(static_cast<HAL_SPIPort>(port), dataToSendPtr, size);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal;
|
|
|
|
|
return retVal;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiRead
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (ILjava/nio/ByteBuffer;B)I
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiRead(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port, jobject dataReceived, jbyte size) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiRead";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
uint8_t *dataReceivedPtr =
|
|
|
|
|
(uint8_t *)env->GetDirectBufferAddress(dataReceived);
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr;
|
2017-05-09 12:12:46 -07:00
|
|
|
jint retVal = HAL_ReadSPI(static_cast<HAL_SPIPort>(port), (uint8_t *)dataReceivedPtr, size);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal;
|
|
|
|
|
return retVal;
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiClose
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
2017-05-09 12:12:46 -07:00
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiClose(JNIEnv *, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiClose";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_CloseSPI(static_cast<HAL_SPIPort>(port));
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiSetSpeed
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (II)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetSpeed(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *, jclass, jint port, jint speed) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetSpeed";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Speed = " << (jint)speed;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPISpeed(static_cast<HAL_SPIPort>(port), speed);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiSetOpts
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (IIII)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetOpts(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *, jclass, jint port, jint msb_first, jint sample_on_trailing,
|
2016-05-20 17:30:37 -07:00
|
|
|
jint clk_idle_high) {
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetOpts";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "msb_first = " << msb_first;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "sample_on_trailing = " << sample_on_trailing;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "clk_idle_high = " << clk_idle_high;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPIOpts(static_cast<HAL_SPIPort>(port), msb_first, sample_on_trailing, clk_idle_high);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiSetChipSelectActiveHigh
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetChipSelectActiveHigh(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetCSActiveHigh";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPIChipSelectActiveHigh(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
CheckStatus(env, status);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
2014-07-16 16:24:44 -04:00
|
|
|
* Method: spiSetChipSelectActiveLow
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2014-01-06 09:27:51 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetChipSelectActiveLow(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetCSActiveLow";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPIChipSelectActiveLow(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
CheckStatus(env, status);
|
2014-01-06 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-22 11:50:49 -08:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiInitAccumulator
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (IIIBIIBBZZ)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiInitAccumulator(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port, jint period, jint cmd, jbyte xferSize,
|
2016-05-20 17:30:37 -07:00
|
|
|
jint validMask, jint validValue, jbyte dataShift, jbyte dataSize,
|
|
|
|
|
jboolean isSigned, jboolean bigEndian) {
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiInitAccumulator";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Period = " << period;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Cmd = " << cmd;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "XferSize = " << (jint)xferSize;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "ValidMask = " << validMask;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "ValidValue = " << validValue;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "DataShift = " << (jint)dataShift;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "DataSize = " << (jint)dataSize;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "IsSigned = " << (jint)isSigned;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "BigEndian = " << (jint)bigEndian;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_InitSPIAccumulator(static_cast<HAL_SPIPort>(port), period, cmd, xferSize, validMask, validValue,
|
2016-05-20 17:30:37 -07:00
|
|
|
dataShift, dataSize, isSigned, bigEndian, &status);
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiFreeAccumulator
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiFreeAccumulator(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiFreeAccumulator";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_FreeSPIAccumulator(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiResetAccumulator
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiResetAccumulator(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiResetAccumulator";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_ResetSPIAccumulator(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiSetAccumulatorCenter
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (II)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetAccumulatorCenter(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port, jint center) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetAccumulatorCenter";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Center = " << center;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPIAccumulatorCenter(static_cast<HAL_SPIPort>(port), center, &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiSetAccumulatorDeadband
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (II)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetAccumulatorDeadband(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port, jint deadband) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetAccumulatorDeadband";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Deadband = " << deadband;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_SetSPIAccumulatorDeadband(static_cast<HAL_SPIPort>(port), deadband, &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiGetAccumulatorLastValue
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)I
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiGetAccumulatorLastValue(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiGetAccumulatorLastValue";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
jint retVal = HAL_GetSPIAccumulatorLastValue(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return retVal;
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiGetAccumulatorValue
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)J
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT jlong JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiGetAccumulatorValue(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiGetAccumulatorValue";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
jlong retVal = HAL_GetSPIAccumulatorValue(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return retVal;
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiGetAccumulatorCount
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)I
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiGetAccumulatorCount(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiGetAccumulatorCount";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
jint retVal = HAL_GetSPIAccumulatorCount(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return retVal;
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiGetAccumulatorAverage
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (I)D
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT jdouble JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiGetAccumulatorAverage(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiGetAccumulatorAverage";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2017-05-09 12:12:46 -07:00
|
|
|
jdouble retVal = HAL_GetSPIAccumulatorAverage(static_cast<HAL_SPIPort>(port), &status);
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return retVal;
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
|
|
|
|
* Method: spiGetAccumulatorOutput
|
2017-05-09 12:12:46 -07:00
|
|
|
* Signature: (ILjava/nio/LongBuffer;Ljava/nio/LongBuffer;)V
|
2015-11-22 11:50:49 -08:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiGetAccumulatorOutput(
|
2017-05-09 12:12:46 -07:00
|
|
|
JNIEnv *env, jclass, jint port, jobject value, jobject count) {
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiGetAccumulatorOutput";
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
|
|
|
|
|
int32_t status = 0;
|
2015-11-22 11:50:49 -08:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
jlong *valuePtr = (jlong *)env->GetDirectBufferAddress(value);
|
2016-07-12 10:45:14 -07:00
|
|
|
jlong *countPtr = (jlong *)env->GetDirectBufferAddress(count);
|
2015-11-22 11:50:49 -08:00
|
|
|
|
2017-08-22 20:49:59 -07:00
|
|
|
int64_t valueInt64;
|
|
|
|
|
int64_t countInt64;
|
|
|
|
|
|
|
|
|
|
HAL_GetSPIAccumulatorOutput(static_cast<HAL_SPIPort>(port), &valueInt64, &countInt64, &status);
|
|
|
|
|
|
|
|
|
|
*valuePtr = valueInt64;
|
|
|
|
|
*countPtr = countInt64;
|
2015-11-22 11:50:49 -08:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
SPIJNI_LOG(logDEBUG) << "Status = " << status;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Value = " << *valuePtr;
|
|
|
|
|
SPIJNI_LOG(logDEBUG) << "Count = " << *countPtr;
|
|
|
|
|
CheckStatus(env, status);
|
2015-11-22 11:50:49 -08:00
|
|
|
}
|
|
|
|
|
|
2015-11-01 09:11:52 -08:00
|
|
|
} // extern "C"
|