From 928b3dc7f22c520eb6b3316f7eb0a13bedf042a1 Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Sun, 17 May 2026 22:59:12 -0700 Subject: [PATCH 1/6] Grab 20V level from ACU --- ECU/Application/Inc/StateData.h | 5 ++--- ECU/Application/Src/CANdler.c | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ECU/Application/Inc/StateData.h b/ECU/Application/Inc/StateData.h index 47b3cd03a..722b33645 100644 --- a/ECU/Application/Inc/StateData.h +++ b/ECU/Application/Inc/StateData.h @@ -54,6 +54,7 @@ typedef volatile struct ECU_StateData { float min_amk_heat_cap_throttle_percent; float ts_voltage; + float glv_voltage_20V; float max_cell_temp_c; /** Temperature of hottest cell, celsius */ float vehicle_speed_mph; /** Vehicle speed, MPH */ @@ -62,9 +63,7 @@ typedef volatile struct ECU_StateData { float rr_wheel_rpm; /** RRv wheel, RPM */ float rl_wheel_rpm; /** RL wheel, RPM */ - // 0.5V when things go to shit (X_OK low) (BAD) - // 3V when things almost poggers (X_OK high but SDC not reset) (BAD) - // 2.4V when things are actually poggers (X_OK high and SDC is not triggered) + float ams_sense; float imd_sense; float bspd_sense; diff --git a/ECU/Application/Src/CANdler.c b/ECU/Application/Src/CANdler.c index 30ff94704..a28821a69 100644 --- a/ECU/Application/Src/CANdler.c +++ b/ECU/Application/Src/CANdler.c @@ -80,6 +80,7 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA state_data->ir_minus = GETBIT(acu_status_2->precharge_latch_flags, 4); state_data->ir_plus = GETBIT(acu_status_2->precharge_latch_flags, 5); state_data->acu_software_latch = GETBIT(acu_status_2->precharge_latch_flags, 6); + state_data->glv_voltage_20V = acu_status_2->_20v_voltage * 0.1f; break; case GRCAN_INVERTER_STATUS_1: From 383b2755fa3f7a8824ed0236261c5a8692057884 Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Sun, 17 May 2026 23:34:26 -0700 Subject: [PATCH 2/6] consolidate comparisons of ams bms bspd sense lines to one function --- ECU/Application/Inc/StateUtils.h | 9 +++++++ ECU/Application/Src/StateTicks.c | 7 ++++-- ECU/Application/Src/StateUtils.c | 42 +++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/ECU/Application/Inc/StateUtils.h b/ECU/Application/Inc/StateUtils.h index cd1798501..af185c58a 100644 --- a/ECU/Application/Inc/StateUtils.h +++ b/ECU/Application/Inc/StateUtils.h @@ -42,8 +42,17 @@ uint32_t MillisecondsSinceBoot(void); #define RATE_LIMIT_100_HZ(x, y) (x - y > 10) #define RATE_LIMIT_10_HZ(x, y) (x - y > 100) +typedef enum { + SDC_OK, + SDC_ONGOING_FAILURE, + SDC_LATCHED_FAILURE +} SDC_Level; + // Checks stateData for critical errors bool CriticalError(volatile const ECU_StateData *stateData); +SDC_Level bmsLevel(volatile const ECU_StateData *stateData); +SDC_Level imdLevel(volatile const ECU_StateData *stateData); +SDC_Level bspdLevel(volatile const ECU_StateData *stateData); bool bmsFailure(volatile const ECU_StateData *stateData); bool imdFailure(volatile const ECU_StateData *stateData); bool bspdFailure(volatile const ECU_StateData *stateData); diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 96a14ea89..827f27fd6 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -53,8 +53,11 @@ void ECU_State_Tick(void) // stateLump.bms_light &= (bmsFailure(&stateLump)); // stateLump.imd_light &= (imdFailure(&stateLump)); - stateLump.bms_light = (stateLump.ams_sense <= 0.5f) || (stateLump.bms_light && bmsFailure(&stateLump)); - stateLump.imd_light = (stateLump.ams_sense <= 0.5f) || (stateLump.imd_light && imdFailure(&stateLump)); + SDC_Level bms_level = bmsLevel(&stateLump); + SDC_Level imd_level = imdLevel(&stateLump); + + stateLump.bms_light = (bms_level == SDC_ONGOING_FAILURE) || (stateLump.bms_light && bmsFailure(&stateLump)); + stateLump.imd_light = (imd_level == SDC_ONGOING_FAILURE) || (stateLump.imd_light && imdFailure(&stateLump)); stateLump.tssi_fault = stateLump.bms_light || stateLump.imd_light; diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index 2162eb661..bc02ba21c 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -55,9 +55,43 @@ bool CriticalError(volatile const ECU_StateData *stateData) return problem; } +SDC_Level bmsLevel(volatile const ECU_StateData *stateData) { + // TODO: DYNAMIC LOGIC HERE + if (stateData->ams_sense < 0.5f) { + return SDC_ONGOING_FAILURE; + } else if (stateData->ams_sense > 1.6f) { + return SDC_LATCHED_FAILURE; + } + + return SDC_OK; +} + +SDC_Level imdLevel(volatile const ECU_StateData *stateData) { + // TODO: DYNAMIC LOGIC HERE + if (stateData->imd_sense < 0.5f) { + return SDC_ONGOING_FAILURE; + } else if (stateData->imd_sense > 1.6f) { + return SDC_LATCHED_FAILURE; + } + + return SDC_OK; +} + +SDC_Level bspdLevel(volatile const ECU_StateData *stateData) { + // TODO: DYNAMIC LOGIC HERE + if (stateData->bspd_sense < 0.5f) { + return SDC_ONGOING_FAILURE; + } else if (stateData->imd_sense > 1.6f) { + return SDC_LATCHED_FAILURE; + } + + return SDC_OK; +} + bool bmsFailure(volatile const ECU_StateData *stateData) { - return stateData->ams_sense < 0.5f || stateData->ams_sense > 1.6f; // 0.5 to 1.6 is valid + SDC_Level level = bmsLevel(stateData); + return level == SDC_ONGOING_FAILURE || level == SDC_LATCHED_FAILURE; } bool imdFailure(volatile const ECU_StateData *stateData) @@ -68,12 +102,14 @@ bool imdFailure(volatile const ECU_StateData *stateData) return false; } - return stateData->imd_sense < 0.5f || stateData->imd_sense > 1.6f; // 0.5 to 1.6 is valid + SDC_Level level = imdLevel(stateData); + return level == SDC_ONGOING_FAILURE || level == SDC_LATCHED_FAILURE; } bool bspdFailure(volatile const ECU_StateData *stateData) { - return stateData->bspd_sense < 0.6f || stateData->bspd_sense > 1.35f; // possible values are 0.3, 1.2, 1.6 + SDC_Level level = bspdLevel(stateData); + return level == SDC_ONGOING_FAILURE || level == SDC_LATCHED_FAILURE; } bool APPS_BSE_Violation(volatile const ECU_StateData *stateData) From f26a0e4700ebf6829631a4df23661973dfb35247 Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Sun, 17 May 2026 23:44:00 -0700 Subject: [PATCH 3/6] Unfuck the bspd (does not depend on GLV 20V) --- ECU/Application/Src/StateUtils.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index bc02ba21c..191f650e9 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -78,10 +78,9 @@ SDC_Level imdLevel(volatile const ECU_StateData *stateData) { } SDC_Level bspdLevel(volatile const ECU_StateData *stateData) { - // TODO: DYNAMIC LOGIC HERE - if (stateData->bspd_sense < 0.5f) { + if (stateData->bspd_sense < 0.6f) { return SDC_ONGOING_FAILURE; - } else if (stateData->imd_sense > 1.6f) { + } else if (stateData->imd_sense > 1.35f) { return SDC_LATCHED_FAILURE; } From b1715d34f5f3ed9231c52e81826004d92fbfc3fc Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Mon, 18 May 2026 19:03:57 -0700 Subject: [PATCH 4/6] give 20v line a default value so something sensible happens on startup --- ECU/Application/Src/StateTicks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 827f27fd6..ce25bd6e3 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -25,7 +25,7 @@ * @remark Intentionally not a globally accessible variable */ -ECU_StateData stateLump = {.ecu_state = GR_GLV_ON, .acu_software_latch = 1}; +ECU_StateData stateLump = {.ecu_state = GR_GLV_ON, .acu_software_latch = 1, .glv_voltage_20V = 20.0f}; static uint32_t millis_since_boot; void ECU_State_Tick(void) From 0656b50f8bd2fc395380efb7d7c0f76ea41a4e84 Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Mon, 18 May 2026 19:18:38 -0700 Subject: [PATCH 5/6] is good --- ECU/Core/Src/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ECU/Core/Src/main.c b/ECU/Core/Src/main.c index 614b570c9..63dfe0044 100644 --- a/ECU/Core/Src/main.c +++ b/ECU/Core/Src/main.c @@ -123,7 +123,6 @@ void write_adc_values_to_state_data(void) stateLump.aux_signal = ADC_outputs[6]; stateLump.steering_angle_signal = ADC_outputs[10]; // TODO: convert to rad/deg...? - // TODO: determine conversion factors for all of these (uint to float) stateLump.bspd_sense = ADC_outputs[7] / 4095.0 * 3.3; stateLump.imd_sense = ADC_outputs[8] / 4095.0 * 3.3; stateLump.ams_sense = ADC_outputs[9] / 4095.0 * 3.3; From 330bbed98641ad67d7dc930fcd44ee16e4f7ad86 Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Mon, 18 May 2026 20:37:19 -0700 Subject: [PATCH 6/6] double unfuck the bspd --- ECU/Application/Src/StateUtils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index 191f650e9..ad50ce3e9 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -80,7 +80,7 @@ SDC_Level imdLevel(volatile const ECU_StateData *stateData) { SDC_Level bspdLevel(volatile const ECU_StateData *stateData) { if (stateData->bspd_sense < 0.6f) { return SDC_ONGOING_FAILURE; - } else if (stateData->imd_sense > 1.35f) { + } else if (stateData->bspd_sense > 1.35f) { return SDC_LATCHED_FAILURE; }