Skip to content

Commit 1ead382

Browse files
committed
drive state required for PCU drive
1 parent f5ba9c6 commit 1ead382

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

PCU/Core/User/Inc/FEB_CAN_BMS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ float FEB_CAN_BMS_getMaxTemperature(void);
6464
void FEB_CAN_BMS_Init(void);
6565
void FEB_CAN_HEARTBEAT_Transmit(void);
6666
void FEB_CAN_BMS_ProcessHeartbeat(void);
67+
bool FEB_CAN_BMS_InDriveState(void);
6768

6869
#endif /* INC_FEB_CAN_BMS_H_ */

PCU/Core/User/Src/FEB_CAN_BMS.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "FEB_CAN_BMS.h"
22
#include "feb_uart_log.h"
3+
#include <stdbool.h>
4+
5+
/* Timeout for BMS CAN communication (ms) */
6+
#define BMS_STATE_TIMEOUT_MS 500
37

48
/* Global BMS message data */
59
BMS_MESSAGE_TYPE BMS_MESSAGE;
@@ -140,3 +144,19 @@ void FEB_CAN_BMS_ProcessHeartbeat(void)
140144
FEB_CAN_HEARTBEAT_Transmit();
141145
}
142146
}
147+
148+
bool FEB_CAN_BMS_InDriveState(void)
149+
{
150+
// Check for recent BMS communication
151+
if (BMS_MESSAGE.last_rx_timestamp == 0)
152+
{
153+
return false; // Never received BMS data
154+
}
155+
156+
if (HAL_GetTick() - BMS_MESSAGE.last_rx_timestamp > BMS_STATE_TIMEOUT_MS)
157+
{
158+
return false; // BMS communication timeout
159+
}
160+
161+
return BMS_MESSAGE.state == FEB_SM_ST_DRIVE;
162+
}

PCU/Core/User/Src/FEB_RMS.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "FEB_RMS.h"
22
#include "FEB_ADC.h"
3+
#include "FEB_CAN_BMS.h"
34
#include "FEB_CAN_RMS.h"
45
#include "FEB_RMS_Config.h"
56
#include "FEB_Debug.h"
@@ -29,6 +30,13 @@ void FEB_RMS_Setup(void)
2930

3031
void FEB_RMS_Process(void)
3132
{
33+
// Require BMS to be in drive state before enabling inverter
34+
if (!FEB_CAN_BMS_InDriveState())
35+
{
36+
LOG_W(TAG_RMS, "Cannot enable RMS: BMS not in drive state (state=%d)", BMS_MESSAGE.state);
37+
return;
38+
}
39+
3240
if (!RMS_CONTROL_MESSAGE.enabled)
3341
{
3442
LOG_I(TAG_RMS, "Sending RMS disable commands to clear lockout");
@@ -175,13 +183,20 @@ float FEB_RMS_GetMaxTorque(void)
175183
*/
176184
void FEB_RMS_Torque(void)
177185
{
186+
// Auto-disable RMS if BMS leaves drive state or communication is lost
187+
if (DRIVE_STATE && !FEB_CAN_BMS_InDriveState())
188+
{
189+
LOG_W(TAG_RMS, "BMS left drive state or timeout, disabling RMS");
190+
FEB_RMS_Disable();
191+
}
178192

179193
// Read latest sensor data
180194
FEB_ADC_GetAPPSData(&APPS_Data);
181195
FEB_ADC_GetBrakeData(&Brake_Data);
182196

183-
// Check plausibility and safety conditions
184-
bool sensors_plausible = true; // OVERRIDE: bypass implausibility for testing
197+
// Check plausibility and safety conditions (require BMS in drive state)
198+
bool bms_in_drive = FEB_CAN_BMS_InDriveState();
199+
bool sensors_plausible = bms_in_drive && DRIVE_STATE;
185200

186201
// Log any safety violations
187202
if (!sensors_plausible)

0 commit comments

Comments
 (0)