[hal] Expose more FPGA functionality (#6942)

- function to reset user rail fault counters
- function to get comms disable count
- correct docs for user rail count functions
This commit is contained in:
Ryan Blue
2024-08-11 02:25:02 -04:00
committed by GitHub
parent 59dc29e701
commit 19b478a33b
13 changed files with 124 additions and 9 deletions

View File

@@ -195,6 +195,14 @@ public final class HAL extends JNIWrapper {
*/
public static native boolean getRSLState();
/**
* Gets the number of times the system has been disabled due to communication errors with the
* Driver Station.
*
* @return number of disables due to communication errors.
*/
public static native int getCommsDisableCount();
/**
* Gets if the system time is valid.
*

View File

@@ -143,6 +143,9 @@ public class PowerJNI extends JNIWrapper {
*/
public static native int getUserCurrentFaults3V3();
/** Resets the overcurrent fault counters for all user rails to 0. */
public static native void resetUserCurrentFaults();
/**
* Set the voltage the roboRIO will brownout and disable all outputs.
*

View File

@@ -452,6 +452,15 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) {
return !(watchdog->readStatus_PowerAlive(status));
}
int32_t HAL_GetCommsDisableCount(int32_t* status) {
hal::init::CheckInit();
if (!watchdog) {
*status = NiFpga_Status_ResourceNotInitialized;
return 0;
}
return watchdog->readStatus_SysDisableCount(status);
}
HAL_Bool HAL_GetRSLState(int32_t* status) {
hal::init::CheckInit();
if (!global) {

View File

@@ -118,6 +118,11 @@ void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) {
power->writeDisable_User3V3(!enabled, status);
}
void HAL_ResetUserCurrentFaults(int32_t* status) {
initializePower(status);
power->strobeResetFaultCounts(status);
}
void HAL_SetBrownoutVoltage(double voltage, int32_t* status) {
initializePower(status);
if (voltage < 0) {

View File

@@ -154,6 +154,21 @@ Java_edu_wpi_first_hal_HAL_getBrownedOut
return val;
}
/*
* Class: edu_wpi_first_hal_HAL
* Method: getCommsDisableCount
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_HAL_getCommsDisableCount
(JNIEnv* env, jclass)
{
int32_t status = 0;
int32_t val = HAL_GetCommsDisableCount(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_hal_HAL
* Method: getRSLState

View File

@@ -264,6 +264,20 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrentFaults3V3
return val;
}
/*
* Class: edu_wpi_first_hal_PowerJNI
* Method: resetUserCurrentFaults
* Signature: ()V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PowerJNI_resetUserCurrentFaults
(JNIEnv* env, jclass)
{
int32_t status = 0;
HAL_ResetUserCurrentFaults(&status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_PowerJNI
* Method: setBrownoutVoltage

View File

@@ -139,6 +139,13 @@ HAL_Bool HAL_GetSystemActive(int32_t* status);
*/
HAL_Bool HAL_GetBrownedOut(int32_t* status);
/**
* Gets the number of times the system has been disabled due to communication
* errors with the Driver Station.
* @return number of disables due to communication errors.
*/
int32_t HAL_GetCommsDisableCount(int32_t* status);
/**
* Gets a port handle for a specific channel.
*

View File

@@ -59,7 +59,7 @@ double HAL_GetUserCurrent6V(int32_t* status);
HAL_Bool HAL_GetUserActive6V(int32_t* status);
/**
* Gets the fault count for the 6V rail.
* Gets the fault count for the 6V rail. Capped at 255.
*
* @param[out] status the error code, or 0 for success
* @return the number of 6V fault counts
@@ -99,7 +99,7 @@ double HAL_GetUserCurrent5V(int32_t* status);
HAL_Bool HAL_GetUserActive5V(int32_t* status);
/**
* Gets the fault count for the 5V rail.
* Gets the fault count for the 5V rail. Capped at 255.
*
* @param[out] status the error code, or 0 for success
* @return the number of 5V fault counts
@@ -139,7 +139,7 @@ double HAL_GetUserCurrent3V3(int32_t* status);
HAL_Bool HAL_GetUserActive3V3(int32_t* status);
/**
* Gets the fault count for the 3V3 rail.
* Gets the fault count for the 3V3 rail. Capped at 255.
*
* @param[out] status the error code, or 0 for success
* @return the number of 3V3 fault counts
@@ -154,6 +154,12 @@ int32_t HAL_GetUserCurrentFaults3V3(int32_t* status);
*/
void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status);
/**
* Resets the overcurrent fault counters for all user rails to 0.
* @param[out] status the error code, or 0 for success
*/
void HAL_ResetUserCurrentFaults(int32_t* status);
/**
* Get the current brownout voltage setting.
*

View File

@@ -339,6 +339,10 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) {
return false; // Figure out if we need to detect a brownout condition
}
int32_t HAL_GetCommsDisableCount(int32_t* status) {
return 0;
}
HAL_Bool HAL_GetRSLState(int32_t* status) {
return false;
}

View File

@@ -59,6 +59,11 @@ int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
return SimRoboRioData->userFaults3V3;
}
void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) {}
void HAL_ResetUserCurrentFaults(int32_t* status) {
SimRoboRioData->userFaults3V3 = 0;
SimRoboRioData->userFaults5V = 0;
SimRoboRioData->userFaults6V = 0;
}
void HAL_SetBrownoutVoltage(double voltage, int32_t* status) {
SimRoboRioData->brownoutVoltage = voltage;
}

View File

@@ -84,6 +84,13 @@ bool RobotController::IsBrownedOut() {
return retVal;
}
int RobotController::GetCommsDisableCount() {
int32_t status = 0;
int retVal = HAL_GetCommsDisableCount(&status);
FRC_CheckErrorStatus(status, "GetCommsDisableCount");
return retVal;
}
bool RobotController::GetRSLState() {
int32_t status = 0;
bool retVal = HAL_GetRSLState(&status);
@@ -214,6 +221,12 @@ int RobotController::GetFaultCount6V() {
return retVal;
}
void RobotController::ResetRailFaultCounts() {
int32_t status = 0;
HAL_ResetUserCurrentFaults(&status);
FRC_CheckErrorStatus(status, "ResetRailFaultCounts");
}
units::volt_t RobotController::GetBrownoutVoltage() {
int32_t status = 0;
double retVal = HAL_GetBrownoutVoltage(&status);

View File

@@ -115,6 +115,14 @@ class RobotController {
*/
static bool IsBrownedOut();
/**
* Gets the number of times the system has been disabled due to communication
* errors with the Driver Station.
*
* @return number of disables due to communication errors.
*/
static int GetCommsDisableCount();
/**
* Gets the current state of the Robot Signal Light (RSL)
* @return The current state of the RSL- true if on, false if off
@@ -174,7 +182,7 @@ class RobotController {
/**
* Get the count of the total current faults on the 3.3V rail since the
* controller has booted.
* code started.
*
* @return The number of faults
*/
@@ -212,7 +220,7 @@ class RobotController {
/**
* Get the count of the total current faults on the 5V rail since the
* controller has booted.
* code started.
*
* @return The number of faults
*/
@@ -250,12 +258,15 @@ class RobotController {
/**
* Get the count of the total current faults on the 6V rail since the
* controller has booted.
* code started.
*
* @return The number of faults.
*/
static int GetFaultCount6V();
/** Reset the overcurrent fault counters for all user rails to 0. */
static void ResetRailFaultCounts();
/**
* Get the current brownout voltage setting.
*

View File

@@ -117,6 +117,16 @@ public final class RobotController {
return HAL.getBrownedOut();
}
/**
* Gets the number of times the system has been disabled due to communication errors with the
* Driver Station.
*
* @return number of disables due to communication errors.
*/
public static int getCommsDisableCount() {
return HAL.getCommsDisableCount();
}
/**
* Gets the current state of the Robot Signal Light (RSL).
*
@@ -191,7 +201,7 @@ public final class RobotController {
}
/**
* Get the count of the total current faults on the 3.3V rail since the controller has booted.
* Get the count of the total current faults on the 3.3V rail since the code started.
*
* @return The number of faults
*/
@@ -237,7 +247,7 @@ public final class RobotController {
}
/**
* Get the count of the total current faults on the 5V rail since the controller has booted.
* Get the count of the total current faults on the 5V rail since the code started.
*
* @return The number of faults
*/
@@ -283,7 +293,7 @@ public final class RobotController {
}
/**
* Get the count of the total current faults on the 6V rail since the controller has booted.
* Get the count of the total current faults on the 6V rail since the code started.
*
* @return The number of faults
*/
@@ -291,6 +301,11 @@ public final class RobotController {
return PowerJNI.getUserCurrentFaults6V();
}
/** Reset the overcurrent fault counters for all user rails to 0. */
public static void resetRailFaultCounts() {
PowerJNI.resetUserCurrentFaults();
}
/**
* Get the current brownout voltage setting.
*