Skip to content

Commit

Permalink
Remove HAL_GetPort
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Jan 31, 2025
1 parent 7533b32 commit 35daaa6
Show file tree
Hide file tree
Showing 33 changed files with 61 additions and 235 deletions.
25 changes: 0 additions & 25 deletions hal/src/main/java/edu/wpi/first/hal/HAL.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,31 +211,6 @@ public static void simPeriodicAfter() {
*/
public static native boolean getSystemTimeValid();

/**
* Gets a port handle for a specific channel and module.
*
* <p>This is expected to be used for PCMs, as the roboRIO does not work with modules anymore.
*
* <p>The created handle does not need to be freed.
*
* @param module the module number
* @param channel the channel number
* @return the created port
* @see "HAL_GetPortWithModule"
*/
public static native int getPortWithModule(byte module, byte channel);

/**
* Gets a port handle for a specific channel.
*
* <p>The created handle does not need to be freed.
*
* @param channel the channel number
* @return the created port
* @see "HAL_GetPort"
*/
public static native int getPort(byte channel);

/**
* Report the usage of a resource of interest.
*
Expand Down
12 changes: 0 additions & 12 deletions hal/src/main/native/cpp/handles/HandlesInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ void HandleBase::ResetGlobalHandles() {
}
}
}
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
// set last 8 bits, then shift to first 8 bits
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::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 channel to last 8 bits
handle += channel;
return handle;
}
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType,
int16_t version) {
if (index < 0) {
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/native/cpp/jni/AnalogJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ extern "C" {
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogInputPort
(JNIEnv* env, jclass, jint id)
(JNIEnv* env, jclass, jint channel)
{
int32_t status = 0;
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
auto analog =
HAL_InitializeAnalogInputPort((HAL_PortHandle)id, stack.c_str(), &status);
HAL_InitializeAnalogInputPort(channel, stack.c_str(), &status);
CheckStatusForceThrow(env, status);
return (jint)analog;
}
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/native/cpp/jni/DIOJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ extern "C" {
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DIOJNI_initializeDIOPort
(JNIEnv* env, jclass, jint id, jboolean input)
(JNIEnv* env, jclass, jint channel, jboolean input)
{
int32_t status = 0;
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
auto dio = HAL_InitializeDIOPort(
(HAL_PortHandle)id, static_cast<uint8_t>(input), stack.c_str(), &status);
channel, static_cast<uint8_t>(input), stack.c_str(), &status);
CheckStatusForceThrow(env, status);
return (jint)dio;
}
Expand Down
26 changes: 0 additions & 26 deletions hal/src/main/native/cpp/jni/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,30 +199,4 @@ Java_edu_wpi_first_hal_HAL_getSystemTimeValid
return val;
}

/*
* Class: edu_wpi_first_hal_HAL
* Method: getPortWithModule
* Signature: (BB)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_HAL_getPortWithModule
(JNIEnv* env, jclass, jbyte module, jbyte channel)
{
HAL_PortHandle port = HAL_GetPortWithModule(module, channel);
return (jint)port;
}

/*
* Class: edu_wpi_first_hal_HAL
* Method: getPort
* Signature: (B)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_HAL_getPort
(JNIEnv* env, jclass, jbyte channel)
{
HAL_PortHandle port = HAL_GetPort(channel);
return (jint)port;
}

} // extern "C"
4 changes: 2 additions & 2 deletions hal/src/main/native/cpp/jni/PWMJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ extern "C" {
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_PWMJNI_initializePWMPort
(JNIEnv* env, jclass, jint id)
(JNIEnv* env, jclass, jint channel)
{
int32_t status = 0;
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, stack.c_str(), &status);
auto pwm = HAL_InitializePWMPort(channel, stack.c_str(), &status);
CheckStatusForceThrow(env, status);
return (jint)pwm;
}
Expand Down
2 changes: 1 addition & 1 deletion hal/src/main/native/include/hal/AnalogInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
* @return the created analog input handle
*/
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
HAL_PortHandle portHandle, const char* allocationLocation, int32_t* status);
int32_t channel, const char* allocationLocation, int32_t* status);

/**
* Frees an analog input port.
Expand Down
2 changes: 1 addition & 1 deletion hal/src/main/native/include/hal/DIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
* @param[out] status Error status variable. 0 on success.
* @return the created digital handle
*/
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel,
HAL_Bool input,
const char* allocationLocation,
int32_t* status);
Expand Down
2 changes: 1 addition & 1 deletion hal/src/main/native/include/hal/DutyCycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
* @param[out] status Error status variable. 0 on success.
* @return the created duty cycle handle
*/
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
const char* allocationLocation,
int32_t* status);

Expand Down
24 changes: 0 additions & 24 deletions hal/src/main/native/include/hal/HALBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,6 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status);
*/
int32_t HAL_GetCommsDisableCount(int32_t* status);

/**
* Gets a port handle for a specific channel.
*
* The created handle does not need to be freed.
*
* @param channel the channel number
* @return the created port
*/
HAL_PortHandle HAL_GetPort(int32_t channel);

