Skip to content

Commit 1d0e0a7

Browse files
committed
can fault on a latching fault
1 parent 9e703f6 commit 1d0e0a7

9 files changed

Lines changed: 78 additions & 6 deletions

File tree

.mxproject

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Cerberus-2.0.ioc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ FDCAN2.Mode=FDCAN_MODE_NORMAL
101101
FDCAN2.NominalPrescaler=8
102102
FDCAN2.NominalTimeSeg1=11
103103
FDCAN2.NominalTimeSeg2=4
104-
FDCAN2.StdFiltersNbr=12
104+
FDCAN2.StdFiltersNbr=14
105105
File.Version=6
106106
GPDMA1.CIRCULARMODE_GPDMACH4=ENABLE
107107
GPDMA1.CIRCULARMODE_GPDMACH5=ENABLE
@@ -486,7 +486,6 @@ PC9.GPIO_Label=MUX_SEL4
486486
PC9.Locked=true
487487
PC9.Signal=GPIO_Output
488488
PCC.Checker=false
489-
PCC.Display=Plot\: All Steps
490489
PCC.Line=STM32H563/H573
491490
PCC.MCU=STM32H563ZITx
492491
PCC.PartNumber=STM32H563ZITx

Core/Inc/u_bms.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __U_BMS_H
33

44
#include <stdint.h>
5+
#include "can_messages_rx.h"
56

67
/* API */
78

@@ -19,4 +20,9 @@ void bms_setBattboxTemp(float temp); // Sets the battbox temperature. The "temp"
1920

2021
void bms_receivePrechargeState(precharge_state_t precharge);
2122
bool bms_getPrecharge(void);
23+
24+
int bms_handleBmsFaultMessage(can_msg_t *message); // CAN faults upon receiving a latching fault message from BMS
25+
int imd_handleImdFaultMessage(can_msg_t *message); // CAN faults upon receiving a latctching fault message from IMD
26+
27+
2228
#endif /* u_bms.h */

Core/Inc/u_can.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ extern can_t can1;
6969
#define CANID_F_RPM 0xDB0
7070
#define CANID_R_RPM 0xDB1
7171

72+
/* Latching Fault CAN IDs */
73+
#define IMD_GENERAL_MSG_ID 0x37
74+
#define BMS_LIGHTNING_OKAY_MSG_ID 0x01E
75+
7276
#endif /* u_can.h */

Core/Inc/u_faults.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef enum {
1111
BMS_CAN_MONITOR_FAULT,
1212
LIGHTNING_CAN_MONITOR_FAULT,
1313
PRECHARGE_FLOATING_FAULT,
14+
LATCHING_ACTIVE_FAULT,
1415

1516
/* Non-critical Faults */
1617
ONBOARD_TEMP_FAULT,

Core/Src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ static void MX_FDCAN2_Init(void)
668668
hfdcan2.Init.DataSyncJumpWidth = 1;
669669
hfdcan2.Init.DataTimeSeg1 = 1;
670670
hfdcan2.Init.DataTimeSeg2 = 1;
671-
hfdcan2.Init.StdFiltersNbr = 12;
671+
hfdcan2.Init.StdFiltersNbr = 14;
672672
hfdcan2.Init.ExtFiltersNbr = 8;
673673
hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
674674
if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK)

Core/Src/u_bms.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,55 @@ int bms_handleDclMessage(void)
5757
return U_SUCCESS;
5858
}
5959

