[hal] Refactor REV PDH (#3775)

Refactors retrieving the faults from the device to match the implementation that we have for the Pneumatic Hub. Instead of having a getter function for each fault, there is a single function to get all faults (sticky or normal) for use with the higher level API

Renames functions to be consistent

Removes some functions that don't need to be included in wpilib:
- Identify device - this just flashes the module LED on the device and has no use in wpilib
- Is PDH enabled - the PDH does not change state depending on robot enabled state

PDH frame and signal names were updated in our DBC, and this PR makes use of the newly generated CAN frame helper functions
This commit is contained in:
Jan-Felix Abellera
2021-12-09 14:27:06 -06:00
committed by GitHub
parent 7269a170fb
commit 41d26bee8d
5 changed files with 2076 additions and 1624 deletions

View File

@@ -55,7 +55,7 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
HAL_CleanPDP(pdpHandle);
}
*status = 0;
auto pdhHandle = HAL_REV_InitializePDH(1, allocationLocation, status);
auto pdhHandle = HAL_InitializeREVPDH(1, allocationLocation, status);
return static_cast<HAL_PowerDistributionHandle>(pdhHandle);
}
@@ -70,7 +70,7 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
moduleNumber = 1;
}
return static_cast<HAL_PowerDistributionHandle>(
HAL_REV_InitializePDH(moduleNumber, allocationLocation, status));
HAL_InitializeREVPDH(moduleNumber, allocationLocation, status));
}
}
@@ -80,7 +80,7 @@ void HAL_CleanPowerDistribution(HAL_PowerDistributionHandle handle) {
if (IsCtre(handle)) {
HAL_CleanPDP(handle);
} else {
HAL_REV_FreePDH(handle);
HAL_FreeREVPDH(handle);
}
}
@@ -89,7 +89,7 @@ int32_t HAL_GetPowerDistributionModuleNumber(HAL_PowerDistributionHandle handle,
if (IsCtre(handle)) {
return HAL_GetPDPModuleNumber(handle, status);
} else {
return HAL_REV_GetPDHModuleNumber(handle, status);
return HAL_GetREVPDHModuleNumber(handle, status);
}
}
@@ -98,7 +98,7 @@ HAL_Bool HAL_CheckPowerDistributionChannel(HAL_PowerDistributionHandle handle,
if (IsCtre(handle)) {
return HAL_CheckPDPChannel(channel);
} else {
return HAL_REV_CheckPDHChannelNumber(channel);
return HAL_CheckREVPDHChannelNumber(channel);
}
}
@@ -107,7 +107,7 @@ HAL_Bool HAL_CheckPowerDistributionModule(int32_t module,
if (type == HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE) {
return HAL_CheckPDPModule(module);
} else {
return HAL_REV_CheckPDHModuleNumber(module);
return HAL_CheckREVPDHModuleNumber(module);
}
}
@@ -142,7 +142,7 @@ double HAL_GetPowerDistributionVoltage(HAL_PowerDistributionHandle handle,
if (IsCtre(handle)) {
return HAL_GetPDPVoltage(handle, status);
} else {
return HAL_REV_GetPDHSupplyVoltage(handle, status);
return HAL_GetREVPDHVoltage(handle, status);
}
}
@@ -151,7 +151,7 @@ double HAL_GetPowerDistributionChannelCurrent(
if (IsCtre(handle)) {
return HAL_GetPDPChannelCurrent(handle, channel, status);
} else {
return HAL_REV_GetPDHChannelCurrent(handle, channel, status);
return HAL_GetREVPDHChannelCurrent(handle, channel, status);
}
}
@@ -171,7 +171,7 @@ void HAL_GetPowerDistributionAllChannelCurrents(
SetLastError(status, "Output array not large enough");
return;
}
return HAL_REV_GetPDHAllChannelCurrents(handle, currents, status);
return HAL_GetREVPDHAllChannelCurrents(handle, currents, status);
}
}
@@ -180,7 +180,7 @@ double HAL_GetPowerDistributionTotalCurrent(HAL_PowerDistributionHandle handle,
if (IsCtre(handle)) {
return HAL_GetPDPTotalCurrent(handle, status);
} else {
return HAL_REV_GetPDHTotalCurrent(handle, status);
return HAL_GetREVPDHTotalCurrent(handle, status);
}
}
@@ -218,7 +218,7 @@ void HAL_ClearPowerDistributionStickyFaults(HAL_PowerDistributionHandle handle,
if (IsCtre(handle)) {
HAL_ClearPDPStickyFaults(handle, status);
} else {
HAL_REV_ClearPDHFaults(handle, status);
HAL_ClearREVPDHStickyFaults(handle, status);
}
}
@@ -228,7 +228,7 @@ void HAL_SetPowerDistributionSwitchableChannel(
// No-op on CTRE
return;
} else {
HAL_REV_SetPDHSwitchableChannel(handle, enabled, status);
HAL_SetREVPDHSwitchableChannel(handle, enabled, status);
}
}
@@ -238,7 +238,7 @@ HAL_Bool HAL_GetPowerDistributionSwitchableChannel(
// No-op on CTRE
return false;
} else {
return HAL_REV_GetPDHSwitchableChannelState(handle, status);
return HAL_GetREVPDHSwitchableChannelState(handle, status);
}
}

View File

