Changes HAL Port from a pointer to a handle (#93)

HAL Port is using a special handle, where the module and pin are bit
shifted straight into the handle. This is one of the few special cases
we have, but for the way port is used it is much cleaner and uses much
less memory.  Plus it is generic and not specific to one type.
This commit is contained in:
Thad House
2016-06-05 15:23:58 -07:00
committed by Peter Johnson
parent 5a82f73d9b
commit fc515f4572
44 changed files with 288 additions and 233 deletions

View File

@@ -9,9 +9,11 @@
#include <stdint.h>
#include "Handles.h"
extern "C" {
// Analog input functions
void* initializeAnalogInputPort(void* port_pointer, int32_t* status);
void* initializeAnalogInputPort(HalPortHandle port_handle, int32_t* status);
void freeAnalogInputPort(void* analog_port_pointer);
bool checkAnalogModule(uint8_t module);
bool checkAnalogInputChannel(uint32_t pin);

View File

@@ -9,8 +9,10 @@
#include <stdint.h>
#include "Handles.h"
extern "C" {
void* initializeAnalogOutputPort(void* port_pointer, int32_t* status);
void* initializeAnalogOutputPort(HalPortHandle port_handle, int32_t* status);
void freeAnalogOutputPort(void* analog_port_pointer);
void setAnalogOutput(void* analog_port_pointer, double voltage,
int32_t* status);

View File

@@ -9,6 +9,8 @@
#include <stdint.h>
#include "Handles.h"
enum AnalogTriggerType {
kInWindow = 0,
kState = 1,
@@ -17,7 +19,7 @@ enum AnalogTriggerType {
};
extern "C" {
void* initializeAnalogTrigger(void* port_pointer, uint32_t* index,
void* initializeAnalogTrigger(HalPortHandle port_handle, uint32_t* index,
int32_t* status);
void cleanAnalogTrigger(void* analog_trigger_pointer, int32_t* status);
void setAnalogTriggerLimitsRaw(void* analog_trigger_pointer, int32_t lower,

View File

@@ -9,10 +9,12 @@
#include <stdint.h>
#include "Handles.h"
extern "C" {
// the following 2 functions are here as they will be changed with
// the handle changes to be DIO exclusive.
void* initializeDigitalPort(void* port_pointer, int32_t* status);
void* initializeDigitalPort(HalPortHandle port_handle, int32_t* status);
void freeDigitalPort(void* digital_port_pointer);
void* allocatePWM(int32_t* status);

View File

@@ -19,6 +19,7 @@
#include "DIO.h"
#include "Encoder.h"
#include "Errors.h"
#include "Handles.h"
#include "I2C.h"
#include "Interrupts.h"
#include "Notifier.h"
@@ -211,9 +212,9 @@ extern const uint32_t solenoid_kNumDO7_0Elements;
extern const uint32_t interrupt_kNumSystems;
extern const uint32_t kSystemClockTicksPerMicrosecond;
void* getPort(uint8_t pin);
void* getPortWithModule(uint8_t module, uint8_t pin);
void freePort(void* port);
HalPortHandle getPort(uint8_t pin);
HalPortHandle getPortWithModule(uint8_t module, uint8_t pin);
void freePort(HalPortHandle port);
const char* getHALErrorMessage(int32_t code);
uint16_t getFPGAVersion(int32_t* status);

View File

@@ -17,3 +17,5 @@
#define HAL_HANDLE_NEGATIVE_INDEX -5
typedef int32_t HalHandle;
typedef HalHandle HalPortHandle;

View File

@@ -1,13 +0,0 @@
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
#pragma once
typedef struct port_t {
uint8_t pin;
uint8_t module;
} Port;

View File

@@ -9,8 +9,10 @@
#include <stdint.h>
#include "Handles.h"
extern "C" {
void* initializeSolenoidPort(void* port_pointer, int32_t* status);
void* initializeSolenoidPort(HalPortHandle port_handle, int32_t* status);
void freeSolenoidPort(void* solenoid_port_pointer);
bool checkSolenoidModule(uint8_t module);

View File

@@ -21,7 +21,7 @@ extern "C" {
bool isAccumulatorChannel(void* analog_port_pointer, int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
for (uint32_t i = 0; i < kAccumulatorNumChannels; i++) {
if (port->port.pin == kAccumulatorChannels[i]) return true;
if (port->pin == kAccumulatorChannels[i]) return true;
}
return false;
}

View File

@@ -14,6 +14,7 @@
#include "HAL/AnalogAccumulator.h"
#include "HAL/HAL.h"
#include "HAL/cpp/priority_mutex.h"
#include "handles/HandlesInternal.h"
using namespace hal;
@@ -23,20 +24,27 @@ extern "C" {
/**
* Initialize the analog input port using the given port object.
*/
void* initializeAnalogInputPort(void* port_pointer, int32_t* status) {
void* initializeAnalogInputPort(HalPortHandle port_handle, int32_t* status) {
initializeAnalog(status);
Port* port = (Port*)port_pointer;
if (*status != 0) return nullptr;
int16_t pin = getPortHandlePin(port_handle);
if (pin == HAL_HANDLE_INVALID_TYPE) {
*status = PARAMETER_OUT_OF_RANGE;
return nullptr;
}
// Initialize port structure
AnalogPort* analog_port = new AnalogPort();
analog_port->port = *port;
analog_port->pin = (uint8_t)pin;
if (isAccumulatorChannel(analog_port, status)) {
analog_port->accumulator = tAccumulator::create(port->pin, status);
analog_port->accumulator = tAccumulator::create(pin, status);
} else
analog_port->accumulator = nullptr;
// Set default configuration
analogInputSystem->writeScanList(port->pin, port->pin, status);
analogInputSystem->writeScanList(pin, pin, status);
setAnalogAverageBits(analog_port, kDefaultAverageBits, status);
setAnalogOversampleBits(analog_port, kDefaultOversampleBits, status);
return analog_port;
@@ -130,7 +138,7 @@ float getAnalogSampleRate(int32_t* status) {
void setAnalogAverageBits(void* analog_port_pointer, uint32_t bits,
int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
analogInputSystem->writeAverageBits(port->port.pin, bits, status);
analogInputSystem->writeAverageBits(port->pin, bits, status);
}
/**
@@ -144,7 +152,7 @@ void setAnalogAverageBits(void* analog_port_pointer, uint32_t bits,
*/
uint32_t getAnalogAverageBits(void* analog_port_pointer, int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
uint32_t result = analogInputSystem->readAverageBits(port->port.pin, status);
uint32_t result = analogInputSystem->readAverageBits(port->pin, status);
return result;
}
@@ -162,7 +170,7 @@ uint32_t getAnalogAverageBits(void* analog_port_pointer, int32_t* status) {
void setAnalogOversampleBits(void* analog_port_pointer, uint32_t bits,
int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
analogInputSystem->writeOversampleBits(port->port.pin, bits, status);
analogInputSystem->writeOversampleBits(port->pin, bits, status);
}
/**
@@ -177,8 +185,7 @@ void setAnalogOversampleBits(void* analog_port_pointer, uint32_t bits,
*/
uint32_t getAnalogOversampleBits(void* analog_port_pointer, int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
uint32_t result =
analogInputSystem->readOversampleBits(port->port.pin, status);
uint32_t result = analogInputSystem->readOversampleBits(port->pin, status);
return result;
}
@@ -195,12 +202,12 @@ uint32_t getAnalogOversampleBits(void* analog_port_pointer, int32_t* status) {
int16_t getAnalogValue(void* analog_port_pointer, int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
int16_t value;
if (!checkAnalogInputChannel(port->port.pin)) {
if (!checkAnalogInputChannel(port->pin)) {
return 0;
}
tAI::tReadSelect readSelect;
readSelect.Channel = port->port.pin;
readSelect.Channel = port->pin;
readSelect.Averaged = false;
{
@@ -230,12 +237,12 @@ int16_t getAnalogValue(void* analog_port_pointer, int32_t* status) {
int32_t getAnalogAverageValue(void* analog_port_pointer, int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
int32_t value;
if (!checkAnalogInputChannel(port->port.pin)) {
if (!checkAnalogInputChannel(port->pin)) {
return 0;
}
tAI::tReadSelect readSelect;
readSelect.Channel = port->port.pin;
readSelect.Channel = port->pin;
readSelect.Averaged = true;
{
@@ -331,7 +338,7 @@ int32_t getAnalogVoltsToValue(void* analog_port_pointer, double voltage,
uint32_t getAnalogLSBWeight(void* analog_port_pointer, int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
uint32_t lsbWeight = FRC_NetworkCommunication_nAICalibration_getLSBWeight(
0, port->port.pin, status); // XXX: aiSystemIndex == 0?
0, port->pin, status); // XXX: aiSystemIndex == 0?
return lsbWeight;
}
@@ -348,7 +355,7 @@ uint32_t getAnalogLSBWeight(void* analog_port_pointer, int32_t* status) {
int32_t getAnalogOffset(void* analog_port_pointer, int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
int32_t offset = FRC_NetworkCommunication_nAICalibration_getOffset(
0, port->port.pin, status); // XXX: aiSystemIndex == 0?
0, port->pin, status); // XXX: aiSystemIndex == 0?
return offset;
}
}

View File

@@ -9,7 +9,6 @@
#include "ChipObject.h"
#include "HAL/AnalogInput.h"
#include "HAL/Port.h"
#include "HAL/cpp/priority_mutex.h"
namespace hal {

View File

@@ -10,7 +10,6 @@
#include <stdint.h>
#include "ChipObject.h"
#include "HAL/Port.h"
#include "HAL/cpp/priority_mutex.h"
namespace hal {
@@ -28,7 +27,7 @@ extern tAO* analogOutputSystem;
extern priority_recursive_mutex analogRegisterWindowMutex;
struct AnalogPort {
Port port;
uint8_t pin;
tAccumulator* accumulator;
};

View File

@@ -8,6 +8,8 @@
#include "HAL/AnalogOutput.h"
#include "AnalogInternal.h"
#include "HAL/Errors.h"
#include "handles/HandlesInternal.h"
using namespace hal;
@@ -16,13 +18,20 @@ extern "C" {
/**
* Initialize the analog output port using the given port object.
*/
void* initializeAnalogOutputPort(void* port_pointer, int32_t* status) {
void* initializeAnalogOutputPort(HalPortHandle port_handle, int32_t* status) {
initializeAnalog(status);
Port* port = (Port*)port_pointer;
if (*status != 0) return nullptr;
int16_t pin = getPortHandlePin(port_handle);
if (pin == HAL_HANDLE_INVALID_TYPE) {
*status = PARAMETER_OUT_OF_RANGE;
return nullptr;
}
// Initialize port structure
AnalogPort* analog_port = new AnalogPort();
analog_port->port = *port;
analog_port->pin = (uint8_t)pin;
analog_port->accumulator = nullptr;
return analog_port;
}
@@ -57,13 +66,13 @@ void setAnalogOutput(void* analog_port_pointer, double voltage,
else if (voltage > 5.0)
rawValue = 0x1000;
analogOutputSystem->writeMXP(port->port.pin, rawValue, status);
analogOutputSystem->writeMXP(port->pin, rawValue, status);
}
double getAnalogOutput(void* analog_port_pointer, int32_t* status) {
AnalogPort* port = (AnalogPort*)analog_port_pointer;
uint16_t rawValue = analogOutputSystem->readMXP(port->port.pin, status);
uint16_t rawValue = analogOutputSystem->readMXP(port->pin, status);
return rawValue * 5.0 / 0x1000;
}

View File

@@ -9,7 +9,9 @@
#include "AnalogInternal.h"
#include "HAL/AnalogInput.h"
#include "HAL/Errors.h"
#include "HAL/cpp/Resource.h"
#include "handles/HandlesInternal.h"
using namespace hal;
@@ -23,20 +25,21 @@ typedef struct trigger_t AnalogTrigger;
static hal::Resource* triggers = nullptr;
void* initializeAnalogTrigger(void* port_pointer, uint32_t* index,
void* initializeAnalogTrigger(HalPortHandle port_handle, uint32_t* index,
int32_t* status) {
Port* port = (Port*)port_pointer;
hal::Resource::CreateResourceObject(&triggers, tAnalogTrigger::kNumSystems);
AnalogTrigger* trigger = new AnalogTrigger();
trigger->port = (AnalogPort*)initializeAnalogInputPort(port, status);
trigger->port = (AnalogPort*)initializeAnalogInputPort(port_handle, status);
if (*status != 0) {
return nullptr;
}
trigger->index = triggers->Allocate("Analog Trigger");
*index = trigger->index;
// TODO: if (index == ~0ul) { CloneError(triggers); return; }
trigger->trigger = tAnalogTrigger::create(trigger->index, status);
trigger->trigger->writeSourceSelect_Channel(port->pin, status);
trigger->trigger->writeSourceSelect_Channel(trigger->port->pin, status);
return trigger;
}

View File

@@ -10,6 +10,7 @@
#include <cmath>
#include "DigitalInternal.h"
#include "handles/HandlesInternal.h"
static_assert(sizeof(uint32_t) <= sizeof(void*),
"This file shoves uint32_ts into pointers.");
@@ -24,13 +25,20 @@ extern "C" {
/**
* Create a new instance of a digital port.
*/
void* initializeDigitalPort(void* port_pointer, int32_t* status) {
void* initializeDigitalPort(HalPortHandle port_handle, int32_t* status) {
initializeDigital(status);
Port* port = (Port*)port_pointer;
if (*status != 0) return nullptr;
int16_t pin = getPortHandlePin(port_handle);
if (pin == HAL_HANDLE_INVALID_TYPE) {
*status = PARAMETER_OUT_OF_RANGE;
return nullptr;
}
// Initialize port structure
DigitalPort* digital_port = new DigitalPort();
digital_port->port = *port;
digital_port->pin = (uint8_t)pin;
return digital_port;
}
@@ -132,9 +140,13 @@ void setPWMOutputChannel(void* pwmGenerator, uint32_t pin, int32_t* status) {
*/
bool allocateDIO(void* digital_port_pointer, bool input, int32_t* status) {
DigitalPort* port = (DigitalPort*)digital_port_pointer;
if (port == nullptr) {
*status = NULL_PARAMETER;
return false;
}
char buf[64];
snprintf(buf, 64, "DIO %d", port->port.pin);
if (DIOChannels->Allocate(port->port.pin, buf) == ~0ul) {
snprintf(buf, 64, "DIO %d", port->pin);
if (DIOChannels->Allocate(port->pin, buf) == ~0ul) {
*status = RESOURCE_IS_ALLOCATED;
return false;
}
@@ -144,8 +156,8 @@ bool allocateDIO(void* digital_port_pointer, bool input, int32_t* status) {
tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status);
if (port->port.pin < kNumHeaders) {
uint32_t bitToSet = 1 << port->port.pin;
if (port->pin < kNumHeaders) {
uint32_t bitToSet = 1 << port->pin;
if (input) {
outputEnable.Headers =
outputEnable.Headers & (~bitToSet); // clear the bit for read
@@ -154,7 +166,7 @@ bool allocateDIO(void* digital_port_pointer, bool input, int32_t* status) {
outputEnable.Headers | bitToSet; // set the bit for write
}
} else {
uint32_t bitToSet = 1 << remapMXPChannel(port->port.pin);
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
// Disable special functions on this pin
short specialFunctions =
@@ -184,7 +196,7 @@ bool allocateDIO(void* digital_port_pointer, bool input, int32_t* status) {
void freeDIO(void* digital_port_pointer, int32_t* status) {
DigitalPort* port = (DigitalPort*)digital_port_pointer;
if (!port) return;
DIOChannels->Free(port->port.pin);
DIOChannels->Free(port->pin);
}
/**
@@ -204,22 +216,20 @@ void setDIO(void* digital_port_pointer, short value, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
tDIO::tDO currentDIO = digitalSystem->readDO(status);
if (port->port.pin < kNumHeaders) {
if (port->pin < kNumHeaders) {
if (value == 0) {
currentDIO.Headers = currentDIO.Headers & ~(1 << port->port.pin);
currentDIO.Headers = currentDIO.Headers & ~(1 << port->pin);
} else if (value == 1) {
currentDIO.Headers = currentDIO.Headers | (1 << port->port.pin);
currentDIO.Headers = currentDIO.Headers | (1 << port->pin);
}
} else {
if (value == 0) {
currentDIO.MXP =
currentDIO.MXP & ~(1 << remapMXPChannel(port->port.pin));
currentDIO.MXP = currentDIO.MXP & ~(1 << remapMXPChannel(port->pin));
} else if (value == 1) {
currentDIO.MXP =
currentDIO.MXP | (1 << remapMXPChannel(port->port.pin));
currentDIO.MXP = currentDIO.MXP | (1 << remapMXPChannel(port->pin));
}
uint32_t bitToSet = 1 << remapMXPChannel(port->port.pin);
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
short specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
@@ -244,17 +254,17 @@ bool getDIO(void* digital_port_pointer, int32_t* status) {
// if it == 0, then return false
// else return true
if (port->port.pin < kNumHeaders) {
return ((currentDIO.Headers >> port->port.pin) & 1) != 0;
if (port->pin < kNumHeaders) {
return ((currentDIO.Headers >> port->pin) & 1) != 0;
} else {
// Disable special functions
uint32_t bitToSet = 1 << remapMXPChannel(port->port.pin);
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
short specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
status);
return ((currentDIO.MXP >> remapMXPChannel(port->port.pin)) & 1) != 0;
return ((currentDIO.MXP >> remapMXPChannel(port->pin)) & 1) != 0;
}
}
@@ -269,16 +279,15 @@ bool getDIODirection(void* digital_port_pointer, int32_t* status) {
DigitalPort* port = (DigitalPort*)digital_port_pointer;
tDIO::tOutputEnable currentOutputEnable =
digitalSystem->readOutputEnable(status);
// Shift 00000001 over port->port.pin-1 places.
// Shift 00000001 over port->pin-1 places.
// AND it against the currentOutputEnable
// if it == 0, then return false
// else return true
if (port->port.pin < kNumHeaders) {
return ((currentOutputEnable.Headers >> port->port.pin) & 1) != 0;
if (port->pin < kNumHeaders) {
return ((currentOutputEnable.Headers >> port->pin) & 1) != 0;
} else {
return ((currentOutputEnable.MXP >> remapMXPChannel(port->port.pin)) & 1) !=
0;
return ((currentOutputEnable.MXP >> remapMXPChannel(port->pin)) & 1) != 0;
}
}
@@ -294,10 +303,10 @@ void pulse(void* digital_port_pointer, double pulseLength, int32_t* status) {
DigitalPort* port = (DigitalPort*)digital_port_pointer;
tDIO::tPulse pulse;
if (port->port.pin < kNumHeaders) {
pulse.Headers = 1 << port->port.pin;
if (port->pin < kNumHeaders) {
pulse.Headers = 1 << port->pin;
} else {
pulse.MXP = 1 << remapMXPChannel(port->port.pin);
pulse.MXP = 1 << remapMXPChannel(port->pin);
}
digitalSystem->writePulseLength(
@@ -315,10 +324,10 @@ bool isPulsing(void* digital_port_pointer, int32_t* status) {
DigitalPort* port = (DigitalPort*)digital_port_pointer;
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
if (port->port.pin < kNumHeaders) {
return (pulseRegister.Headers & (1 << port->port.pin)) != 0;
if (port->pin < kNumHeaders) {
return (pulseRegister.Headers & (1 << port->pin)) != 0;
} else {
return (pulseRegister.MXP & (1 << remapMXPChannel(port->port.pin))) != 0;
return (pulseRegister.MXP & (1 << remapMXPChannel(port->pin))) != 0;
}
}
@@ -345,10 +354,10 @@ void setFilterSelect(void* digital_port_pointer, int filter_index,
DigitalPort* port = (DigitalPort*)digital_port_pointer;
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
if (port->port.pin < kNumHeaders) {
digitalSystem->writeFilterSelectHdr(port->port.pin, filter_index, status);
if (port->pin < kNumHeaders) {
digitalSystem->writeFilterSelectHdr(port->pin, filter_index, status);
} else {
digitalSystem->writeFilterSelectMXP(remapMXPChannel(port->port.pin),
digitalSystem->writeFilterSelectMXP(remapMXPChannel(port->pin),
filter_index, status);
}
}
@@ -365,10 +374,10 @@ int getFilterSelect(void* digital_port_pointer, int32_t* status) {
DigitalPort* port = (DigitalPort*)digital_port_pointer;
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
if (port->port.pin < kNumHeaders) {
return digitalSystem->readFilterSelectHdr(port->port.pin, status);
if (port->pin < kNumHeaders) {
return digitalSystem->readFilterSelectHdr(port->pin, status);
} else {
return digitalSystem->readFilterSelectMXP(remapMXPChannel(port->port.pin),
return digitalSystem->readFilterSelectMXP(remapMXPChannel(port->pin),
status);
}
}

View File

@@ -13,7 +13,6 @@
#include "ChipObject.h"
#include "FRC_NetworkCommunication/LoadOut.h"
#include "HAL/HAL.h"
#include "HAL/Port.h"
#include "HAL/cpp/Resource.h"
#include "HAL/cpp/priority_mutex.h"
@@ -78,7 +77,7 @@ void initializeDigital(int32_t* status) {
for (uint32_t pwm_index = 0; pwm_index < kPwmPins; pwm_index++) {
// Initialize port structure
DigitalPort digital_port;
digital_port.port.pin = pwm_index;
digital_port.pin = pwm_index;
setPWM(&digital_port, kPwmDisabled, status);
setPWMPeriodScale(&digital_port, 3, status); // Set all to 4x by default.

View File

@@ -10,7 +10,6 @@
#include <stdint.h>
#include "ChipObject.h"
#include "HAL/Port.h"
#include "HAL/cpp/Resource.h"
namespace hal {
@@ -62,7 +61,7 @@ extern hal::Resource* PWMChannels;
extern bool digitalSystemsInitialized;
struct DigitalPort {
Port port;
uint8_t pin;
uint32_t PWMGeneratorID;
};

View File

@@ -24,8 +24,8 @@
#include "FRC_NetworkCommunication/LoadOut.h"
#include "FRC_NetworkCommunication/UsageReporting.h"
#include "HAL/Errors.h"
#include "HAL/Port.h"
#include "ctre/ctre.h"
#include "handles/HandlesInternal.h"
#include "visa/visa.h"
const uint32_t solenoid_kNumDO7_0Elements = 8;
@@ -42,28 +42,21 @@ static uint32_t timeEpoch = 0;
static uint32_t prevFPGATime = 0;
static HalNotifierHandle rolloverNotifier = 0;
using namespace hal;
extern "C" {
void* getPort(uint8_t pin) {
Port* port = new Port();
port->pin = pin;
port->module = 1;
return port;
}
HalPortHandle getPort(uint8_t pin) { return createPortHandle(pin, 1); }
/**
* @deprecated Uses module numbers
*/
void* getPortWithModule(uint8_t module, uint8_t pin) {
Port* port = new Port();
port->pin = pin;
port->module = module;
return port;
HalPortHandle getPortWithModule(uint8_t module, uint8_t pin) {
return createPortHandle(pin, module);
}
void freePort(void* port_pointer) {
Port* port = (Port*)port_pointer;
delete port;
void freePort(HalPortHandle port_handle) {
// noop
}
const char* getHALErrorMessage(int32_t code) {

View File

@@ -8,6 +8,7 @@
#include "HAL/I2C.h"
#include "DigitalInternal.h"
#include "HAL/DIO.h"
#include "HAL/HAL.h"
#include "i2clib/i2c-lib.h"
@@ -32,6 +33,7 @@ extern "C" {
*/
void i2CInitialize(uint8_t port, int32_t* status) {
initializeDigital(status);
if (*status != 0) return;
if (port > 1) {
// Set port out of range error here
@@ -49,8 +51,12 @@ void i2CInitialize(uint8_t port, int32_t* status) {
} else if (port == 1) {
i2CMXPObjCount++;
if (i2CMXPHandle > 0) return;
if (!allocateDIO(getPort(24), false, status)) return;
if (!allocateDIO(getPort(25), false, status)) return;
if (!allocateDIO(initializeDigitalPort(getPort(24), status), false,
status))
return;
if (!allocateDIO(initializeDigitalPort(getPort(25), status), false,
status))
return;
digitalSystem->writeEnableMXPSpecialFunction(
digitalSystem->readEnableMXPSpecialFunction(status) | 0xC000, status);
i2CMXPHandle = i2clib_open("/dev/i2c-1");

View File

@@ -17,7 +17,7 @@ using namespace hal;
extern "C" {
bool checkPWMChannel(void* digital_port_pointer) {
DigitalPort* port = (DigitalPort*)digital_port_pointer;
return port->port.pin < kPwmPins;
return port->pin < kPwmPins;
}
/**
@@ -53,10 +53,10 @@ void setPWM(void* digital_port_pointer, unsigned short value, int32_t* status) {
return;
}
if (port->port.pin < tPWM::kNumHdrRegisters) {
pwmSystem->writeHdr(port->port.pin, value, status);
if (port->pin < tPWM::kNumHdrRegisters) {
pwmSystem->writeHdr(port->pin, value, status);
} else {
pwmSystem->writeMXP(port->port.pin - tPWM::kNumHdrRegisters, value, status);
pwmSystem->writeMXP(port->pin - tPWM::kNumHdrRegisters, value, status);
}
}
@@ -72,10 +72,10 @@ unsigned short getPWM(void* digital_port_pointer, int32_t* status) {
return 0;
}
if (port->port.pin < tPWM::kNumHdrRegisters) {
return pwmSystem->readHdr(port->port.pin, status);
if (port->pin < tPWM::kNumHdrRegisters) {
return pwmSystem->readHdr(port->pin, status);
} else {
return pwmSystem->readMXP(port->port.pin - tPWM::kNumHdrRegisters, status);
return pwmSystem->readMXP(port->pin - tPWM::kNumHdrRegisters, status);
}
}
@@ -85,8 +85,8 @@ void latchPWMZero(void* digital_port_pointer, int32_t* status) {
return;
}
pwmSystem->writeZeroLatch(port->port.pin, true, status);
pwmSystem->writeZeroLatch(port->port.pin, false, status);
pwmSystem->writeZeroLatch(port->pin, true, status);
pwmSystem->writeZeroLatch(port->pin, false, status);
}
/**
@@ -102,11 +102,11 @@ void setPWMPeriodScale(void* digital_port_pointer, uint32_t squelchMask,
return;
}
if (port->port.pin < tPWM::kNumPeriodScaleHdrElements) {
pwmSystem->writePeriodScaleHdr(port->port.pin, squelchMask, status);
if (port->pin < tPWM::kNumPeriodScaleHdrElements) {
pwmSystem->writePeriodScaleHdr(port->pin, squelchMask, status);
} else {
pwmSystem->writePeriodScaleMXP(
port->port.pin - tPWM::kNumPeriodScaleHdrElements, squelchMask, status);
pwmSystem->writePeriodScaleMXP(port->pin - tPWM::kNumPeriodScaleHdrElements,
squelchMask, status);
}
}
@@ -117,19 +117,18 @@ bool allocatePWMChannel(void* digital_port_pointer, int32_t* status) {
}
char buf[64];
snprintf(buf, 64, "PWM %d", port->port.pin);
if (PWMChannels->Allocate(port->port.pin, buf) == ~0ul) {
snprintf(buf, 64, "PWM %d", port->pin);
if (PWMChannels->Allocate(port->pin, buf) == ~0ul) {
*status = RESOURCE_IS_ALLOCATED;
return false;
}
if (port->port.pin > tPWM::kNumHdrRegisters - 1) {
snprintf(buf, 64, "PWM %d and DIO %d", port->port.pin,
remapMXPPWMChannel(port->port.pin) + 10);
if (DIOChannels->Allocate(remapMXPPWMChannel(port->port.pin) + 10, buf) ==
~0ul)
if (port->pin > tPWM::kNumHdrRegisters - 1) {
snprintf(buf, 64, "PWM %d and DIO %d", port->pin,
remapMXPPWMChannel(port->pin) + 10);
if (DIOChannels->Allocate(remapMXPPWMChannel(port->pin) + 10, buf) == ~0ul)
return false;
uint32_t bitToSet = 1 << remapMXPPWMChannel(port->port.pin);
uint32_t bitToSet = 1 << remapMXPPWMChannel(port->pin);
short specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions | bitToSet,
@@ -145,10 +144,10 @@ void freePWMChannel(void* digital_port_pointer, int32_t* status) {
return;
}
PWMChannels->Free(port->port.pin);
if (port->port.pin > tPWM::kNumHdrRegisters - 1) {
DIOChannels->Free(remapMXPPWMChannel(port->port.pin) + 10);
uint32_t bitToUnset = 1 << remapMXPPWMChannel(port->port.pin);
PWMChannels->Free(port->pin);
if (port->pin > tPWM::kNumHdrRegisters - 1) {
DIOChannels->Free(remapMXPPWMChannel(port->pin) + 10);
uint32_t bitToUnset = 1 << remapMXPPWMChannel(port->pin);
short specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToUnset,

View File

@@ -22,7 +22,7 @@ constexpr uint32_t kRelayPins = 8;
extern "C" {
bool checkRelayChannel(void* digital_port_pointer) {
DigitalPort* port = (DigitalPort*)digital_port_pointer;
return port->port.pin < kRelayPins;
return port->pin < kRelayPins;
}
/**
@@ -60,9 +60,9 @@ void setRelayForward(void* digital_port_pointer, bool on, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(digitalRelayMutex);
uint8_t forwardRelays = relaySystem->readValue_Forward(status);
if (on)
forwardRelays |= 1 << port->port.pin;
forwardRelays |= 1 << port->pin;
else
forwardRelays &= ~(1 << port->port.pin);
forwardRelays &= ~(1 << port->pin);
relaySystem->writeValue_Forward(forwardRelays, status);
}
}
@@ -83,9 +83,9 @@ void setRelayReverse(void* digital_port_pointer, bool on, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(digitalRelayMutex);
uint8_t reverseRelays = relaySystem->readValue_Reverse(status);
if (on)
reverseRelays |= 1 << port->port.pin;
reverseRelays |= 1 << port->pin;
else
reverseRelays &= ~(1 << port->port.pin);
reverseRelays &= ~(1 << port->pin);
relaySystem->writeValue_Reverse(reverseRelays, status);
}
}
@@ -100,7 +100,7 @@ bool getRelayForward(void* digital_port_pointer, int32_t* status) {
}
uint8_t forwardRelays = relaySystem->readValue_Forward(status);
return (forwardRelays & (1 << port->port.pin)) != 0;
return (forwardRelays & (1 << port->pin)) != 0;
}
/**
@@ -113,6 +113,6 @@ bool getRelayReverse(void* digital_port_pointer, int32_t* status) {
}
uint8_t reverseRelays = relaySystem->readValue_Reverse(status);
return (reverseRelays & (1 << port->port.pin)) != 0;
return (reverseRelays & (1 << port->pin)) != 0;
}
}

View File

@@ -10,6 +10,7 @@
#include <atomic>
#include "DigitalInternal.h"
#include "HAL/DIO.h"
#include "HAL/HAL.h"
#include "spilib/spi-lib.h"
@@ -78,19 +79,24 @@ void spiInitialize(uint8_t port, int32_t* status) {
break;
case 4:
initializeDigital(status);
if (!allocateDIO(getPort(14), false, status)) {
if (*status != 0) return;
if (!allocateDIO(initializeDigitalPort(getPort(14), status), false,
status)) {
printf("Failed to allocate DIO 14\n");
return;
}
if (!allocateDIO(getPort(15), false, status)) {
if (!allocateDIO(initializeDigitalPort(getPort(15), status), false,
status)) {
printf("Failed to allocate DIO 15\n");
return;
}
if (!allocateDIO(getPort(16), true, status)) {
if (!allocateDIO(initializeDigitalPort(getPort(16), status), true,
status)) {
printf("Failed to allocate DIO 16\n");
return;
}
if (!allocateDIO(getPort(17), false, status)) {
if (!allocateDIO(initializeDigitalPort(getPort(17), status), false,
status)) {
printf("Failed to allocate DIO 17\n");
return;
}

View File

@@ -10,8 +10,8 @@
#include "ChipObject.h"
#include "FRC_NetworkCommunication/LoadOut.h"
#include "HAL/Errors.h"
#include "HAL/Port.h"
#include "ctre/PCM.h"
#include "handles/HandlesInternal.h"
static const int NUM_MODULE_NUMBERS = 63;
@@ -28,15 +28,23 @@ void initializePCM(int module) {
}
}
using namespace hal;
extern "C" {
void* initializeSolenoidPort(void* port_pointer, int32_t* status) {
Port* port = (Port*)port_pointer;
initializePCM(port->module);
void* initializeSolenoidPort(HalPortHandle port_handle, int32_t* status) {
int16_t pin = getPortHandlePin(port_handle);
int16_t module = getPortHandleModule(port_handle);
if (pin == HAL_HANDLE_INVALID_TYPE) {
*status = PARAMETER_OUT_OF_RANGE;
return nullptr;
}
initializePCM(module);
solenoid_port_t* solenoid_port = new solenoid_port_t;
solenoid_port->module = PCM_modules[port->module];
solenoid_port->pin = port->pin;
solenoid_port->module = PCM_modules[module];
solenoid_port->pin = pin;
return solenoid_port;
}

View File

@@ -11,6 +11,19 @@
#include "UnlimitedHandleResource.h"
namespace hal {
HalPortHandle createPortHandle(uint8_t pin, uint8_t module) {
// set last 8 bits, then shift to first 8 bits
HalPortHandle handle = static_cast<HalPortHandle>(HalHandleEnum::Port);
handle = handle << 24;
// shift module and add to 3rd set of 8 bits
int32_t temp = module;
temp = (temp << 8) & 0xff00;
handle += temp;
// add pin to last 8 bits
handle += pin;
return handle;
}
HalHandle createHandle(int16_t index, HalHandleEnum handleType) {
if (index < 0) return HAL_HANDLE_NEGATIVE_INDEX;
uint8_t hType = static_cast<uint8_t>(handleType);

View File

@@ -42,5 +42,30 @@ static inline int16_t getHandleTypedIndex(HalHandle handle,
return getHandleIndex(handle);
}
/* specialized functions for Port handle
* Port Handle Data Layout
* Bits 0-7: Pin Number
* Bits 8-15: Module Number
* Bits 16-23: Unused
* Bits 24-30: Handle Type
* Bit 31: 1 if handle error, 0 if no error
*/
// using a 16 bit value so we can store 0-255 and still report error
static inline int16_t getPortHandlePin(HalPortHandle handle) {
if (!isHandleType(handle, HalHandleEnum::Port))
return HAL_HANDLE_INVALID_TYPE;
return (uint8_t)(handle & 0xff);
}
// using a 16 bit value so we can store 0-255 and still report error
static inline int16_t getPortHandleModule(HalPortHandle handle) {
if (!isHandleType(handle, HalHandleEnum::Port))
return HAL_HANDLE_INVALID_TYPE;
return (uint8_t)((handle >> 8) & 0xff);
}
HalPortHandle createPortHandle(uint8_t pin, uint8_t module);
HalHandle createHandle(int16_t index, HalHandleEnum handleType);
}

View File

@@ -7,7 +7,6 @@
#include "AnalogInput.h"
#include "HAL/HAL.h"
#include "HAL/Port.h"
#include "LiveWindow/LiveWindow.h"
#include "Resource.h"
#include "Timer.h"
@@ -45,7 +44,7 @@ AnalogInput::AnalogInput(uint32_t channel) {
m_channel = channel;
void* port = getPort(channel);
HalPortHandle port = getPort(channel);
int32_t status = 0;
m_port = initializeAnalogInputPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));

View File

@@ -7,7 +7,6 @@
#include "AnalogOutput.h"
#include "HAL/HAL.h"
#include "HAL/Port.h"
#include "LiveWindow/LiveWindow.h"
#include "Resource.h"
#include "WPIErrors.h"
@@ -47,7 +46,7 @@ AnalogOutput::AnalogOutput(uint32_t channel) {
m_channel = channel;
void* port = getPort(m_channel);
HalPortHandle port = getPort(m_channel);
int32_t status = 0;
m_port = initializeAnalogOutputPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));

View File

@@ -9,7 +9,6 @@
#include "AnalogInput.h"
#include "HAL/HAL.h"
#include "HAL/Port.h"
#include "Resource.h"
#include "WPIErrors.h"
@@ -22,7 +21,7 @@
* on-board 4-7 are on the MXP port.
*/
AnalogTrigger::AnalogTrigger(int32_t channel) {
void* port = getPort(channel);
HalPortHandle port = getPort(channel);
int32_t status = 0;
uint32_t index = 0;
m_trigger = initializeAnalogTrigger(port, &index, &status);

View File

@@ -9,7 +9,6 @@
#include "FRC_NetworkCommunication/LoadOut.h"
#include "HAL/HAL.h"
#include "HAL/Port.h"
#include "WPIErrors.h"
const uint32_t SensorBase::kDigitalChannels;
@@ -33,7 +32,7 @@ void* SensorBase::m_pwm_ports[kPwmChannels];
SensorBase::SensorBase() {
if (!portsInitialized) {
for (uint32_t i = 0; i < kDigitalChannels; i++) {
void* port = getPort(i);
HalPortHandle port = getPort(i);
int32_t status = 0;
m_digital_ports[i] = initializeDigitalPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
@@ -41,7 +40,7 @@ SensorBase::SensorBase() {
}
for (uint32_t i = 0; i < kRelayChannels; i++) {
void* port = getPort(i);
HalPortHandle port = getPort(i);
int32_t status = 0;
m_relay_ports[i] = initializeDigitalPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
@@ -49,7 +48,7 @@ SensorBase::SensorBase() {
}
for (uint32_t i = 0; i < kPwmChannels; i++) {
void* port = getPort(i);
HalPortHandle port = getPort(i);
int32_t status = 0;
m_pwm_ports[i] = initializeDigitalPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));

View File

@@ -20,7 +20,7 @@ std::unique_ptr<Resource> SolenoidBase::m_allocated;
SolenoidBase::SolenoidBase(uint8_t moduleNumber)
: m_moduleNumber(moduleNumber) {
for (uint32_t i = 0; i < kSolenoidChannels; i++) {
void* port = getPortWithModule(moduleNumber, i);
HalPortHandle port = getPortWithModule(moduleNumber, i);
int32_t status = 0;
SolenoidBase::m_ports[moduleNumber][i] =
initializeSolenoidPort(port, &status);

View File

@@ -31,14 +31,14 @@ extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initializeAnalogInputPort
* Signature: (J)J
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogInputPort(
JNIEnv *env, jclass, jlong id) {
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
JNIEnv *env, jclass, jint id) {
ANALOGJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)id;
int32_t status = 0;
void *analog = initializeAnalogInputPort((void *)id, &status);
void *analog = initializeAnalogInputPort((HalPortHandle)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog;
CheckStatus(env, status);
@@ -60,14 +60,14 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_freeAnalogInputPort(
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initializeAnalogOutputPort
* Signature: (J)J
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort(
JNIEnv *env, jclass, jlong id) {
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
JNIEnv *env, jclass, jint id) {
ANALOGJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)id;
int32_t status = 0;
void *analog = initializeAnalogOutputPort((void *)id, &status);
void *analog = initializeAnalogOutputPort((HalPortHandle)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog;
CheckStatus(env, status);
@@ -521,19 +521,19 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput(
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initializeAnalogTrigger
* Signature: (JLjava/nio/IntBuffer;)J
* Signature: (ILjava/nio/IntBuffer;)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger(
JNIEnv *env, jclass, jlong id, jobject index) {
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
JNIEnv *env, jclass, jint id, jobject index) {
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (HalPortHandle)id;
jint *indexPtr = (jint *)env->GetDirectBufferAddress(index);
ANALOGJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr;
int32_t status = 0;
void *analogTrigger =
initializeAnalogTrigger((void *)id, (uint32_t *)indexPtr, &status);
initializeAnalogTrigger((HalPortHandle)id, (uint32_t *)indexPtr, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AnalogTrigger Ptr = " << analogTrigger;
CheckStatus(env, status);

View File

@@ -29,15 +29,15 @@ extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: initializeDigitalPort
* Signature: (J)J;
* Signature: (I)J;
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDigitalPort(
JNIEnv *env, jclass, jlong id) {
JNIEnv *env, jclass, jint id) {
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI initializeDigitalPort";
DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
DIOJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)id;
int32_t status = 0;
void *dio = initializeDigitalPort((void *)id, &status);
void *dio = initializeDigitalPort((HalPortHandle)id, &status);
DIOJNI_LOG(logDEBUG) << "Status = " << status;
DIOJNI_LOG(logDEBUG) << "DIO Ptr = " << dio;
CheckStatus(env, status);

View File

@@ -18,46 +18,46 @@ extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
* Method: getPortWithModule
* Signature: (BB)J
* Signature: (BB)I
*/
JNIEXPORT jlong JNICALL
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPortWithModule(
JNIEnv* env, jclass, jbyte module, jbyte pin) {
// FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
// FILE_LOG(logDEBUG) << "Module = " << (jint)module;
// FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
void* port = getPortWithModule(module, pin);
// FILE_LOG(logDEBUG) << "Port Ptr = " << port;
return (jlong)port;
HalPortHandle port = getPortWithModule(module, pin);
// FILE_LOG(logDEBUG) << "Port Handle = " << port;
return (jint)port;
}
/*
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
* Method: getPort
* Signature: (BB)J
* Signature: (B)I
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort(
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort(
JNIEnv* env, jclass, jbyte pin) {
// FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
// FILE_LOG(logDEBUG) << "Module = " << (jint)module;
// FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
void* port = getPort(pin);
// FILE_LOG(logDEBUG) << "Port Ptr = " << port;
return (jlong)port;
HalPortHandle port = getPort(pin);
// FILE_LOG(logDEBUG) << "Port Handle = " << port;
return (jint)port;
}
/*
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
* Method: freePort
* Signature: (J)V
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_freePort(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
// FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
// FILE_LOG(logDEBUG) << "Module = " << (jint)module;
// FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
freePort((void*)id);
// FILE_LOG(logDEBUG) << "Port Ptr = " << port;
freePort((HalPortHandle)id);
// FILE_LOG(logDEBUG) << "Port Handle = " << port;
}
} // extern "C"

View File

@@ -26,21 +26,21 @@ extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: initializeSolenoidPort
* Signature: (J)J
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort(
JNIEnv *env, jclass, jlong port_pointer) {
JNIEnv *env, jclass, jint port_handle) {
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI initializeSolenoidPort";
SOLENOIDJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)port_pointer;
char *aschars = (char *)port_pointer;
SOLENOIDJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)port_handle;
char *aschars = (char *)port_handle;
SOLENOIDJNI_LOG(logDEBUG) << '\t' << (int)aschars[0] << '\t'
<< (int)aschars[1] << std::endl;
int32_t status = 0;
void *solenoid_port_pointer =
initializeSolenoidPort((void *)port_pointer, &status);
initializeSolenoidPort((HalPortHandle)port_handle, &status);
SOLENOIDJNI_LOG(logDEBUG) << "Status = " << status;
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = "
@@ -68,19 +68,6 @@ Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_freeSolenoidPort(
freeSolenoidPort((void *)id);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: getPortWithModule
* Signature: (BB)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWithModule(
JNIEnv *env, jclass, jbyte module, jbyte channel) {
void *port_pointer = getPortWithModule(module, channel);
return (jlong)port_pointer;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: setSolenoid

View File

@@ -59,8 +59,8 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
throw new AllocationException("Analog input channel " + m_channel + " is already allocated");
}
final long portPointer = AnalogJNI.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogInputPort(portPointer);
final int portHandle = AnalogJNI.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogInputPort(portHandle);
LiveWindow.addSensor("AnalogInput", channel, this);
UsageReporting.report(tResourceType.kResourceType_AnalogChannel, channel);

View File

@@ -42,8 +42,8 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
throw new AllocationException("Analog output channel " + m_channel + " is already allocated");
}
final long portPointer = AnalogJNI.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogOutputPort(portPointer);
final int portHandle = AnalogJNI.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogOutputPort(portHandle);
LiveWindow.addSensor("AnalogOutput", channel, this);
UsageReporting.report(tResourceType.kResourceType_AnalogOutput, channel);

View File

@@ -51,12 +51,12 @@ public class AnalogTrigger {
* @param channel the port to use for the analog trigger
*/
public AnalogTrigger(final int channel) {
final long portPointer = AnalogJNI.getPort((byte) channel);
final int portHandle = AnalogJNI.getPort((byte) channel);
ByteBuffer index = ByteBuffer.allocateDirect(4);
index.order(ByteOrder.LITTLE_ENDIAN);
m_port =
AnalogJNI.initializeAnalogTrigger(portPointer, index.asIntBuffer());
AnalogJNI.initializeAnalogTrigger(portHandle, index.asIntBuffer());
m_index = index.asIntBuffer().get(0);
UsageReporting.report(tResourceType.kResourceType_AnalogTrigger, channel);

View File

@@ -35,8 +35,8 @@ public abstract class DigitalSource extends InterruptableSensorBase {
throw new AllocationException("Digital input " + m_channel + " is already allocated");
}
long portPointer = DIOJNI.getPort((byte) channel);
m_port = DIOJNI.initializeDigitalPort(portPointer);
int portHandle = DIOJNI.getPort((byte) channel);
m_port = DIOJNI.initializeDigitalPort(portHandle);
DIOJNI.allocateDIO(m_port, input);
}

View File

@@ -57,8 +57,8 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
+ m_moduleNumber + " is already allocated");
}
long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
m_solenoidPort = SolenoidJNI.initializeSolenoidPort(port);
int portHandle = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
m_solenoidPort = SolenoidJNI.initializeSolenoidPort(portHandle);
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber);

View File

@@ -28,8 +28,8 @@ public abstract class SolenoidBase extends SensorBase {
m_moduleNumber = moduleNumber;
m_ports = new long[SensorBase.kSolenoidChannels];
for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
long port = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) i);
m_ports[i] = SolenoidJNI.initializeSolenoidPort(port);
int portHandle = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) i);
m_ports[i] = SolenoidJNI.initializeSolenoidPort(portHandle);
}
}

View File

@@ -33,11 +33,11 @@ public class AnalogJNI extends JNIWrapper {
int kFallingPulse = 3;
}
public static native long initializeAnalogInputPort(long portPointer);
public static native long initializeAnalogInputPort(int halPortHandle);
public static native void freeAnalogInputPort(long portPointer);
public static native long initializeAnalogOutputPort(long portPointer);
public static native long initializeAnalogOutputPort(int halPortHandle);
public static native void freeAnalogOutputPort(long portPointer);
@@ -94,7 +94,7 @@ public class AnalogJNI extends JNIWrapper {
public static native void getAccumulatorOutput(long analogPortPointer, LongBuffer value,
IntBuffer count);
public static native long initializeAnalogTrigger(long portPointer, IntBuffer index);
public static native long initializeAnalogTrigger(int halPortHandle, IntBuffer index);
public static native void cleanAnalogTrigger(long analogTriggerPointer);

View File

@@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj.hal;
@SuppressWarnings("AbbreviationAsWordInName")
public class DIOJNI extends JNIWrapper {
public static native long initializeDigitalPort(long portPointer);
public static native long initializeDigitalPort(int halPortHandle);
public static native void freeDigitalPort(long portPointer);

View File

@@ -59,9 +59,9 @@ public class JNIWrapper {
}
}
public static native long getPortWithModule(byte module, byte pin);
public static native int getPortWithModule(byte module, byte pin);
public static native long getPort(byte pin);
public static native int getPort(byte pin);
public static native void freePort(long portPointer);
public static native void freePort(int halPortHandle);
}

View File

@@ -8,12 +8,10 @@
package edu.wpi.first.wpilibj.hal;
public class SolenoidJNI extends JNIWrapper {
public static native long initializeSolenoidPort(long portPointer);
public static native long initializeSolenoidPort(int halPortHandle);
public static native void freeSolenoidPort(long portPointer);
public static native long getPortWithModule(byte module, byte channel);
public static native void setSolenoid(long port, boolean on);
public static native boolean getSolenoid(long port);