Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
194f1ca
The beginnings of state machine implementation
kzwicker Jan 9, 2026
d3c9322
The beginnings of state machine implementation
kzwicker Jan 9, 2026
c1ed33e
Added the function signature of ECU_Tractive_System_Discharge_Start i…
SlowThomas Jan 9, 2026
35bc726
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 13, 2026
5e8a21b
Merge branch 'StateMachineImplementation' of https://github.com/Gauch…
kzwicker Jan 13, 2026
1114241
cleaned up data, switched to floats, etc
kzwicker Jan 13, 2026
6f38a83
Merge branch 'StateMachineImplementation' of https://github.com/Gauch…
kzwicker Jan 13, 2026
4008051
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 13, 2026
a72a587
add a placeholder
SlowThomas Jan 13, 2026
b2d1ef0
Merge branch 'main' into StateMachineImplementation
dchansen06 Jan 13, 2026
f33172e
volatile state lump
kzwicker Jan 16, 2026
6a27ff1
scopes
kzwicker Jan 16, 2026
cec19d0
adc basic functionality to ECU
khoulihan27 Jan 16, 2026
6fa0832
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 16, 2026
5c7f46b
Merge branch 'main' into StateMachineImplementation
dchansen06 Jan 16, 2026
beb3a2f
fixed LL stuff
khoulihan27 Jan 16, 2026
9a978d2
fixed LL implementation
khoulihan27 Jan 16, 2026
7921f1b
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 16, 2026
7434de7
fixed free() stuff
khoulihan27 Jan 16, 2026
f5a3ac2
Co-authored-by: Ng0710 <Ng0710@users.noreply.github.com>
khoulihan27 Jan 16, 2026
bfa3f4a
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 16, 2026
8bef2c1
Spread volatility over the state data lump for things to do better
dchansen06 Jan 16, 2026
787876c
removed switch-case for if-else, fixed function order in main
khoulihan27 Jan 16, 2026
d5ccf94
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 16, 2026
f0d0633
Use `const volatile` for `ECU_StateData` pointers that you should not…
dchansen06 Jan 16, 2026
9187de1
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 16, 2026
10e55cc
fixed stateLump not being declared volatile
khoulihan27 Jan 16, 2026
d13be09
Cleanup `CANdler` error messages
dchansen06 Jan 20, 2026
c8dd1e9
Incorrect use of `uint16_t` casting when referring to an address spac…
dchansen06 Jan 20, 2026
76de0b8
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
82d43b5
Merge branch 'main' into StateMachineImplementation
dchansen06 Jan 20, 2026
dc6c6d5
Fix `NUM_SIGNALS_DIGITAL` to reflect there actually being 8
dchansen06 Jan 20, 2026
b8a5854
Cleanup mock ECU test to be reflective of current goals
dchansen06 Jan 20, 2026
825a146
Automatic CMake Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
eb37b91
this is a lot of changes small and big brace for merge
kzwicker Jan 20, 2026
6725a93
Merge branch 'StateMachineImplementation' of https://github.com/Gauch…
kzwicker Jan 20, 2026
da1b696
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
695ac63
Fix formatting in `settings.json`
dchansen06 Jan 20, 2026
b5c5626
Refactor CAN message handling and update voltage checks to use SAFE_V…
kzwicker Jan 20, 2026
6f6cf56
Merge branch 'StateMachineImplementation' of https://github.com/Gauch…
kzwicker Jan 20, 2026
0f6ded3
yucky errors
kzwicker Jan 20, 2026
a5d2607
someone still wrote
kzwicker Jan 20, 2026
a7f095d
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
2212e61
All warnings/errors are resolved at this point probably
dchansen06 Jan 20, 2026
e9f47c0
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
3d406da
Fix the HOOTL testing to be correctly dummied
dchansen06 Jan 20, 2026
f070ca8
Automatic CMake Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
79516f8
Another checkpoint where everything compiled
dchansen06 Jan 20, 2026
fb3bac1
Another compilation checkpoint I believe
dchansen06 Jan 20, 2026
f4b8606
Add early returns in ECU_GLV_On, ECU_Precharge_Start, and ECU_Prechar…
dchansen06 Jan 20, 2026
b441e4a
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
10ffeb3
Things seem to be working
dchansen06 Jan 20, 2026
d2db785
No warnings or errors maybe (who knows)
dchansen06 Jan 20, 2026
53fe870
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
b4eeb7e
Get ready for clock things
dchansen06 Jan 20, 2026
2a800ca
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
e3ec2d4
ADC should now work for ECU - tested
anthony9975 Jan 20, 2026
8bb665f
Half-implementation of DTI on CAN
dchansen06 Jan 20, 2026
a4d5180
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 20, 2026
b47c6fa
added brake light functionality; quick fix, check if correct
khoulihan27 Jan 23, 2026
e86897d
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 23, 2026
e587987
tssi lights; again, quick fix
khoulihan27 Jan 23, 2026
e612345
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 23, 2026
5a3172c
correct timer usage for ecu status message and TS discharge timer
SlowThomas Jan 23, 2026
f03db50
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 23, 2026
e8549b9
move pinout documentation to RelevantInfo.md
SlowThomas Jan 23, 2026
3703246
fixed analog measurements being digital
khoulihan27 Jan 23, 2026
921bb44
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 23, 2026
c8e0d4f
fixed analog measurements being digital
khoulihan27 Jan 23, 2026
c5fc283
Merge branch 'StateMachineImplementation' of https://github.com/Gauch…
khoulihan27 Jan 23, 2026
bb5e8d0
added relevant info for ADC2
khoulihan27 Jan 23, 2026
0e7cc7f
more relevant info + bms/imd error checking
khoulihan27 Jan 23, 2026
3f4115b
stateData light bools added
khoulihan27 Jan 23, 2026
9cf50da
added functions to check for BMS and IMD failure specifically
SlowThomas Jan 23, 2026
79d5b46
implement TSSI functionality; needs further checkings
SlowThomas Jan 23, 2026
f3188bc
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 23, 2026
4c4959c
Merge branch 'main' into StateMachineImplementation
dchansen06 Jan 23, 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
2 changes: 0 additions & 2 deletions CCU/Core/Inc/stm32g4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void FDCAN1_IT0_IRQHandler(void);
void FDCAN2_IT0_IRQHandler(void);
/* USER CODE BEGIN EFP */