/**
* Gets a port handle for a specific channel and module.
*
* This is expected to be used for PCMs, as the roboRIO does not work with
* modules anymore.
*
* The created handle does not need to be freed.
*
* @param module the module number
* @param channel the channel number
* @return the created port
*/
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);

/**
* Reads the microsecond-resolution timer on the FPGA.
*
Expand Down
2 changes: 1 addition & 1 deletion hal/src/main/native/include/hal/PWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {
* @param[out] status Error status variable. 0 on success.
* @return the created pwm handle
*/
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
const char* allocationLocation,
int32_t* status);

Expand Down
2 changes: 0 additions & 2 deletions hal/src/main/native/include/hal/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

typedef int32_t HAL_Handle;

typedef HAL_Handle HAL_PortHandle;

typedef HAL_Handle HAL_AnalogInputHandle;

typedef HAL_Handle HAL_AnalogOutputHandle;
Expand Down
37 changes: 0 additions & 37 deletions hal/src/main/native/include/hal/handles/HandlesInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,43 +153,6 @@ inline int16_t getHandleTypedIndex(HAL_Handle handle, HAL_HandleEnum enumType,
* 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
/**
* Gets the port channel of a port handle.
*
* @param handle the port handle
* @return the port channel
*/
inline int16_t getPortHandleChannel(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
return InvalidHandleIndex;
}
return static_cast<uint8_t>(handle & 0xff);
}

// using a 16 bit value so we can store 0-255 and still report error
/**
* Gets the port module of a port handle.
*
* @param handle the port handle
* @return the port module
*/
inline int16_t getPortHandleModule(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
return InvalidHandleIndex;
}
return static_cast<uint8_t>((handle >> 8) & 0xff);
}

/**
* Create a port handle.
*
* @param channel the channel
* @param module the module
* @return port handle for the module and channel
*/
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module);

/**
* Create a handle for a specific index, type and version.
*
Expand Down
5 changes: 2 additions & 3 deletions hal/src/main/native/sim/AnalogInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ void InitializeAnalogInput() {}

extern "C" {
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
HAL_PortHandle portHandle, const char* allocationLocation,
int32_t channel, const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex || channel >= kNumAnalogInputs) {
if (channel < 0 || channel >= kNumAnalogInputs) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input",
0, kNumAnalogInputs, channel);
Expand Down
5 changes: 2 additions & 3 deletions hal/src/main/native/sim/DIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ void InitializeDIO() {

extern "C" {

HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel,
HAL_Bool input,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();

int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
if (channel < 0 || channel >= kNumDigitalChannels) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
kNumDigitalChannels, channel);
Expand Down
4 changes: 2 additions & 2 deletions hal/src/main/native/sim/DutyCycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void InitializeDutyCycle() {
} // namespace hal::init

extern "C" {
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();
Expand All @@ -51,7 +51,7 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
}

int16_t index = getHandleIndex(handle);
SimDutyCycleData[index].digitalChannel = getPortHandleChannel(portHandle);
SimDutyCycleData[index].digitalChannel = channel;
SimDutyCycleData[index].initialized = true;
SimDutyCycleData[index].simDevice = 0;
dutyCycle->index = index;
Expand Down
19 changes: 0 additions & 19 deletions hal/src/main/native/sim/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,6 @@ void InitializeHAL() {

extern "C" {

HAL_PortHandle HAL_GetPort(int32_t channel) {
// Dont allow a number that wouldn't fit in a uint8_t
if (channel < 0 || channel >= 255) {
return HAL_kInvalidHandle;
}
return createPortHandle(channel, 1);
}

HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel) {
// Dont allow a number that wouldn't fit in a uint8_t
if (channel < 0 || channel >= 255) {
return HAL_kInvalidHandle;
}
if (module < 0 || module >= 255) {
return HAL_kInvalidHandle;
}
return createPortHandle(channel, module);
}

const char* HAL_GetErrorMessage(int32_t code) {
switch (code) {
case 0:
Expand Down
5 changes: 2 additions & 3 deletions hal/src/main/native/sim/PWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ static inline int32_t GetFullRangeScaleFactor(DigitalPort* port) {

extern "C" {

HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();

int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
if (channel < 0 || channel >= kNumPWMChannels) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0,
kNumPWMChannels, channel);
Expand Down
6 changes: 2 additions & 4 deletions hal/src/main/native/systemcore/AnalogInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ using namespace hal;
extern "C" {

HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
HAL_PortHandle portHandle, const char* allocationLocation,
int32_t* status) {
int32_t channel, const char* allocationLocation, int32_t* status) {
hal::init::CheckInit();

int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
if (channel < 0 || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog", 0,
kNumSmartIo, channel);
Expand Down
5 changes: 2 additions & 3 deletions hal/src/main/native/systemcore/DIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ void InitializeDIO() {}

extern "C" {

HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel,
HAL_Bool input,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();

int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
if (channel < 0 || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
kNumSmartIo, channel);
Expand Down
5 changes: 2 additions & 3 deletions hal/src/main/native/systemcore/DutyCycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ void InitializeDutyCycle() {}
} // namespace hal::init

extern "C" {
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();

int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
if (channel < 0 || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DutyCycle", 0,
kNumSmartIo, channel);
Expand Down
Loading

0 comments on commit 35daaa6

Please sign in to comment.