@@ -43,32 +43,26 @@ static constexpr uint32_t APIFromExtId(uint32_t extId) {
return (extId >> 6) & 0x3FF;
}
static constexpr uint32_t PDH_SWITCH_CHANNEL_SET_FRAME_API =
APIFromExtId(PDH_SWITCH_CHANNEL_SET_FRAME_ID);
static constexpr uint32_t PDH_SET_SWITCH_CHANNEL_FRAME_API =
APIFromExtId(PDH_SET_SWITCH_CHANNEL_FRAME_ID);
static constexpr uint32_t PDH_STATUS0_FRAME_API =
APIFromExtId(PDH_STATUS0_FRAME_ID);
static constexpr uint32_t PDH_STATUS1_FRAME_API =
APIFromExtId(PDH_STATUS1_FRAME_ID);
static constexpr uint32_t PDH_STATUS2_FRAME_API =
APIFromExtId(PDH_STATUS2_FRAME_ID);
static constexpr uint32_t PDH_STATUS3_FRAME_API =
APIFromExtId(PDH_STATUS3_FRAME_ID);
static constexpr uint32_t PDH_STATUS4_FRAME_API =
APIFromExtId(PDH_STATUS4_FRAME_ID);
static constexpr uint32_t PDH_STATUS_0_FRAME_API =
APIFromExtId(PDH_STATUS_0_FRAME_ID);
static constexpr uint32_t PDH_STATUS_1_FRAME_API =
APIFromExtId(PDH_STATUS_1_FRAME_ID);
static constexpr uint32_t PDH_STATUS_2_FRAME_API =
APIFromExtId(PDH_STATUS_2_FRAME_ID);
static constexpr uint32_t PDH_STATUS_3_FRAME_API =
APIFromExtId(PDH_STATUS_3_FRAME_ID);
static constexpr uint32_t PDH_STATUS_4_FRAME_API =
APIFromExtId(PDH_STATUS_4_FRAME_ID);
static constexpr uint32_t PDH_CLEAR_FAULTS_FRAME_API =
APIFromExtId(PDH_CLEAR_FAULTS_FRAME_ID);
static constexpr uint32_t PDH_IDENTIFY_FRAME_API =
APIFromExtId(PDH_IDENTIFY_FRAME_ID);
static constexpr uint32_t PDH_VERSION_FRAME_API =
APIFromExtId(PDH_VERSION_FRAME_ID);
static constexpr uint32_t PDH_CONFIGURE_HR_CHANNEL_FRAME_API =
APIFromExtId(PDH_CONFIGURE_HR_CHANNEL_FRAME_ID);
static constexpr int32_t kPDHFrameStatus0Timeout = 20;
static constexpr int32_t kPDHFrameStatus1Timeout = 20;
static constexpr int32_t kPDHFrameStatus2Timeout = 20;
@@ -89,97 +83,97 @@ void InitializeREVPDH() {
extern "C" {
static PDH_status0_t HAL_REV_ReadPDHStatus0(HAL_CANHandle hcan,
static PDH_status_0_t HAL_ReadREVPDHStatus0(HAL_CANHandle hcan,
int32_t* status) {
uint8_t packedData[8] = {0};
int32_t length = 0;
uint64_t timestamp = 0;
PDH_status0_t result = {};
PDH_status_0_t result = {};
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS0_FRAME_API, packedData, &length,
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS_0_FRAME_API, packedData, &length,
&timestamp, kPDHFrameStatus0Timeout * 2, status);
if (*status != 0) {
return result;
}
PDH_status0_unpack(&result, packedData, PDH_STATUS0_LENGTH);
PDH_status_0_unpack(&result, packedData, PDH_STATUS_0_LENGTH);
return result;
}
static PDH_status1_t HAL_REV_ReadPDHStatus1(HAL_CANHandle hcan,
static PDH_status_1_t HAL_ReadREVPDHStatus1(HAL_CANHandle hcan,
int32_t* status) {
uint8_t packedData[8] = {0};
int32_t length = 0;
uint64_t timestamp = 0;
PDH_status1_t result = {};
PDH_status_1_t result = {};
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS1_FRAME_API, packedData, &length,
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS_1_FRAME_API, packedData, &length,
&timestamp, kPDHFrameStatus1Timeout * 2, status);
if (*status != 0) {
return result;
}
PDH_status1_unpack(&result, packedData, PDH_STATUS1_LENGTH);
PDH_status_1_unpack(&result, packedData, PDH_STATUS_1_LENGTH);
return result;
}
static PDH_status2_t HAL_REV_ReadPDHStatus2(HAL_CANHandle hcan,
static PDH_status_2_t HAL_ReadREVPDHStatus2(HAL_CANHandle hcan,
int32_t* status) {
uint8_t packedData[8] = {0};
int32_t length = 0;
uint64_t timestamp = 0;
PDH_status2_t result = {};
PDH_status_2_t result = {};
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS2_FRAME_API, packedData, &length,
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS_2_FRAME_API, packedData, &length,
&timestamp, kPDHFrameStatus2Timeout * 2, status);
if (*status != 0) {
return result;
}
PDH_status2_unpack(&result, packedData, PDH_STATUS2_LENGTH);
PDH_status_2_unpack(&result, packedData, PDH_STATUS_2_LENGTH);
return result;
}
static PDH_status3_t HAL_REV_ReadPDHStatus3(HAL_CANHandle hcan,
static PDH_status_3_t HAL_ReadREVPDHStatus3(HAL_CANHandle hcan,
int32_t* status) {
uint8_t packedData[8] = {0};
int32_t length = 0;
uint64_t timestamp = 0;
PDH_status3_t result = {};
PDH_status_3_t result = {};
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS3_FRAME_API, packedData, &length,
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS_3_FRAME_API, packedData, &length,
&timestamp, kPDHFrameStatus3Timeout * 2, status);
if (*status != 0) {
return result;
}
PDH_status3_unpack(&result, packedData, PDH_STATUS3_LENGTH);
PDH_status_3_unpack(&result, packedData, PDH_STATUS_3_LENGTH);
return result;
}
static PDH_status4_t HAL_REV_ReadPDHStatus4(HAL_CANHandle hcan,
static PDH_status_4_t HAL_ReadREVPDHStatus4(HAL_CANHandle hcan,
int32_t* status) {
uint8_t packedData[8] = {0};
int32_t length = 0;
uint64_t timestamp = 0;
PDH_status4_t result = {};
PDH_status_4_t result = {};
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS4_FRAME_API, packedData, &length,
HAL_ReadCANPacketTimeout(hcan, PDH_STATUS_4_FRAME_API, packedData, &length,
&timestamp, kPDHFrameStatus4Timeout * 2, status);
if (*status != 0) {
return result;
}
PDH_status4_unpack(&result, packedData, PDH_STATUS4_LENGTH);
PDH_status_4_unpack(&result, packedData, PDH_STATUS_4_LENGTH);
return result;
}
@@ -187,23 +181,23 @@ static PDH_status4_t HAL_REV_ReadPDHStatus4(HAL_CANHandle hcan,
/**
* Helper function for the individual getter functions for status 4
*/
PDH_status4_t HAL_REV_GetPDHStatus4(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status4_t statusFrame = {};
PDH_status_4_t HAL_GetREVPDHStatus4(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status_4_t statusFrame = {};
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
*status = HAL_HANDLE_ERROR;
return statusFrame;
}
statusFrame = HAL_REV_ReadPDHStatus4(hpdh->hcan, status);
statusFrame = HAL_ReadREVPDHStatus4(hpdh->hcan, status);
return statusFrame;
}
HAL_REVPDHHandle HAL_REV_InitializePDH(int32_t module,
const char* allocationLocation,
int32_t* status) {
HAL_REVPDHHandle HAL_InitializeREVPDH(int32_t module,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();
if (!HAL_REV_CheckPDHModuleNumber(module)) {
if (!HAL_CheckREVPDHModuleNumber(module)) {
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
@@ -236,7 +230,7 @@ HAL_REVPDHHandle HAL_REV_InitializePDH(int32_t module,
return handle;
}
void HAL_REV_FreePDH(HAL_REVPDHHandle handle) {
void HAL_FreeREVPDH(HAL_REVPDHHandle handle) {
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
return;
@@ -247,27 +241,27 @@ void HAL_REV_FreePDH(HAL_REVPDHHandle handle) {
REVPDHHandles->Free(handle);
}
int32_t HAL_REV_GetPDHModuleNumber(HAL_REVPDHHandle handle, int32_t* status) {
int32_t HAL_GetREVPDHModuleNumber(HAL_REVPDHHandle handle, int32_t* status) {
return hal::getHandleIndex(handle);
}
HAL_Bool HAL_REV_CheckPDHModuleNumber(int32_t module) {
HAL_Bool HAL_CheckREVPDHModuleNumber(int32_t module) {
return ((module >= 1) && (module < kNumREVPDHModules)) ? 1 : 0;
}
HAL_Bool HAL_REV_CheckPDHChannelNumber(int32_t channel) {
HAL_Bool HAL_CheckREVPDHChannelNumber(int32_t channel) {
return ((channel >= 0) && (channel < kNumREVPDHChannels)) ? 1 : 0;
}
double HAL_REV_GetPDHChannelCurrent(HAL_REVPDHHandle handle, int32_t channel,
int32_t* status) {
double HAL_GetREVPDHChannelCurrent(HAL_REVPDHHandle handle, int32_t channel,
int32_t* status) {
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
if (!HAL_REV_CheckPDHChannelNumber(channel)) {
if (!HAL_CheckREVPDHChannelNumber(channel)) {
*status = RESOURCE_OUT_OF_RANGE;
return 0;
}
@@ -275,174 +269,101 @@ double HAL_REV_GetPDHChannelCurrent(HAL_REVPDHHandle handle, int32_t channel,
// Determine what periodic status the channel is in
if (channel < 6) {
// Periodic status 0
PDH_status0_t statusFrame = HAL_REV_ReadPDHStatus0(hpdh->hcan, status);
PDH_status_0_t statusFrame = HAL_ReadREVPDHStatus0(hpdh->hcan, status);
switch (channel) {
case 0:
return PDH_status0_channel_0_current_decode(
return PDH_status_0_channel_0_current_decode(
statusFrame.channel_0_current);
case 1:
return PDH_status0_channel_1_current_decode(
return PDH_status_0_channel_1_current_decode(
statusFrame.channel_1_current);
case 2:
return PDH_status0_channel_2_current_decode(
return PDH_status_0_channel_2_current_decode(
statusFrame.channel_2_current);
case 3:
return PDH_status0_channel_3_current_decode(
return PDH_status_0_channel_3_current_decode(
statusFrame.channel_3_current);
case 4:
return PDH_status0_channel_4_current_decode(
return PDH_status_0_channel_4_current_decode(
statusFrame.channel_4_current);
case 5:
return PDH_status0_channel_5_current_decode(
return PDH_status_0_channel_5_current_decode(
statusFrame.channel_5_current);
}
} else if (channel < 12) {
// Periodic status 1
PDH_status1_t statusFrame = HAL_REV_ReadPDHStatus1(hpdh->hcan, status);
PDH_status_1_t statusFrame = HAL_ReadREVPDHStatus1(hpdh->hcan, status);
switch (channel) {
case 6:
return PDH_status1_channel_6_current_decode(
return PDH_status_1_channel_6_current_decode(
statusFrame.channel_6_current);
case 7:
return PDH_status1_channel_7_current_decode(
return PDH_status_1_channel_7_current_decode(
statusFrame.channel_7_current);
case 8:
return PDH_status1_channel_8_current_decode(
return PDH_status_1_channel_8_current_decode(
statusFrame.channel_8_current);
case 9:
return PDH_status1_channel_9_current_decode(
return PDH_status_1_channel_9_current_decode(
statusFrame.channel_9_current);
case 10:
return PDH_status1_channel_10_current_decode(
return PDH_status_1_channel_10_current_decode(
statusFrame.channel_10_current);
case 11:
return PDH_status1_channel_11_current_decode(
return PDH_status_1_channel_11_current_decode(
statusFrame.channel_11_current);
}
} else if (channel < 18) {
// Periodic status 2
PDH_status2_t statusFrame = HAL_REV_ReadPDHStatus2(hpdh->hcan, status);
PDH_status_2_t statusFrame = HAL_ReadREVPDHStatus2(hpdh->hcan, status);
switch (channel) {
case 12:
return PDH_status2_channel_12_current_decode(
return PDH_status_2_channel_12_current_decode(
statusFrame.channel_12_current);
case 13:
return PDH_status2_channel_13_current_decode(
return PDH_status_2_channel_13_current_decode(
statusFrame.channel_13_current);
case 14:
return PDH_status2_channel_14_current_decode(
return PDH_status_2_channel_14_current_decode(
statusFrame.channel_14_current);
case 15:
return PDH_status2_channel_15_current_decode(
return PDH_status_2_channel_15_current_decode(
statusFrame.channel_15_current);
case 16:
return PDH_status2_channel_16_current_decode(
return PDH_status_2_channel_16_current_decode(
statusFrame.channel_16_current);
case 17:
return PDH_status2_channel_17_current_decode(
return PDH_status_2_channel_17_current_decode(
statusFrame.channel_17_current);
}
} else if (channel < 24) {
// Periodic status 3
PDH_status3_t statusFrame = HAL_REV_ReadPDHStatus3(hpdh->hcan, status);
PDH_status_3_t statusFrame = HAL_ReadREVPDHStatus3(hpdh->hcan, status);
switch (channel) {
case 18:
return PDH_status3_channel_18_current_decode(
return PDH_status_3_channel_18_current_decode(
statusFrame.channel_18_current);
case 19:
return PDH_status3_channel_19_current_decode(
return PDH_status_3_channel_19_current_decode(
statusFrame.channel_19_current);
case 20:
return PDH_status3_channel_20_current_decode(
return PDH_status_3_channel_20_current_decode(
statusFrame.channel_20_current);
case 21:
return PDH_status3_channel_21_current_decode(
return PDH_status_3_channel_21_current_decode(
statusFrame.channel_21_current);
case 22:
return PDH_status3_channel_22_current_decode(
return PDH_status_3_channel_22_current_decode(
statusFrame.channel_22_current);
case 23:
return PDH_status3_channel_23_current_decode(
return PDH_status_3_channel_23_current_decode(
statusFrame.channel_23_current);
}
}
return 0;
}
void HAL_REV_GetPDHAllChannelCurrents(HAL_REVPDHHandle handle, double* currents,
int32_t* status) {
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
PDH_status0_t statusFrame0 = HAL_REV_ReadPDHStatus0(hpdh->hcan, status);
PDH_status1_t statusFrame1 = HAL_REV_ReadPDHStatus1(hpdh->hcan, status);
PDH_status2_t statusFrame2 = HAL_REV_ReadPDHStatus2(hpdh->hcan, status);
PDH_status3_t statusFrame3 = HAL_REV_ReadPDHStatus3(hpdh->hcan, status);
currents[0] =
PDH_status0_channel_0_current_decode(statusFrame0.channel_0_current);
currents[1] =
PDH_status0_channel_1_current_decode(statusFrame0.channel_1_current);
currents[2] =
PDH_status0_channel_2_current_decode(statusFrame0.channel_2_current);
currents[3] =
PDH_status0_channel_3_current_decode(statusFrame0.channel_3_current);
currents[4] =
PDH_status0_channel_4_current_decode(statusFrame0.channel_4_current);
currents[5] =
PDH_status0_channel_5_current_decode(statusFrame0.channel_5_current);
currents[6] =
PDH_status1_channel_6_current_decode(statusFrame1.channel_6_current);
currents[7] =
PDH_status1_channel_7_current_decode(statusFrame1.channel_7_current);
currents[8] =
PDH_status1_channel_8_current_decode(statusFrame1.channel_8_current);
currents[9] =
PDH_status1_channel_9_current_decode(statusFrame1.channel_9_current);
currents[10] =
PDH_status1_channel_10_current_decode(statusFrame1.channel_10_current);
currents[11] =
PDH_status1_channel_11_current_decode(statusFrame1.channel_11_current);
currents[12] =
PDH_status2_channel_12_current_decode(statusFrame2.channel_12_current);
currents[13] =
PDH_status2_channel_13_current_decode(statusFrame2.channel_13_current);
currents[14] =
PDH_status2_channel_14_current_decode(statusFrame2.channel_14_current);
currents[15] =
PDH_status2_channel_15_current_decode(statusFrame2.channel_15_current);
currents[16] =
PDH_status2_channel_16_current_decode(statusFrame2.channel_16_current);
currents[17] =
PDH_status2_channel_17_current_decode(statusFrame2.channel_17_current);
currents[18] =
PDH_status3_channel_18_current_decode(statusFrame3.channel_18_current);
currents[19] =
PDH_status3_channel_19_current_decode(statusFrame3.channel_19_current);
currents[20] =
PDH_status3_channel_20_current_decode(statusFrame3.channel_20_current);
currents[21] =
PDH_status3_channel_21_current_decode(statusFrame3.channel_21_current);
currents[22] =
PDH_status3_channel_22_current_decode(statusFrame3.channel_22_current);
currents[23] =
PDH_status3_channel_23_current_decode(statusFrame3.channel_23_current);
}
uint16_t HAL_REV_GetPDHTotalCurrent(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0;
}
return PDH_status4_total_current_decode(statusFrame.total_current);
}
void HAL_REV_SetPDHSwitchableChannel(HAL_REVPDHHandle handle, HAL_Bool enabled,
void HAL_GetREVPDHAllChannelCurrents(HAL_REVPDHHandle handle, double* currents,
int32_t* status) {
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
@@ -450,290 +371,114 @@ void HAL_REV_SetPDHSwitchableChannel(HAL_REVPDHHandle handle, HAL_Bool enabled,
return;
}
uint8_t packedData[8] = {0};
PDH_switch_channel_set_t frame;
frame.output_set_value = enabled;
frame.use_system_enable = false;
PDH_switch_channel_set_pack(packedData, &frame, 1);
PDH_status_0_t statusFrame0 = HAL_ReadREVPDHStatus0(hpdh->hcan, status);
PDH_status_1_t statusFrame1 = HAL_ReadREVPDHStatus1(hpdh->hcan, status);
PDH_status_2_t statusFrame2 = HAL_ReadREVPDHStatus2(hpdh->hcan, status);
PDH_status_3_t statusFrame3 = HAL_ReadREVPDHStatus3(hpdh->hcan, status);
HAL_WriteCANPacket(hpdh->hcan, packedData, PDH_SWITCH_CHANNEL_SET_LENGTH,
PDH_SWITCH_CHANNEL_SET_FRAME_API, status);
currents[0] =
PDH_status_0_channel_0_current_decode(statusFrame0.channel_0_current);
currents[1] =
PDH_status_0_channel_1_current_decode(statusFrame0.channel_1_current);
currents[2] =
PDH_status_0_channel_2_current_decode(statusFrame0.channel_2_current);
currents[3] =
PDH_status_0_channel_3_current_decode(statusFrame0.channel_3_current);
currents[4] =
PDH_status_0_channel_4_current_decode(statusFrame0.channel_4_current);
currents[5] =
PDH_status_0_channel_5_current_decode(statusFrame0.channel_5_current);
currents[6] =
PDH_status_1_channel_6_current_decode(statusFrame1.channel_6_current);
currents[7] =
PDH_status_1_channel_7_current_decode(statusFrame1.channel_7_current);
currents[8] =
PDH_status_1_channel_8_current_decode(statusFrame1.channel_8_current);
currents[9] =
PDH_status_1_channel_9_current_decode(statusFrame1.channel_9_current);
currents[10] =
PDH_status_1_channel_10_current_decode(statusFrame1.channel_10_current);
currents[11] =
PDH_status_1_channel_11_current_decode(statusFrame1.channel_11_current);
currents[12] =
PDH_status_2_channel_12_current_decode(statusFrame2.channel_12_current);
currents[13] =
PDH_status_2_channel_13_current_decode(statusFrame2.channel_13_current);
currents[14] =
PDH_status_2_channel_14_current_decode(statusFrame2.channel_14_current);
currents[15] =
PDH_status_2_channel_15_current_decode(statusFrame2.channel_15_current);
currents[16] =
PDH_status_2_channel_16_current_decode(statusFrame2.channel_16_current);
currents[17] =
PDH_status_2_channel_17_current_decode(statusFrame2.channel_17_current);
currents[18] =
PDH_status_3_channel_18_current_decode(statusFrame3.channel_18_current);
currents[19] =
PDH_status_3_channel_19_current_decode(statusFrame3.channel_19_current);
currents[20] =
PDH_status_3_channel_20_current_decode(statusFrame3.channel_20_current);
currents[21] =
PDH_status_3_channel_21_current_decode(statusFrame3.channel_21_current);
currents[22] =
PDH_status_3_channel_22_current_decode(statusFrame3.channel_22_current);
currents[23] =
PDH_status_3_channel_23_current_decode(statusFrame3.channel_23_current);
}
HAL_Bool HAL_REV_GetPDHSwitchableChannelState(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
uint16_t HAL_GetREVPDHTotalCurrent(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status_4_t statusFrame = HAL_GetREVPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
return 0;
}
return PDH_status4_sw_state_decode(statusFrame.sw_state);
return PDH_status_4_total_current_decode(statusFrame.total_current);
}
HAL_Bool HAL_REV_CheckPDHChannelBrownout(HAL_REVPDHHandle handle,
int32_t channel, int32_t* status) {
void HAL_SetREVPDHSwitchableChannel(HAL_REVPDHHandle handle, HAL_Bool enabled,
int32_t* status) {
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
return;
}
if (!HAL_REV_CheckPDHChannelNumber(channel)) {
*status = RESOURCE_OUT_OF_RANGE;
return 0;
}
uint8_t packedData[8] = {0};
PDH_set_switch_channel_t frame;
frame.output_set_value = enabled;
PDH_set_switch_channel_pack(packedData, &frame,
PDH_SET_SWITCH_CHANNEL_LENGTH);
// Determine what periodic status the channel is in
if (channel < 4) {
// Periodic status 0
PDH_status0_t statusFrame = HAL_REV_ReadPDHStatus0(hpdh->hcan, status);
switch (channel) {
case 0:
return PDH_status0_channel_0_brownout_decode(
statusFrame.channel_0_brownout);
case 1:
return PDH_status0_channel_1_brownout_decode(
statusFrame.channel_1_brownout);
case 2:
return PDH_status0_channel_2_brownout_decode(
statusFrame.channel_2_brownout);
case 3:
return PDH_status0_channel_3_brownout_decode(
statusFrame.channel_3_brownout);
}
} else if (channel < 8) {
// Periodic status 1
PDH_status1_t statusFrame = HAL_REV_ReadPDHStatus1(hpdh->hcan, status);
switch (channel) {
case 4:
return PDH_status1_channel_4_brownout_decode(
statusFrame.channel_4_brownout);
case 5:
return PDH_status1_channel_5_brownout_decode(
statusFrame.channel_5_brownout);
case 6:
return PDH_status1_channel_6_brownout_decode(
statusFrame.channel_6_brownout);
case 7:
return PDH_status1_channel_7_brownout_decode(
statusFrame.channel_7_brownout);
}
} else if (channel < 12) {
// Periodic status 2
PDH_status2_t statusFrame = HAL_REV_ReadPDHStatus2(hpdh->hcan, status);
switch (channel) {
case 8:
return PDH_status2_channel_8_brownout_decode(
statusFrame.channel_8_brownout);
case 9:
return PDH_status2_channel_9_brownout_decode(
statusFrame.channel_9_brownout);
case 10:
return PDH_status2_channel_10_brownout_decode(
statusFrame.channel_10_brownout);
case 11:
return PDH_status2_channel_11_brownout_decode(
statusFrame.channel_11_brownout);
}
} else if (channel < 24) {
// Periodic status 3
PDH_status3_t statusFrame = HAL_REV_ReadPDHStatus3(hpdh->hcan, status);
switch (channel) {
case 12:
return PDH_status3_channel_12_brownout_decode(
statusFrame.channel_12_brownout);
case 13:
return PDH_status3_channel_13_brownout_decode(
statusFrame.channel_13_brownout);
case 14:
return PDH_status3_channel_14_brownout_decode(
statusFrame.channel_14_brownout);
case 15:
return PDH_status3_channel_15_brownout_decode(
statusFrame.channel_15_brownout);
case 16:
return PDH_status3_channel_16_brownout_decode(
statusFrame.channel_16_brownout);
case 17:
return PDH_status3_channel_17_brownout_decode(
statusFrame.channel_17_brownout);
case 18:
return PDH_status3_channel_18_brownout_decode(
statusFrame.channel_18_brownout);
case 19:
return PDH_status3_channel_19_brownout_decode(
statusFrame.channel_19_brownout);
case 20:
return PDH_status3_channel_20_brownout_decode(
statusFrame.channel_20_brownout);
case 21:
return PDH_status3_channel_21_brownout_decode(
statusFrame.channel_21_brownout);
case 22:
return PDH_status3_channel_22_brownout_decode(
statusFrame.channel_22_brownout);
case 23:
return PDH_status3_channel_23_brownout_decode(
statusFrame.channel_23_brownout);
}
}
return 0;
HAL_WriteCANPacket(hpdh->hcan, packedData, PDH_SET_SWITCH_CHANNEL_LENGTH,
PDH_SET_SWITCH_CHANNEL_FRAME_API, status);
}
double HAL_REV_GetPDHSupplyVoltage(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
HAL_Bool HAL_GetREVPDHSwitchableChannelState(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status_4_t statusFrame = HAL_GetREVPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_v_bus_decode(statusFrame.v_bus);
return PDH_status_4_switch_channel_state_decode(
statusFrame.switch_channel_state);
}
HAL_Bool HAL_REV_IsPDHEnabled(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return false;
}
return PDH_status4_system_enable_decode(statusFrame.system_enable);
}
HAL_Bool HAL_REV_CheckPDHBrownout(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return false;
}
return PDH_status4_brownout_decode(statusFrame.brownout);
}
HAL_Bool HAL_REV_CheckPDHCANWarning(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
double HAL_GetREVPDHVoltage(HAL_REVPDHHandle handle, int32_t* status) {
PDH_status_4_t statusFrame = HAL_GetREVPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_can_warning_decode(statusFrame.can_warning);
return PDH_status_4_v_bus_decode(statusFrame.v_bus);
}
HAL_Bool HAL_REV_CheckPDHHardwareFault(HAL_REVPDHHandle handle,
HAL_REVPDHVersion HAL_GetREVPDHVersion(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_hardware_fault_decode(statusFrame.hardware_fault);
}
HAL_Bool HAL_REV_CheckPDHStickyBrownout(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_sticky_brownout_decode(statusFrame.sticky_brownout);
}
HAL_Bool HAL_REV_CheckPDHStickyCANWarning(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_sticky_can_warning_decode(statusFrame.sticky_can_warning);
}
HAL_Bool HAL_REV_CheckPDHStickyCANBusOff(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_sticky_can_bus_off_decode(statusFrame.sticky_can_bus_off);
}
HAL_Bool HAL_REV_CheckPDHStickyHardwareFault(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_sticky_hardware_fault_decode(
statusFrame.sticky_hardware_fault);
}
HAL_Bool HAL_REV_CheckPDHStickyFirmwareFault(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_sticky_firmware_fault_decode(
statusFrame.sticky_firmware_fault);
}
HAL_Bool HAL_REV_CheckPDHStickyChannelBrownout(HAL_REVPDHHandle handle,
int32_t channel,
int32_t* status) {
if (channel < 20 || channel > 23) {
*status = RESOURCE_OUT_OF_RANGE;
return 0.0;
}
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
switch (channel) {
case 20:
return PDH_status4_sticky_ch20_brownout_decode(
statusFrame.sticky_ch20_brownout);
case 21:
return PDH_status4_sticky_ch21_brownout_decode(
statusFrame.sticky_ch21_brownout);
case 22:
return PDH_status4_sticky_ch22_brownout_decode(
statusFrame.sticky_ch22_brownout);
case 23:
return PDH_status4_sticky_ch23_brownout_decode(
statusFrame.sticky_ch23_brownout);
}
return 0;
}
HAL_Bool HAL_REV_CheckPDHStickyHasReset(HAL_REVPDHHandle handle,
int32_t* status) {
PDH_status4_t statusFrame = HAL_REV_GetPDHStatus4(handle, status);
if (*status != 0) {
return 0.0;
}
return PDH_status4_sticky_has_reset_decode(statusFrame.sticky_has_reset);
}
REV_PDH_Version HAL_REV_GetPDHVersion(HAL_REVPDHHandle handle,
int32_t* status) {
REV_PDH_Version version;
HAL_REVPDHVersion version;
std::memset(&version, 0, sizeof(version));
uint8_t packedData[8] = {0};
int32_t length = 0;
@@ -765,13 +510,102 @@ REV_PDH_Version HAL_REV_GetPDHVersion(HAL_REVPDHHandle handle,
version.firmwareMajor = result.firmware_year;
version.firmwareMinor = result.firmware_minor;
version.firmwareFix = result.firmware_fix;
version.hardwareRev = result.hardware_code;
version.hardwareMinor = result.hardware_minor;
version.hardwareMajor = result.hardware_major;
version.uniqueId = result.unique_id;
return version;
}
void HAL_REV_ClearPDHFaults(HAL_REVPDHHandle handle, int32_t* status) {
HAL_REVPDHFaults HAL_GetREVPDHFaults(HAL_REVPDHHandle handle, int32_t* status) {
HAL_REVPDHFaults faults = {};
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
*status = HAL_HANDLE_ERROR;
return faults;
}
PDH_status_0_t status0 = HAL_ReadREVPDHStatus0(hpdh->hcan, status);
PDH_status_1_t status1 = HAL_ReadREVPDHStatus1(hpdh->hcan, status);
PDH_status_2_t status2 = HAL_ReadREVPDHStatus2(hpdh->hcan, status);
PDH_status_3_t status3 = HAL_ReadREVPDHStatus3(hpdh->hcan, status);
PDH_status_4_t status4 = HAL_ReadREVPDHStatus4(hpdh->hcan, status);
faults.channel0BreakerFault = status0.channel_0_breaker_fault;
faults.channel1BreakerFault = status0.channel_1_breaker_fault;
faults.channel2BreakerFault = status0.channel_2_breaker_fault;
faults.channel3BreakerFault = status0.channel_3_breaker_fault;
faults.channel4BreakerFault = status1.channel_4_breaker_fault;
faults.channel5BreakerFault = status1.channel_5_breaker_fault;
faults.channel6BreakerFault = status1.channel_6_breaker_fault;
faults.channel7BreakerFault = status1.channel_7_breaker_fault;
faults.channel8BreakerFault = status2.channel_8_breaker_fault;
faults.channel9BreakerFault = status2.channel_9_breaker_fault;
faults.channel10BreakerFault = status2.channel_10_breaker_fault;
faults.channel11BreakerFault = status2.channel_11_breaker_fault;
faults.channel12BreakerFault = status3.channel_12_breaker_fault;
faults.channel13BreakerFault = status3.channel_13_breaker_fault;
faults.channel14BreakerFault = status3.channel_14_breaker_fault;
faults.channel15BreakerFault = status3.channel_15_breaker_fault;
faults.channel16BreakerFault = status3.channel_16_breaker_fault;
faults.channel17BreakerFault = status3.channel_17_breaker_fault;
faults.channel18BreakerFault = status3.channel_18_breaker_fault;
faults.channel19BreakerFault = status3.channel_19_breaker_fault;
faults.channel20BreakerFault = status3.channel_20_breaker_fault;
faults.channel21BreakerFault = status3.channel_21_breaker_fault;
faults.channel22BreakerFault = status3.channel_22_breaker_fault;
faults.channel23BreakerFault = status3.channel_23_breaker_fault;
faults.brownout = status4.brownout_fault;
faults.canWarning = status4.can_warning_fault;
faults.hardwareFault = status4.hardware_fault;
return faults;
}
HAL_REVPDHStickyFaults HAL_GetREVPDHStickyFaults(HAL_REVPDHHandle handle,
int32_t* status) {
HAL_REVPDHStickyFaults stickyFaults = {};
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
*status = HAL_HANDLE_ERROR;
return stickyFaults;
}
PDH_status_4_t status4 = HAL_ReadREVPDHStatus4(hpdh->hcan, status);
stickyFaults.channel0BreakerFault = status4.sticky_ch0_breaker_fault;
stickyFaults.channel1BreakerFault = status4.sticky_ch1_breaker_fault;
stickyFaults.channel2BreakerFault = status4.sticky_ch2_breaker_fault;
stickyFaults.channel3BreakerFault = status4.sticky_ch3_breaker_fault;
stickyFaults.channel4BreakerFault = status4.sticky_ch4_breaker_fault;
stickyFaults.channel5BreakerFault = status4.sticky_ch5_breaker_fault;
stickyFaults.channel6BreakerFault = status4.sticky_ch6_breaker_fault;
stickyFaults.channel7BreakerFault = status4.sticky_ch7_breaker_fault;
stickyFaults.channel8BreakerFault = status4.sticky_ch8_breaker_fault;
stickyFaults.channel9BreakerFault = status4.sticky_ch9_breaker_fault;
stickyFaults.channel10BreakerFault = status4.sticky_ch10_breaker_fault;
stickyFaults.channel11BreakerFault = status4.sticky_ch11_breaker_fault;
stickyFaults.channel12BreakerFault = status4.sticky_ch12_breaker_fault;
stickyFaults.channel13BreakerFault = status4.sticky_ch13_breaker_fault;
stickyFaults.channel14BreakerFault = status4.sticky_ch14_breaker_fault;
stickyFaults.channel15BreakerFault = status4.sticky_ch15_breaker_fault;
stickyFaults.channel16BreakerFault = status4.sticky_ch16_breaker_fault;
stickyFaults.channel17BreakerFault = status4.sticky_ch17_breaker_fault;
stickyFaults.channel18BreakerFault = status4.sticky_ch18_breaker_fault;
stickyFaults.channel19BreakerFault = status4.sticky_ch19_breaker_fault;
stickyFaults.channel20BreakerFault = status4.sticky_ch20_breaker_fault;
stickyFaults.channel21BreakerFault = status4.sticky_ch21_breaker_fault;
stickyFaults.channel22BreakerFault = status4.sticky_ch22_breaker_fault;
stickyFaults.channel23BreakerFault = status4.sticky_ch23_breaker_fault;
stickyFaults.brownout = status4.sticky_brownout_fault;
stickyFaults.canWarning = status4.sticky_can_warning_fault;
stickyFaults.canBusOff = status4.sticky_can_bus_off_fault;
stickyFaults.hasReset = status4.sticky_has_reset_fault;
return stickyFaults;
}
void HAL_ClearREVPDHStickyFaults(HAL_REVPDHHandle handle, int32_t* status) {
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -783,16 +617,4 @@ void HAL_REV_ClearPDHFaults(HAL_REVPDHHandle handle, int32_t* status) {
PDH_CLEAR_FAULTS_FRAME_API, status);
}
void HAL_REV_IdentifyPDH(HAL_REVPDHHandle handle, int32_t* status) {
auto hpdh = REVPDHHandles->Get(handle);
if (hpdh == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
uint8_t packedData[8] = {0};
HAL_WriteCANPacket(hpdh->hcan, packedData, PDH_IDENTIFY_LENGTH,
PDH_IDENTIFY_FRAME_API, status);
}
} // extern "C"

View File

@@ -14,14 +14,85 @@
* @{
*/
struct REV_PDH_Version {
/**
* Storage for REV PDH Version
*/
struct HAL_REVPDHVersion {
uint32_t firmwareMajor;
uint32_t firmwareMinor;
uint32_t firmwareFix;
uint32_t hardwareRev;
uint32_t hardwareMinor;
uint32_t hardwareMajor;
uint32_t uniqueId;
};
/**
* Storage for REV PDH Faults
*/
struct HAL_REVPDHFaults {
uint32_t channel0BreakerFault : 1;
uint32_t channel1BreakerFault : 1;
uint32_t channel2BreakerFault : 1;
uint32_t channel3BreakerFault : 1;
uint32_t channel4BreakerFault : 1;
uint32_t channel5BreakerFault : 1;
uint32_t channel6BreakerFault : 1;
uint32_t channel7BreakerFault : 1;
uint32_t channel8BreakerFault : 1;
uint32_t channel9BreakerFault : 1;
uint32_t channel10BreakerFault : 1;
uint32_t channel11BreakerFault : 1;
uint32_t channel12BreakerFault : 1;
uint32_t channel13BreakerFault : 1;
uint32_t channel14BreakerFault : 1;
uint32_t channel15BreakerFault : 1;
uint32_t channel16BreakerFault : 1;
uint32_t channel17BreakerFault : 1;
uint32_t channel18BreakerFault : 1;
uint32_t channel19BreakerFault : 1;
uint32_t channel20BreakerFault : 1;
uint32_t channel21BreakerFault : 1;
uint32_t channel22BreakerFault : 1;
uint32_t channel23BreakerFault : 1;
uint32_t brownout : 1;
uint32_t canWarning : 1;
uint32_t hardwareFault : 1;
};
/**
* Storage for REV PDH Sticky Faults
*/
struct HAL_REVPDHStickyFaults {
uint32_t channel0BreakerFault : 1;
uint32_t channel1BreakerFault : 1;
uint32_t channel2BreakerFault : 1;
uint32_t channel3BreakerFault : 1;
uint32_t channel4BreakerFault : 1;
uint32_t channel5BreakerFault : 1;
uint32_t channel6BreakerFault : 1;
uint32_t channel7BreakerFault : 1;
uint32_t channel8BreakerFault : 1;
uint32_t channel9BreakerFault : 1;
uint32_t channel10BreakerFault : 1;
uint32_t channel11BreakerFault : 1;
uint32_t channel12BreakerFault : 1;
uint32_t channel13BreakerFault : 1;
uint32_t channel14BreakerFault : 1;
uint32_t channel15BreakerFault : 1;
uint32_t channel16BreakerFault : 1;
uint32_t channel17BreakerFault : 1;
uint32_t channel18BreakerFault : 1;
uint32_t channel19BreakerFault : 1;
uint32_t channel20BreakerFault : 1;
uint32_t channel21BreakerFault : 1;
uint32_t channel22BreakerFault : 1;
uint32_t channel23BreakerFault : 1;
uint32_t brownout : 1;
uint32_t canWarning : 1;
uint32_t canBusOff : 1;
uint32_t hasReset : 1;
};
#ifdef __cplusplus
extern "C" {
#endif
@@ -32,21 +103,21 @@ extern "C" {
* @param module the device CAN ID (1 .. 63)
* @return the created PDH handle
*/
HAL_REVPDHHandle HAL_REV_InitializePDH(int32_t module,
const char* allocationLocation,
int32_t* status);
HAL_REVPDHHandle HAL_InitializeREVPDH(int32_t module,
const char* allocationLocation,
int32_t* status);
/**
* Frees a PDH device handle.
*
* @param handle the previously created PDH handle
*/
void HAL_REV_FreePDH(HAL_REVPDHHandle handle);
void HAL_FreeREVPDH(HAL_REVPDHHandle handle);
/**
* Gets the module number for a pdh.
*/
int32_t HAL_REV_GetPDHModuleNumber(HAL_REVPDHHandle handle, int32_t* status);
int32_t HAL_GetREVPDHModuleNumber(HAL_REVPDHHandle handle, int32_t* status);
/**
* Checks if a PDH module number is valid.
@@ -56,34 +127,34 @@ int32_t HAL_REV_GetPDHModuleNumber(HAL_REVPDHHandle handle, int32_t* status);
* @param module module number (1 .. 63)
* @return 1 if the module number is valid; 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHModuleNumber(int32_t module);
HAL_Bool HAL_CheckREVPDHModuleNumber(int32_t module);
/**
* Checks if a PDH channel number is valid.
*
* @param module channel number (0 .. HAL_REV_PDH_NUM_CHANNELS)
* @param module channel number (0 .. kNumREVPDHChannels)
* @return 1 if the channel number is valid; 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHChannelNumber(int32_t channel);
HAL_Bool HAL_CheckREVPDHChannelNumber(int32_t channel);
/**
* Gets the current of a PDH channel in Amps.
*
* @param handle PDH handle
* @param channel the channel to retrieve the current of (0 ..
* HAL_REV_PDH_NUM_CHANNELS)
* kNumREVPDHChannels)
*
* @return the current of the PDH channel in Amps
*/
double HAL_REV_GetPDHChannelCurrent(HAL_REVPDHHandle handle, int32_t channel,
int32_t* status);
double HAL_GetREVPDHChannelCurrent(HAL_REVPDHHandle handle, int32_t channel,
int32_t* status);
/**
* @param handle PDH handle
* @param currents array of currents
*/
void HAL_REV_GetPDHAllChannelCurrents(HAL_REVPDHHandle handle, double* currents,
int32_t* status);
void HAL_GetREVPDHAllChannelCurrents(HAL_REVPDHHandle handle, double* currents,
int32_t* status);
/**
* Gets the total current of the PDH in Amps, measured to the nearest even
@@ -93,7 +164,7 @@ void HAL_REV_GetPDHAllChannelCurrents(HAL_REVPDHHandle handle, double* currents,
*
* @return the total current of the PDH in Amps
*/
uint16_t HAL_REV_GetPDHTotalCurrent(HAL_REVPDHHandle handle, int32_t* status);
uint16_t HAL_GetREVPDHTotalCurrent(HAL_REVPDHHandle handle, int32_t* status);
/**
* Sets the state of the switchable channel on a PDH device.
@@ -102,8 +173,8 @@ uint16_t HAL_REV_GetPDHTotalCurrent(HAL_REVPDHHandle handle, int32_t* status);
* @param enabled 1 if the switchable channel should be enabled; 0
* otherwise
*/
void HAL_REV_SetPDHSwitchableChannel(HAL_REVPDHHandle handle, HAL_Bool enabled,
int32_t* status);
void HAL_SetREVPDHSwitchableChannel(HAL_REVPDHHandle handle, HAL_Bool enabled,
int32_t* status);
/**
* Gets the current state of the switchable channel on a PDH device.
@@ -114,174 +185,9 @@ void HAL_REV_SetPDHSwitchableChannel(HAL_REVPDHHandle handle, HAL_Bool enabled,
* @param handle PDH handle
* @return 1 if the switchable channel is enabled; 0 otherwise
*/
HAL_Bool HAL_REV_GetPDHSwitchableChannelState(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Checks if a PDH channel is currently experiencing a brownout condition.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
* @param channel the channel to retrieve the brownout status of
*
* @return 1 if the channel is experiencing a brownout; 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHChannelBrownout(HAL_REVPDHHandle handle,
int32_t channel, int32_t* status);
/**
* Gets the voltage being supplied to a PDH device.
*
* @param handle PDH handle
*
* @return the voltage at the input of the PDH in Volts
*/
double HAL_REV_GetPDHSupplyVoltage(HAL_REVPDHHandle handle, int32_t* status);
/**
* Checks if a PDH device is currently enabled.
*
* @param handle PDH handle
*
* @return 1 if the PDH is enabled; 0 otherwise
*/
HAL_Bool HAL_REV_IsPDHEnabled(HAL_REVPDHHandle handle, int32_t* status);
/**
* Checks if the input voltage on a PDH device is currently below the minimum
* voltage.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the PDH is experiencing a brownout; 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHBrownout(HAL_REVPDHHandle handle, int32_t* status);
/**
* Checks if the CAN RX or TX error levels on a PDH device have exceeded the
* warning threshold.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the device has exceeded the warning threshold; 0
* otherwise
*/
HAL_Bool HAL_REV_CheckPDHCANWarning(HAL_REVPDHHandle handle, int32_t* status);
/**
* Checks if a PDH device is currently malfunctioning.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the device is in a hardware fault state; 0
* otherwise
*/
HAL_Bool HAL_REV_CheckPDHHardwareFault(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Checks if the input voltage on a PDH device has gone below the specified
* minimum voltage.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the device has had a brownout; 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHStickyBrownout(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Checks if the CAN RX or TX error levels on a PDH device have exceeded the
* warning threshold.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the device has exceeded the CAN warning threshold;
* 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHStickyCANWarning(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Checks if the CAN bus on a PDH device has previously experienced a 'Bus Off'
* event.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the device has experienced a 'Bus Off' event; 0
* otherwise
*/
HAL_Bool HAL_REV_CheckPDHStickyCANBusOff(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Checks if a PDH device has malfunctioned.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the device has had a malfunction; 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHStickyHardwareFault(HAL_REVPDHHandle handle,
HAL_Bool HAL_GetREVPDHSwitchableChannelState(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Checks if the firmware on a PDH device has malfunctioned and reset during
* operation.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the device has had a malfunction and reset; 0
* otherwise
*/
HAL_Bool HAL_REV_CheckPDHStickyFirmwareFault(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Checks if a brownout has happened on channels 20-23 of a PDH device while it
* was enabled.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
* @param channel PDH channel to retrieve sticky brownout status (20 ..
* 23)
*
*
* @return 1 if the channel has had a brownout; 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHStickyChannelBrownout(HAL_REVPDHHandle handle,
int32_t channel,
int32_t* status);
/**
* Checks if a PDH device has reset.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*
* @return 1 if the device has reset; 0 otherwise
*/
HAL_Bool HAL_REV_CheckPDHStickyHasReset(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Gets the firmware and hardware versions of a PDH device.
*
@@ -289,25 +195,43 @@ HAL_Bool HAL_REV_CheckPDHStickyHasReset(HAL_REVPDHHandle handle,
*
* @return version information
*/
REV_PDH_Version HAL_REV_GetPDHVersion(HAL_REVPDHHandle handle, int32_t* status);
HAL_REVPDHVersion HAL_GetREVPDHVersion(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Gets the voltage being supplied to a PDH device.
*
* @param handle PDH handle
*
* @return the voltage at the input of the PDH in Volts
*/
double HAL_GetREVPDHVoltage(HAL_REVPDHHandle handle, int32_t* status);
/**
* Gets the faults of a PDH device.
*
* @param handle PDH handle
*
* @return the faults of the PDH
*/
HAL_REVPDHFaults HAL_GetREVPDHFaults(HAL_REVPDHHandle handle, int32_t* status);
/**
* Gets the sticky faults of a PDH device.
*
* @param handle PDH handle
*
* @return the sticky faults of the PDH
*/
HAL_REVPDHStickyFaults HAL_GetREVPDHStickyFaults(HAL_REVPDHHandle handle,
int32_t* status);
/**
* Clears the sticky faults on a PDH device.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*/
void HAL_REV_ClearPDHFaults(HAL_REVPDHHandle handle, int32_t* status);
/**
* Identifies a PDH device by blinking its LED.
*
* NOTE: Not implemented in firmware as of 2021-04-23.
*
* @param handle PDH handle
*/
void HAL_REV_IdentifyPDH(HAL_REVPDHHandle handle, int32_t* status);
void HAL_ClearREVPDHStickyFaults(HAL_REVPDHHandle handle, int32_t* status);
#ifdef __cplusplus
} // extern "C"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff