Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ced8dd0
Initial changeover, totally untested
dchansen06 May 12, 2026
02521cc
Bring back HOOTL testing
dchansen06 May 12, 2026
44484e6
Set bspd sense in test to new good value
kzwicker May 13, 2026
ebe95dd
Fix analog data and inverter command frequency
dchansen06 May 13, 2026
2e36676
Sanity set initial statics to 0
dchansen06 May 13, 2026
619f576
Fix can dlc size
dchansen06 May 13, 2026
d8bfa01
Revise dti send can
dchansen06 May 13, 2026
b018016
Scale torque request respectfully
dchansen06 May 13, 2026
5d63c9d
Random tested values for throttle
dchansen06 May 13, 2026
0b7fc64
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] May 13, 2026
de64947
Switch to custom bytes to CAN DLC function for hootl test
dchansen06 May 13, 2026
3a1c390
Allegedly fix rtd button press latch
dchansen06 May 13, 2026
a2a6bee
Read and reset the variable set by the button read interrupt exactly …
kzwicker May 13, 2026
4f9ad78
Explicitly send do not torque
dchansen06 May 13, 2026
55ea9e2
Driving check?
dchansen06 May 13, 2026
42392ff
ADC alpha is useless if not rate limited
dchansen06 May 13, 2026
3e558c0
Remove sketchy APPS debug logic
dchansen06 May 14, 2026
3e01c85
Migrate analog data message out of state ticks to be something always…
dchansen06 May 14, 2026
daabfdf
Merge branch 'main' into HV-test
dchansen06 May 14, 2026
483657d
Merge branch 'main' into HV-test
dchansen06 May 14, 2026
32f2d30
added a scary FIXME for the code causing HOOTLTest failures
SlowThomas May 15, 2026
524477e
No more DWT
dchansen06 May 15, 2026
0b52ba7
Set clock div 4, oversample 64, bitshift right 6
dchansen06 May 15, 2026
76afff7
Cycle adc init values into real values while in hot loop waiting for …
dchansen06 May 15, 2026
928b3dc
Grab 20V level from ACU
kzwicker May 18, 2026
383b275
consolidate comparisons of ams bms bspd sense lines to one function
kzwicker May 18, 2026
f26a0e4
Unfuck the bspd (does not depend on GLV 20V)
kzwicker May 18, 2026
b1715d3
give 20v line a default value so something sensible happens on startup
kzwicker May 19, 2026
0656b50
is good
kzwicker May 19, 2026
330bbed
double unfuck the bspd
kzwicker May 19, 2026
a83a94b
Merge branch 'main' into dynamic-SDC-voltages
kzwicker May 30, 2026
de78348
remove duplicate fn
kzwicker May 30, 2026
2266eb8
change SDC levels
kzwicker May 30, 2026
e6a85b3
Add condition for SDC startup instead of weird latch thing
kzwicker May 30, 2026
27aafa8
comments
kzwicker May 30, 2026
7efeafb
bms not ams
kzwicker May 30, 2026
f47a4af
also bms here
kzwicker May 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ECU/Application/Inc/StateData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -62,10 +63,8 @@ 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 bms_sense;
float imd_sense;
float bspd_sense;

Expand Down
9 changes: 9 additions & 0 deletions ECU/Application/Inc/StateUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ uint32_t MillisecondsSinceBoot(void);
*/
#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);
Expand Down
1 change: 1 addition & 0 deletions ECU/Application/Src/CANdler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_INV_STATUS_1:
Expand Down
1 change: 0 additions & 1 deletion ECU/Application/Src/CANutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ void SendECUAnalogDataOverCAN(ECU_StateData *stateData)
uint32_t millis_since_boot = MillisecondsSinceBoot();

static uint32_t last_can_tcm_request_millis = 0;

if (millis_since_boot - last_can_tcm_request_millis > 100) {
GRCAN_ECU_ANALOG_DATA_MSG message = {.bspd_signal = stateData->bspd_signal,
.bse_signal = stateData->bse_signal,
Expand Down
26 changes: 25 additions & 1 deletion ECU/Application/Src/Lights.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,35 @@ void BrakeLightControl(ECU_StateData *stateLump)
}
}

static bool SDCStartupCondition = true; // prevent false positive TSSI on startup
// PRECONDITION: IMD assumed to give valid readings before this is run
void TSSILightControl(ECU_StateData *stateLump)
{
// EV.5.11.5: Flash, 2 Hz to 5 Hz, 50% duty cycle
// Here we chose a period of 286ms
if (stateLump->tssi_fault) {

bool redCar;

// if we are before SDC is reset, don't red car unless there is an active failure
if (SDCStartupCondition) {
redCar = false;

SDC_Level bms = bmsLevel(stateLump);
SDC_Level imd = imdLevel(stateLump);

if (bms == SDC_OK && imd == SDC_OK) {
SDCStartupCondition = false;
} else if (bms == SDC_ONGOING_FAILURE || imd == SDC_ONGOING_FAILURE) {
SDCStartupCondition = false;
redCar = true;
}
} else {
redCar = bmsFailure(stateLump) || imdFailure(stateLump);
}


// if red car blink tssi
if (redCar) {
LL_GPIO_ResetOutputPin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin);
if (MillisecondsSinceBoot() % 286 < 143) {
LL_GPIO_SetOutputPin(TSSI_R_CONTROL_GPIO_Port, TSSI_R_CONTROL_Pin);
Expand Down
23 changes: 1 addition & 22 deletions ECU/Application/Src/StateTicks.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @remark Intentionally not a globally accessible variable
*/

ECU_StateData stateLump = {.ecu_state = GR_GLV_ON, .acu_software_latch = 1, .powerlevel = 3};
ECU_StateData stateLump = {.ecu_state = GR_GLV_ON, .acu_software_latch = 1, .glv_voltage_20V = 20.0f, .powerlevel = 3};

static uint32_t millis_since_boot;
void ECU_State_Tick(void)
Expand All @@ -39,27 +39,6 @@ void ECU_State_Tick(void)
last_ECU_status_msg_millis = millis_since_boot;
}

// light control
// false or imd_sense > 0.5 -> false -> no light
// false or imd_sense < 0.5 -> true -> light
// true or imd_sense > 0.5 -> true -> light stays on
// stateLump.bms_light |= !(stateLump.ams_sense > 0.5f);
// stateLump.imd_light |= !(stateLump.imd_sense > 0.5f);
// lgoht control reset

// true and no failiure -> flase
// true and failiure -> true
// false and failure -> false
// flase and no failure -> false
// stateLump.bms_light &= (bmsFailure(&stateLump));
// stateLump.imd_light &= (imdFailure(&stateLump));

stateLump.bms_light = (stateLump.ams_sense <= 0.4f) || (stateLump.bms_light && bmsFailure(&stateLump));
stateLump.imd_light = (stateLump.imd_sense <= 0.4f) || (stateLump.imd_light && imdFailure(&stateLump));

stateLump.tssi_fault = stateLump.bms_light || stateLump.imd_light;

// bmsFailure(&stateLump) || imdFailure(&stateLump);

if (stateLump.ts_active_button_press_interrupt) {
stateLump.ts_active_button_press_interrupt = false;
Expand Down
46 changes: 39 additions & 7 deletions ECU/Application/Src/StateUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,43 @@ bool CriticalError(volatile const ECU_StateData *stateData)
return problem;
}

SDC_Level bmsLevel(volatile const ECU_StateData *stateData) {
// TODO: DYNAMIC LOGIC HERE
if (stateData->bms_sense < 0.2f) {
return SDC_ONGOING_FAILURE;
} else if (stateData->bms_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.2f) {
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) {
if (stateData->bspd_sense < 0.6f) {
return SDC_ONGOING_FAILURE;
} else if (stateData->bspd_sense > 1.35f) {
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)
Expand All @@ -71,16 +105,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)
{
#ifdef PLAN_C
return false;
#endif

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)
Expand Down
4 changes: 2 additions & 2 deletions ECU/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void write_adc_values_to_state_data(void)
// TODO: determine conversion factors for all of these (uint to float)
stateLump.bspd_sense = ADC_outputs[ADC_BUFFER_SENSE_BSPD] / 4095.0 * 3.3;
stateLump.imd_sense = ADC_outputs[ADC_BUFFER_SENSE_IMD] / 4095.0 * 3.3;
stateLump.ams_sense = ADC_outputs[ADC_BUFFER_SENSE_AMS] / 4095.0 * 3.3;
stateLump.bms_sense = ADC_outputs[ADC_BUFFER_SENSE_AMS] / 4095.0 * 3.3;
}

void ADC_Configure(void)
Expand Down Expand Up @@ -540,7 +540,7 @@ int main(void)
// ADC_Logomatic();
}
}
/* USER CODE END 3 */
/* USER CODE END 3 */
}

/**
Expand Down
Loading