/* USER CODE END EFP */
Expand Down
35 changes: 0 additions & 35 deletions CCU/Core/Src/stm32g4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,41 +187,6 @@ void SysTick_Handler(void)
/* USER CODE END SysTick_IRQn 1 */
}

/******************************************************************************/
/* STM32G4xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32g4xx.s). */
/******************************************************************************/

/**
* @brief This function handles FDCAN1 interrupt 0.
*/
void FDCAN1_IT0_IRQHandler(void)
{
/* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */

/* USER CODE END FDCAN1_IT0_IRQn 0 */
HAL_FDCAN_IRQHandler(&hfdcan1);
/* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */

/* USER CODE END FDCAN1_IT0_IRQn 1 */
}

/**
* @brief This function handles FDCAN2 interrupt 0.
*/
void FDCAN2_IT0_IRQHandler(void)
{
/* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */

/* USER CODE END FDCAN2_IT0_IRQn 0 */
HAL_FDCAN_IRQHandler(&hfdcan2);
/* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */

/* USER CODE END FDCAN2_IT0_IRQn 1 */
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
15 changes: 15 additions & 0 deletions ECU/Application/Inc/CANutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdint.h>

#include "GR_OLD_BUS_ID.h"
#include "GR_OLD_MSG_ID.h"
#include "GR_OLD_NODE_ID.h"
#include "StateData.h"

#ifndef CANUTILS_H
#define CANUTILS_H

#define ECU_STATE_DATA_SEND_INTERVAL_MS 250
void ECU_CAN_Send(GR_OLD_BUS_ID bus, GR_OLD_NODE_ID destNode, GR_OLD_MSG_ID messageID, void *data, uint32_t size);
void SendECUStateDataOverCAN(ECU_StateData *stateData);

#endif
91 changes: 76 additions & 15 deletions ECU/Application/Inc/StateData.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,93 @@
* @remark It is passed to each state function on tick to allow state-specific
* logic to access and modify the ECU's operational data.
*/
typedef struct ECU_StateData {
// DON'T TOUCH YET
GR_OLD_ECU_STATUS_1_MSG ecuStatus1;
GR_OLD_ECU_STATUS_2_MSG ecuStatus2;
GR_OLD_ECU_STATUS_3_MSG ecuStatus3;

#define SAFE_VOLTAGE_LIMIT 60
#define BUTTON_REFRESH_RATE_MS 100

typedef union {
struct {
uint8_t ECUState;
uint8_t StatusBits[3];
uint8_t PowerLevelTorqueMap;
uint8_t MaxCellTemp;
uint8_t AccumulatorStateOfCharge;
uint8_t GLVStateOfCharge;
uint16_t TractiveSystemVoltage;
uint16_t VehicleSpeed;
uint16_t FRWheelRPM;
uint16_t FLWheelRPM;
uint16_t RRWheelRPM;
uint16_t RLWheelRPM;
};

struct {
uint8_t ECUStatusMsgOne[8];
uint8_t ECUStatusMsgTwo[8];
uint8_t ECUStatusMsgThree[4];
};
} ECU_StateDataToSend;

typedef volatile struct ECU_StateData {

// TODO: Remove unneeded states

uint32_t millisSinceBoot;

int32_t dischargeStartMillis;
uint32_t lastECUStatusMsgTick;
uint32_t lastECUStatusMsgMillis;
uint32_t lastTSSIFlash;
int32_t last_drive_active_control_ms;

float min_amk_heat_cap_throttle_percent;
float ts_voltage;
float max_cell_temp; /** Temperature of hottest cell, celsius */

float vehicle_speed; /** Vehicle speed, MPH */
float fr_wheel_rpm; /** FR wheel, RPM */
float fl_wheel_rpm; /** FL wheel, RPM */
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;

float estop_sense;
uint16_t driving_heat_capacity_1;
uint16_t driving_heat_capacity_2;
uint16_t APPS1_Signal;
uint16_t APPS2_Signal;
uint16_t Brake_R_Signal;
uint16_t Brake_F_Signal;
uint8_t acu_error_warning_bits;
uint16_t STEERING_ANGLE_SIGNAL;
uint8_t status_bits[3];
int8_t ping_block[3]; /** Node timeout status bits (1=OK, 0=Timeout) */
uint8_t powerlevel_torquemap; /** Power lvl (4b) & torque map (4b) */
uint8_t tractivebattery_soc;
uint8_t glv_soc;
uint8_t bcu_error_warning_bits;
uint8_t inverter_fault_map;
bool bse_apps_violation;
bool ts_active_button_engaged;
bool rtd_button_engaged;
} ECU_StateData; // FIXME Add comments to each data field with descriptions and
// rules (eg -1 = invalid?, etc)
// Will also need to add information from ADC into this struct
// --- such as the APPS and Brake signals after doing smoothing
// and whatnot to get the values sane
bool ts_active;
bool rtd;
bool prev_ts_active_button_state;
bool prev_rtd_button_state;
uint32_t prev_ts_press_millis;
uint32_t prev_rtd_press_millis;
bool ir_plus;
bool ir_minus;
bool bcu_software_latch;

bool bms_light;
bool imd_light;
bool tssi_red;

uint32_t tssi_red_blinking_current_cycle_starting_millis;

GR_ECU_State ecu_state;
} ECU_StateData;

#endif
28 changes: 28 additions & 0 deletions ECU/Application/Inc/StateTicks.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include "StateData.h"
#include "StateMachine.h"
#include "adc.h"
#include "can.h"

#ifndef _STATE_TICKS_H_
#define _STATE_TICKS_H_

extern CANHandle *primary_can;
extern CANHandle *data_can;

/**
* @brief Tick function for the ECU state machine.
*
Expand Down Expand Up @@ -35,6 +40,17 @@ void ECU_GLV_Off(ECU_StateData *stateData);
*/
void ECU_GLV_On(ECU_StateData *stateData);

/**
* @brief Handles the transition from GLV On to Precharge Engaged state.
*
* Initiates the precharge process by switching to the Precharge Engaged state.
*
* @param stateData Pointer to the ECU state data structure.
*
* @return void
*/
void ECU_Precharge_Start(ECU_StateData *stateData);

/**
* @brief State handler for the Precharge Engaged state.
*
Expand Down Expand Up @@ -68,6 +84,18 @@ void ECU_Precharge_Complete(ECU_StateData *stateData);
*/
void ECU_Drive_Active(ECU_StateData *stateData);

/**
* @brief Init function for ECU_Tractive_System_Discharge_Start.
*
* Resets Tractive System discharge timer and switches on the Tractive System
* Discharge state.
*
* @param stateData Pointer to the ECU state data structure.
*
* @return void
*/
void ECU_Tractive_System_Discharge_Start(ECU_StateData *stateData);

/**
* @brief State handler for the Tractive System Discharge state.
*
Expand Down
24 changes: 18 additions & 6 deletions ECU/Application/Inc/StateUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#ifndef _STATE_UTILS_H_
#define _STATE_UTILS_H_

/// @brief Get the current time in milliseconds since system start
/// @return Current time in milliseconds
uint32_t MillisecondsSinceBoot(void);

// Constants
#define BRAKE_F_MIN 0 // TODO: need to be determined FIXME: Rename better
#define BRAKE_F_MAX 4095 // TODO: need to be determined FIXME: Rename better
Expand All @@ -19,12 +23,20 @@
#define APPS_PROPORTION 2.0f // TODO: Need to be experimentally determined
#define APPS_OFFSET 250.0f // TODO: Need to be experimentally determined

#define MAX_CURRENT_AMPS 42.0f // TODO: Change as appropriate
#define MAX_REVERSE_CURRENT_AMPS 20.0f // TODO: Change as appropriate

void setSoftwareLatch(bool close);

// Checks stateData for critical errors
bool CriticalError(const ECU_StateData *stateData);
bool CommunicationError(const ECU_StateData *stateData);
bool APPS_BSE_Violation(const ECU_StateData *stateData);
bool PressingBrake(const ECU_StateData *stateData);
float CalcBrakePercent(const ECU_StateData *stateData);
float CalcPedalTravel(const ECU_StateData *stateData);
bool CriticalError(volatile const ECU_StateData *stateData);
bool bmsFailure(volatile const ECU_StateData *stateData);
bool imdFailure(volatile const ECU_StateData *stateData);
bool CommunicationError(volatile const ECU_StateData *stateData);
bool APPS_BSE_Violation(volatile const ECU_StateData *stateData);
bool PressingBrake(volatile const ECU_StateData *stateData);
float CalcBrakePercent(volatile const ECU_StateData *stateData);
float CalcPedalTravel(volatile const ECU_StateData *stateData);
bool vehicle_is_moving(volatile const ECU_StateData *stateData);

#endif
40 changes: 21 additions & 19 deletions ECU/Application/Src/CANdler.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "GR_OLD_NODE_ID.h"
#include "Logomatic.h"
#include "StateData.h"
#include "bitManipulations.h"

extern ECU_StateData stateLump;

void ReportBadMessageLength(GR_OLD_BUS_ID bus_id, GR_OLD_MSG_ID msg_id, GR_OLD_NODE_ID sender_id)
{
Expand All @@ -31,47 +34,55 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GR_OLD_BUS_ID bus_id, GR_
}
LOGOMATIC("Received from %02X on bus %d: %.*s\n", sender_id, bus_id, (int)data_length, data);
break;

case MSG_DEBUG_FD:
if (data_length > sizeof(GR_OLD_DEBUG_2_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
LOGOMATIC("Received from %02X on bus %d: %.*s\n", sender_id, bus_id, (int)data_length, data);
break;

case MSG_PING:
if (data_length != sizeof(GR_OLD_PING_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
// TODO See Issue #143
break;
case MSG_ACU_STATUS_1:

case MSG_BCU_STATUS_1:
if (data_length != sizeof(GR_OLD_BCU_STATUS_1_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GR_OLD_BCU_STATUS_1_MSG *bcu_status_1 = (GR_OLD_BCU_STATUS_1_MSG *)data;
state_data->ecuStatus1.tractivebattery_soc = bcu_status_1->tractivebattery_soc;
state_data->ecuStatus1.glv_soc = bcu_status_1->glv_soc;
state_data->ecuStatus2.ts_voltage = bcu_status_1->ts_voltage;
state_data->tractivebattery_soc = bcu_status_1->tractivebattery_soc * 0.01;
state_data->glv_soc = bcu_status_1->glv_soc * 20 / 51;
state_data->ts_voltage = bcu_status_1->ts_voltage * 0.01;
break;
case MSG_ACU_STATUS_2:

case MSG_BCU_STATUS_2:
if (data_length != sizeof(GR_OLD_BCU_STATUS_2_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GR_OLD_BCU_STATUS_2_MSG *bcu_status_2 = (GR_OLD_BCU_STATUS_2_MSG *)data;
state_data->ecuStatus1.max_cell_temp = bcu_status_2->max_cell_temp;
state_data->acu_error_warning_bits = bcu_status_2->error_bits;
state_data->max_cell_temp = bcu_status_2->max_cell_temp * 0.25;
state_data->bcu_error_warning_bits = bcu_status_2->error_bits;
state_data->ir_minus = GETBIT(bcu_status_2->precharge_bits, 1);
state_data->ir_plus = GETBIT(bcu_status_2->precharge_bits, 2);
state_data->bcu_software_latch = GETBIT(bcu_status_2->precharge_bits, 3);
break;

case MSG_INVERTER_STATUS_1:
if (data_length != sizeof(GR_OLD_INVERTER_STATUS_1_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GR_OLD_INVERTER_STATUS_1_MSG *inverter_status_1 = (GR_OLD_INVERTER_STATUS_1_MSG *)data;
state_data->ecuStatus3.rl_wheel_rpm = inverter_status_1->motor_rpm;
state_data->ecuStatus3.rr_wheel_rpm = inverter_status_1->motor_rpm;
state_data->rl_wheel_rpm = inverter_status_1->motor_rpm - 32768;
state_data->rr_wheel_rpm = inverter_status_1->motor_rpm - 32768;
break;
case MSG_INVERTER_STATUS_3:
if (data_length != sizeof(GR_OLD_INVERTER_STATUS_3_MSG)) {
Expand All @@ -81,22 +92,13 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GR_OLD_BUS_ID bus_id, GR_
GR_OLD_INVERTER_STATUS_3_MSG *inverter_status_3 = (GR_OLD_INVERTER_STATUS_3_MSG *)data;
state_data->inverter_fault_map = inverter_status_3->fault_bits;
break;
case MSG_DASH_STATUS:
if (data_length != sizeof(GR_OLD_DASH_STATUS_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GR_OLD_DASH_STATUS_MSG *dash_status = (GR_OLD_DASH_STATUS_MSG *)data;
state_data->ts_active_button_engaged = dash_status->ts_button;
state_data->rtd_button_engaged = dash_status->rtd_button;
break;
case MSG_STEERING_STATUS:
if (data_length != sizeof(GR_OLD_STEERING_STATUS_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GR_OLD_STEERING_STATUS_MSG *steering_status = (GR_OLD_STEERING_STATUS_MSG *)data;
state_data->ecuStatus1.powerlevel_torquemap = steering_status->encoder_bits;
state_data->powerlevel_torquemap = steering_status->encoder_bits;
break;
default:
ReportUnhandledMessage(bus_id, msg_id, sender_id);
Expand Down
Loading
Loading