60+
int bms_handleBmsFaultMessage(can_msg_t *message) {
61+
bms_critically_faulted_t data = { 0 };
62+
receive_bms_critically_faulted(message, &data);
63+
PRINTLN_INFO("bms critically faulted=%d", data.critically_faulted);
64+
if (data.critically_faulted == true) {
65+
queue_send(&faults, &(fault_t){LATCHING_ACTIVE_FAULT}, TX_NO_WAIT);
66+
}
67+
}
68+
69+
#define _GET_BIT(data, bit) (((data) & (1U << (bit))) != 0U)
70+
int imd_handleImdFaultMessage(can_msg_t *message) {
71+
/* Extract the warnings and alarms field (bytes 4 and 5 of the message). */
72+
uint16_t warnings_and_alarms = 0;
73+
memcpy(&warnings_and_alarms, &message->data[4], 2); // Copy over two bytes of the message, starting at byte 4. This should result in byte 4 and byte 5 being copied over.
74+
75+
/* Get all the bit states from the register. */
76+
bool device_error_active = _GET_BIT(warnings_and_alarms, 0); // true = device error active
77+
bool HV_pos_connection_failure = _GET_BIT(warnings_and_alarms, 1); // true = HV_pos connection failure
78+
bool HV_neg_connection_failure = _GET_BIT(warnings_and_alarms, 2); // true = HV_neg connection failure
79+
bool Earth_connection_failure = _GET_BIT(warnings_and_alarms, 3); // true = Earth connection failure
80+
bool Iso_alarm = _GET_BIT(warnings_and_alarms, 4); // true = Iso value below threshold error
81+
bool Iso_warning = _GET_BIT(warnings_and_alarms, 5); // true = Iso value below treshold warning
82+
bool Iso_outdated = _GET_BIT(warnings_and_alarms, 6); // true = Iso outdated
83+
bool Unbalance_alarm = _GET_BIT(warnings_and_alarms, 7); // true = unbalane value below threshold
84+
bool Undervoltage_alarm = _GET_BIT(warnings_and_alarms, 8); // true = undervoltage alarm
85+
bool Unsafe_to_start = _GET_BIT(warnings_and_alarms, 9); // true = Unsafe to start
86+
bool Earthlift_open = _GET_BIT(warnings_and_alarms, 10); // true = Earthlift open
87+
88+
/* Do we have an error? */
89+
bool imd_error =
90+
device_error_active ||
91+
HV_pos_connection_failure ||
92+
HV_neg_connection_failure ||
93+
Earth_connection_failure ||
94+
Iso_alarm ||
95+
Iso_warning ||
96+
Iso_outdated ||
97+
Unbalance_alarm ||
98+
Undervoltage_alarm ||
99+
Unsafe_to_start ||
100+
Earthlift_open;
101+
// Right now, if any of these are true, we are considering it an error.
102+
103+
/* Update `has_imd_made_contact`, since we have made contact if this has been called. */
104+
if (imd_error) {
105+
queue_send(&faults, &(fault_t){LATCHING_ACTIVE_FAULT}, TX_NO_WAIT);
106+
}
107+
}
108+
60109
/* Returns the battbox temperature. */
61110
float bms_getBattboxTemp(void) {
62111
return battbox_temp;

Core/Src/u_can.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ uint8_t can1_init(FDCAN_HandleTypeDef *hcan) {
6060
}
6161

6262
/* Add filters for standard IDs */
63-
uint16_t standard5[] = {CANID_SHUTDOWN, 0x00};
63+
uint16_t standard5[] = {CANID_SHUTDOWN, IMD_GENERAL_MSG_ID};
6464
status = can_add_filter_standard(&can1, standard5);
6565
if (status != HAL_OK) {
6666
PRINTLN_ERROR("Failed to add standard filter to can1 (Status: %d/%s, ID1: 0x%X, ID2: 0x%X).", status, hal_status_toString(status), standard5[0], standard5[1]);
6767
return U_ERROR;
6868
}
6969

70-
70+
/* Add filters for standard IDs */
71+
uint16_t standard6[] = {BMS_LIGHTNING_OKAY_MSG_ID, 0x0};
72+
status = can_add_filter_standard(&can1, standard6);
73+
if (status != HAL_OK) {
74+
PRINTLN_ERROR("Failed to add standard filter to can1 (Status: %d/%s, ID1: 0x%X, ID2: 0x%X).", status, hal_status_toString(status), standard6[0], standard6[1]);
75+
return U_ERROR;
76+
}
7177

7278
/* Add fitlers for extended IDs */
7379
uint32_t extended1[] = {CANID_CALYPSO_EFCTRL_DASHBOARD, CANID_CALYPSO_EFCTRL_BRAKE};
@@ -255,6 +261,12 @@ void can_inbox(can_msg_t *message) {
255261
}
256262
}
257263
break;
264+
case IMD_GENERAL_MSG_ID:
265+
imd_handleImdFaultMessage(message);
266+
break;
267+
case BMS_LIGHTNING_OKAY_MSG_ID:
268+
bms_handleBmsFaultMessage(message);
269+
break;
258270
default:
259271
PRINTLN_WARNING("Unknown CAN Message Recieved (Message ID: 0x%X).", message->id);
260272
break;

Core/Src/u_faults.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static const _metadata faults[] = {
2626
[BMS_CAN_MONITOR_FAULT] = {"BMS_CAN_MONITOR_FAULT", CRITICAL, .timeout = 5000},
2727
[LIGHTNING_CAN_MONITOR_FAULT] = {"LIGHTNING_CAN_MONITOR_FAULT", CRITICAL, .timeout = 5000},
2828
[PRECHARGE_FLOATING_FAULT] = {"PRECHARGE_FLOATING_FAULT", CRITICAL, .timeout = 5000},
29+
[LATCHING_ACTIVE_FAULT] = {"LATCHING_ACTIVE_FAULT", CRITICAL, .timeout = 10000},
2930

3031
/* Non-critical Faults */
3132
[ONBOARD_TEMP_FAULT] = {"ONBOARD_TEMP_FAULT", NON_CRITICAL, .timeout = 5000},

0 commit comments

Comments
 (0)