Compare commits
2 Commits
0e2de588bf
...
0d03fee529
Author | SHA1 | Date | |
---|---|---|---|
0d03fee529 | |||
76e3e60f7a |
32
AMS_Master_Code/.vscode/launch.json
vendored
32
AMS_Master_Code/.vscode/launch.json
vendored
@ -23,7 +23,19 @@
|
||||
"port": 0,
|
||||
"type": "console",
|
||||
"label": "SWO LOG",
|
||||
"encoding": "ascii"
|
||||
"encoding": "utf8"
|
||||
},
|
||||
{
|
||||
"port": 1,
|
||||
"type": "console",
|
||||
"label": "Master Status",
|
||||
"encoding": "utf8"
|
||||
},
|
||||
{
|
||||
"port": 2,
|
||||
"type": "console",
|
||||
"label": "Module Status",
|
||||
"encoding": "utf8"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -54,7 +66,19 @@
|
||||
"port": 0,
|
||||
"type": "console",
|
||||
"label": "SWO LOG",
|
||||
"encoding": "ascii"
|
||||
"encoding": "utf8"
|
||||
},
|
||||
{
|
||||
"port": 1,
|
||||
"type": "console",
|
||||
"label": "Master Status",
|
||||
"encoding": "utf8"
|
||||
},
|
||||
{
|
||||
"port": 2,
|
||||
"type": "console",
|
||||
"label": "Module Status",
|
||||
"encoding": "utf8"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -66,8 +90,8 @@
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/lene/fasttube/FT25/03_ams/ams-master/AMS_Master_Code/Core/Src",
|
||||
"program": "c:/lene/fasttube/FT25/03_ams/ams-master/AMS_Master_Code/Core/Src/build/Debug/outDebug",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"program": "${workspaceFolder}/build/debug/AMS_Master_Nucleo.elf",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
|
@ -7,11 +7,18 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
extern uint16_t min_voltage;
|
||||
extern uint16_t max_voltage;
|
||||
extern struct {uint16_t min; uint16_t max;} module_voltages[N_BMS];
|
||||
extern int16_t max_temp;
|
||||
extern int16_t min_temp;
|
||||
extern struct {int16_t min; int16_t max;} module_temps[N_BMS];
|
||||
|
||||
extern int16_t cellTemps[N_BMS][N_CELLS];
|
||||
|
||||
HAL_StatusTypeDef battery_init(SPI_HandleTypeDef* hspi);
|
||||
HAL_StatusTypeDef battery_update();
|
||||
|
||||
void print_battery_info();
|
||||
void print_master_status();
|
||||
|
||||
#endif // __BATTERY_H
|
@ -16,6 +16,29 @@ typedef enum {
|
||||
IMD_STATE_GND_FAULT,
|
||||
} IMDState;
|
||||
|
||||
static inline const char *IMDStateToString(IMDState state) {
|
||||
switch (state) {
|
||||
case IMD_STATE_UNKNOWN:
|
||||
return "UNKNOWN";
|
||||
case IMD_STATE_SHORTCIRCUIT_SUPPLY:
|
||||
return "SHORTCIRCUIT_SUPPLY";
|
||||
case IMD_STATE_SHORTCIRCUIT_GND:
|
||||
return "SHORTCIRCUIT_GND";
|
||||
case IMD_STATE_NORMAL:
|
||||
return "NORMAL";
|
||||
case IMD_STATE_UNDERVOLTAGE:
|
||||
return "UNDERVOLTAGE";
|
||||
case IMD_STATE_SST:
|
||||
return "SST";
|
||||
case IMD_STATE_DEV_ERROR:
|
||||
return "DEV_ERROR";
|
||||
case IMD_STATE_GND_FAULT:
|
||||
return "GND_FAULT";
|
||||
default:
|
||||
return "INVALID STATE";
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int ok;
|
||||
|
||||
|
@ -48,7 +48,7 @@ extern int hv_active;
|
||||
extern int neg_air_closed;
|
||||
extern int pos_air_closed;
|
||||
extern int precharge_closed;
|
||||
extern int precharge_opened;
|
||||
extern int pre_and_air_open;
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void set_error_led();
|
||||
void print_status();
|
||||
|
||||
#endif // INC_UTIL_H
|
@ -30,6 +30,27 @@ typedef enum {
|
||||
TS_CHARGING
|
||||
} TSState;
|
||||
|
||||
static inline const char *TSStateToString(TSState state) {
|
||||
switch (state) {
|
||||
case TS_INACTIVE:
|
||||
return "INACTIVE";
|
||||
case TS_ACTIVE:
|
||||
return "ACTIVE";
|
||||
case TS_PRECHARGE:
|
||||
return "PRECHARGE";
|
||||
case TS_DISCHARGE:
|
||||
return "DISCHARGE";
|
||||
case TS_ERROR:
|
||||
return "ERROR";
|
||||
case TS_CHARGING_CHECK:
|
||||
return "CHARGING_CHECK";
|
||||
case TS_CHARGING:
|
||||
return "CHARGING";
|
||||
default:
|
||||
return "INVALID STATE";
|
||||
}
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
TS_ERRORKIND_NONE = 0x00,
|
||||
TS_ERRORKIND_SLAVE_TIMEOUT = 0x01,
|
||||
|
@ -6,9 +6,14 @@
|
||||
|
||||
#define SWO_LOG_PREFIX "[BATTERY] "
|
||||
#include "swo_log.h"
|
||||
|
||||
|
||||
uint16_t min_voltage = 0xFFFF;
|
||||
int16_t max_temp = -1;
|
||||
uint16_t max_voltage = 0;
|
||||
typeof(module_voltages) module_voltages = {[0 ... N_BMS - 1] = {0xFFFF, 0}};
|
||||
int16_t min_temp = INT16_MAX;
|
||||
int16_t max_temp = INT16_MIN;
|
||||
typeof(module_temps) module_temps = {[0 ... N_BMS - 1] = {INT16_MAX, INT16_MIN}};
|
||||
|
||||
int16_t cellTemps[N_BMS][N_CELLS];
|
||||
|
||||
HAL_StatusTypeDef battery_init(SPI_HandleTypeDef *hspi) {
|
||||
@ -37,153 +42,44 @@ HAL_StatusTypeDef battery_update() {
|
||||
}
|
||||
|
||||
min_voltage = 0xFFFF;
|
||||
max_temp = -1;
|
||||
max_voltage = 0;
|
||||
min_temp = INT16_MAX;
|
||||
max_temp = INT16_MIN;
|
||||
|
||||
for (size_t i = 0; i < N_BMS; i++) {
|
||||
for (size_t j = 0; j < N_CELLS; j++) {
|
||||
if (modules[i].cellVoltages[j] > min_voltage) {
|
||||
min_voltage = modules[i].cellVoltages[j];
|
||||
}
|
||||
if (modules[i].cellVoltages[j] < max_voltage) {
|
||||
max_voltage = modules[i].cellVoltages[j];
|
||||
}
|
||||
if (modules[i].cellVoltages[j] > module_voltages[i].max) {
|
||||
module_voltages[i].max = modules[i].cellVoltages[j];
|
||||
}
|
||||
if (modules[i].cellVoltages[j] < module_voltages[i].min) {
|
||||
module_voltages[i].min = modules[i].cellVoltages[j];
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < 10; j++) { //10 GPIOs
|
||||
cellTemps[i][j] = ntc_mv_to_celsius(modules[i].auxVoltages[j]);
|
||||
|
||||
if (cellTemps[i][j] > max_temp) {
|
||||
max_temp = cellTemps[i][j];
|
||||
}
|
||||
if (cellTemps[i][j] < min_temp) {
|
||||
min_temp = cellTemps[i][j];
|
||||
}
|
||||
|
||||
if (cellTemps[i][j] > module_temps[i].max) {
|
||||
module_temps[i].max = cellTemps[i][j];
|
||||
}
|
||||
if (cellTemps[i][j] < module_temps[i].min) {
|
||||
module_temps[i].min = cellTemps[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
void print_battery_info() {
|
||||
for (size_t i = 0; i < N_BMS; i++) {
|
||||
debug_log(LOG_LEVEL_INFO, "Module %d status:", i);
|
||||
|
||||
// Print cell voltages in 4x4 format
|
||||
debug_log(LOG_LEVEL_INFO, " Cell voltages (mV):");
|
||||
debug_log(LOG_LEVEL_INFO, " C0: %4d C1: %4d C2: %4d C3: %4d",
|
||||
modules[i].cellVoltages[0], modules[i].cellVoltages[1],
|
||||
modules[i].cellVoltages[2], modules[i].cellVoltages[3]);
|
||||
debug_log(LOG_LEVEL_INFO, " C4: %4d C5: %4d C6: %4d C7: %4d",
|
||||
modules[i].cellVoltages[4], modules[i].cellVoltages[5],
|
||||
modules[i].cellVoltages[6], modules[i].cellVoltages[7]);
|
||||
debug_log(LOG_LEVEL_INFO, " C8: %4d C9: %4d C10: %4d C11: %4d",
|
||||
modules[i].cellVoltages[8], modules[i].cellVoltages[9],
|
||||
modules[i].cellVoltages[10], modules[i].cellVoltages[11]);
|
||||
debug_log(LOG_LEVEL_INFO, " C12: %4d C13: %4d C14: %4d C15: %4d",
|
||||
modules[i].cellVoltages[12], modules[i].cellVoltages[13],
|
||||
modules[i].cellVoltages[14], modules[i].cellVoltages[15]);
|
||||
|
||||
// Print GPIO values
|
||||
debug_log(LOG_LEVEL_INFO, " GPIO voltages (mV):");
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" G0: %4d G1: %4d G2: %4d G3: %4d G4: %4d",
|
||||
modules[i].auxVoltages[0], modules[i].auxVoltages[1],
|
||||
modules[i].auxVoltages[2], modules[i].auxVoltages[3],
|
||||
modules[i].auxVoltages[4]);
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" G5: %4d G6: %4d G7: %4d G8: %4d G9: %4d",
|
||||
modules[i].auxVoltages[5], modules[i].auxVoltages[6],
|
||||
modules[i].auxVoltages[7], modules[i].auxVoltages[8],
|
||||
modules[i].auxVoltages[9]);
|
||||
|
||||
// Print temperatures
|
||||
debug_log(LOG_LEVEL_INFO, " GPIO as temperatures (°C):");
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" G0: %4d G1: %4d G2: %4d G3: %4d G4: %4d",
|
||||
cellTemps[i][0], cellTemps[i][1], cellTemps[i][2],
|
||||
cellTemps[i][3], cellTemps[i][4]);
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" G5: %4d G6: %4d G7: %4d G8: %4d G9: %4d",
|
||||
cellTemps[i][5], cellTemps[i][6], cellTemps[i][7],
|
||||
cellTemps[i][8], cellTemps[i][9]);
|
||||
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" Internal temp: %d, VAnalog: %d, VDigital: %d, VRef: %d",
|
||||
modules[i].internalDieTemp, modules[i].analogSupplyVoltage,
|
||||
modules[i].digitalSupplyVoltage, modules[i].refVoltage);
|
||||
|
||||
// Print error flags if any are set
|
||||
bool hasFlags = false;
|
||||
char flagBuffer[128] = "";
|
||||
char *bufPos = flagBuffer;
|
||||
|
||||
if (modules[i].status.CS_FLT) {
|
||||
bufPos = stpcpy(bufPos, "CS_FLT ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.SMED) {
|
||||
bufPos = stpcpy(bufPos, "SMED ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.SED) {
|
||||
bufPos = stpcpy(bufPos, "SED ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.CMED) {
|
||||
bufPos = stpcpy(bufPos, "CMED ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.CED) {
|
||||
bufPos = stpcpy(bufPos, "CED ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VD_UV) {
|
||||
bufPos = stpcpy(bufPos, "VD_UV ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VD_OV) {
|
||||
bufPos = stpcpy(bufPos, "VD_OV ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VA_UV) {
|
||||
bufPos = stpcpy(bufPos, "VA_UV ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VA_OV) {
|
||||
bufPos = stpcpy(bufPos, "VA_OV ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.THSD) {
|
||||
bufPos = stpcpy(bufPos, "THSD ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.SLEEP) {
|
||||
bufPos = stpcpy(bufPos, "SLEEP ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.SPIFLT) {
|
||||
bufPos = stpcpy(bufPos, "SPIFLT ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.COMPARE) {
|
||||
bufPos = stpcpy(bufPos, "COMPARE ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VDE) {
|
||||
bufPos = stpcpy(bufPos, "VDE ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VDEL) {
|
||||
bufPos = stpcpy(bufPos, "VDEL ");
|
||||
hasFlags = true;
|
||||
}
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, " Status flags: %s",
|
||||
hasFlags ? flagBuffer : "[none]");
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, " Conversion counter: %d",
|
||||
modules[i].status.CCTS);
|
||||
|
||||
// Check for over/under voltage
|
||||
if (modules[i].overVoltage || modules[i].underVoltage) {
|
||||
debug_log(LOG_LEVEL_WARNING,
|
||||
" Module %d voltage issues - OV: 0x%08lX, UV: 0x%08lX", i,
|
||||
modules[i].overVoltage, modules[i].underVoltage);
|
||||
}
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, " ---------------");
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ HAL_StatusTypeDef can_send_status() {
|
||||
}
|
||||
data[0] = (sdc_closed_nodelay << 0) | (ts_error << 1) | (hv_active << 2) |
|
||||
(neg_air_closed << 3) | (pos_air_closed << 4) |
|
||||
(precharge_closed << 5) | (precharge_opened << 6);
|
||||
(precharge_closed << 5) | (pre_and_air_open << 6);
|
||||
return ftcan_transmit(CAN_ID_AMS_SIGNALS, data, 1);
|
||||
}
|
||||
|
||||
|
@ -73,9 +73,6 @@ int pos_air_closed;
|
||||
int precharge_closed;
|
||||
int pre_and_air_open; // used to be:int precharge_opened = 0; now we read if PC is open from the pin -> high if open
|
||||
|
||||
#warning just a fix to make the code compile
|
||||
int precharge_opened = 0;
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@ -222,7 +219,7 @@ int main(void)
|
||||
}
|
||||
if (count % 4 == 0) {
|
||||
print_battery_info();
|
||||
debug_log(LOG_LEVEL_INFO, " Time since last update: %lu ms", HAL_GetTick() - lastTimestamp);
|
||||
print_master_status();
|
||||
}
|
||||
shunt_check();
|
||||
ts_sm_update();
|
||||
|
74
AMS_Master_Code/Core/Src/print_master_status.c
Normal file
74
AMS_Master_Code/Core/Src/print_master_status.c
Normal file
@ -0,0 +1,74 @@
|
||||
#include "print_master_status.h"
|
||||
#include "imd_monitoring.h"
|
||||
#include "main.h"
|
||||
#include "soc_estimation.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
#include "shunt_monitoring.h"
|
||||
#include "ts_state_machine.h"
|
||||
#include "battery.h"
|
||||
|
||||
#define DEBUG_CHANNEL 1 // channel to output messages on
|
||||
#include "swo_log.h"
|
||||
|
||||
void print_status() {
|
||||
debug_clear_console();
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, "------ AMS_Master on %s (%s), compiled at %s ------", COMMIT_BRANCH,
|
||||
COMMIT_HASH, COMPILE_DATE);
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, "\nGeneral:");
|
||||
debug_log(LOG_LEVEL_INFO, " State: %s", TSStateToString(ts_state.current_state));
|
||||
debug_log(LOG_LEVEL_INFO, " Target: %s", TSStateToString(ts_state.target_state));
|
||||
debug_log(LOG_LEVEL_INFO, " Err Source: %s", ts_state.error_source == 0 ? "NONE" : (ts_state.error_source == 0b11 ? "SHUNT, SLAVE" : (ts_state.error_source == 0b01 ? "SHUNT" : "SLAVE")));
|
||||
debug_log(LOG_LEVEL_INFO, " Err type: %s", ts_state.error_type == 0 ? "NONE" : (ts_state.error_type == 0x01 ? "SLAVE_TIMEOUT" : (ts_state.error_type == 0x02 ? "SLAVE_PANIC" : (ts_state.error_type == 0x03 ? "SHUNT_TIMEOUT" : (ts_state.error_type == 0x04 ? "SHUNT_OVERCURRENT" : (ts_state.error_type == 0x05 ? "SHUNT_OVERTEMP" : "UNKNOWN"))))));
|
||||
debug_log(LOG_LEVEL_INFO, " HV active: %s", hv_active ? "YES" : "NO");
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, "\nRelay positions:");
|
||||
debug_log(LOG_LEVEL_INFO, " SDC: %s", sdc_closed ? "CLOSED" : "OPEN");
|
||||
debug_log(LOG_LEVEL_INFO, " Air-: %s", neg_air_closed ? "CLOSED" : "OPEN");
|
||||
debug_log(LOG_LEVEL_INFO, " Air+: %s", pos_air_closed ? "CLOSED" : "OPEN");
|
||||
debug_log(LOG_LEVEL_INFO, " Precharge: %s", precharge_closed ? "CLOSED" : "OPEN");
|
||||
debug_log(LOG_LEVEL_INFO, " Precharge/Air+ sense: %s", pre_and_air_open ? "HIGH" : "LOW");
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, "\nIMD data:");
|
||||
debug_log(LOG_LEVEL_INFO, " State: %s", IMDStateToString(imd_data.state));
|
||||
debug_log(LOG_LEVEL_INFO, " R_iso: %lu kOhm", imd_data.r_iso);
|
||||
debug_log(LOG_LEVEL_INFO, " Frequency: %lu Hz", imd_data.freq);
|
||||
debug_log(LOG_LEVEL_INFO, " Duty cycle: %lu %%", imd_data.duty_cycle);
|
||||
debug_log(LOG_LEVEL_INFO, " Last high: %lu ms", imd_data.last_high);
|
||||
debug_log(LOG_LEVEL_INFO, " OK: %s", imd_data.ok ? "YES" : "NO");
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, "\nShunt data:");
|
||||
debug_log(LOG_LEVEL_INFO, " Voltage: %ld mV", shunt_data.voltage_bat);
|
||||
debug_log(LOG_LEVEL_INFO, " Current: %ld mA", shunt_data.current);
|
||||
debug_log(LOG_LEVEL_INFO, " Power: %ld W", shunt_data.power);
|
||||
debug_log(LOG_LEVEL_INFO, " Energy: %ld Ws", shunt_data.energy);
|
||||
debug_log(LOG_LEVEL_INFO, " Temp: %ld °C", shunt_data.busbartemp / 10);
|
||||
debug_log(LOG_LEVEL_INFO, " Time delta: %lu ms", HAL_GetTick() - shunt_data.last_message);
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, "\nBattery data:");
|
||||
debug_log(LOG_LEVEL_INFO, " Min/Max voltage: %d mV / %d mV", min_voltage, max_voltage);
|
||||
debug_log(LOG_LEVEL_INFO, " Min/Max temp: %d °C / %d °C", min_temp, max_temp);
|
||||
debug_log(LOG_LEVEL_INFO, " SoC: %.2f %%", current_soc);
|
||||
debug_log(LOG_LEVEL_INFO, " Module data: Min V | Max V | Min T | Max T");
|
||||
for (size_t i = 0; i < N_BMS; i++) {
|
||||
#if USE_ANSI_ESCAPE_CODES
|
||||
#define COLOR_MIN "\033[34m" // Blue for min
|
||||
#define COLOR_MAX "\033[31m" // Red for max
|
||||
#define COLOR_RESET "\033[0m"
|
||||
debug_log(LOG_LEVEL_INFO, " %2zu: %s%5d mV%s | %s%5d mV%s | %s%3d °C%s | %s%3d °C%s", i,
|
||||
(module_voltages[i].min == min_voltage) ? COLOR_MIN : "", (module_voltages[i].min), COLOR_RESET,
|
||||
(module_voltages[i].max == max_voltage) ? COLOR_MAX : "", (module_voltages[i].max), COLOR_RESET,
|
||||
(module_temps[i].min == min_temp) ? COLOR_MIN : "", (module_temps[i].min), COLOR_RESET,
|
||||
(module_temps[i].max == max_temp) ? COLOR_MAX : "", (module_temps[i].max), COLOR_RESET);
|
||||
#else
|
||||
debug_log(LOG_LEVEL_INFO, " %2zu: %5d mV | %5d mV | %3d °C | %3d °C", i,
|
||||
module_voltages[i].min, module_voltages[i].max,
|
||||
module_temps[i].min, module_temps[i].max);
|
||||
#endif
|
||||
}
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, "\n------ Updated at %lu ------", HAL_GetTick());
|
||||
}
|
||||
|
143
AMS_Master_Code/Core/Src/print_module_status.c
Normal file
143
AMS_Master_Code/Core/Src/print_module_status.c
Normal file
@ -0,0 +1,143 @@
|
||||
#include "battery.h"
|
||||
#include "ADBMS_Driver.h"
|
||||
#include "NTC.h"
|
||||
#include "config_ADBMS6830.h"
|
||||
#include <string.h>
|
||||
|
||||
#define DEBUG_CHANNEL 2 // channel to output messages on
|
||||
#include "swo_log.h"
|
||||
|
||||
void print_battery_info() {
|
||||
debug_clear_console();
|
||||
debug_log(LOG_LEVEL_INFO, "------ AMS_Master on %s (%s), compiled at %s ------\n", COMMIT_BRANCH,
|
||||
COMMIT_HASH, COMPILE_DATE);
|
||||
|
||||
for (size_t i = 0; i < N_BMS; i++) {
|
||||
debug_log(LOG_LEVEL_INFO, "Module %d status:", i);
|
||||
|
||||
// Print cell voltages in 4x4 format
|
||||
debug_log(LOG_LEVEL_INFO, " Cell voltages (mV):");
|
||||
debug_log(LOG_LEVEL_INFO, " C0: %4d C1: %4d C2: %4d C3: %4d",
|
||||
modules[i].cellVoltages[0], modules[i].cellVoltages[1],
|
||||
modules[i].cellVoltages[2], modules[i].cellVoltages[3]);
|
||||
debug_log(LOG_LEVEL_INFO, " C4: %4d C5: %4d C6: %4d C7: %4d",
|
||||
modules[i].cellVoltages[4], modules[i].cellVoltages[5],
|
||||
modules[i].cellVoltages[6], modules[i].cellVoltages[7]);
|
||||
debug_log(LOG_LEVEL_INFO, " C8: %4d C9: %4d C10: %4d C11: %4d",
|
||||
modules[i].cellVoltages[8], modules[i].cellVoltages[9],
|
||||
modules[i].cellVoltages[10], modules[i].cellVoltages[11]);
|
||||
debug_log(LOG_LEVEL_INFO, " C12: %4d C13: %4d C14: %4d C15: %4d",
|
||||
modules[i].cellVoltages[12], modules[i].cellVoltages[13],
|
||||
modules[i].cellVoltages[14], modules[i].cellVoltages[15]);
|
||||
|
||||
// Print GPIO values
|
||||
debug_log(LOG_LEVEL_INFO, " GPIO voltages (mV):");
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" G0: %4d G1: %4d G2: %4d G3: %4d G4: %4d",
|
||||
modules[i].auxVoltages[0], modules[i].auxVoltages[1],
|
||||
modules[i].auxVoltages[2], modules[i].auxVoltages[3],
|
||||
modules[i].auxVoltages[4]);
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" G5: %4d G6: %4d G7: %4d G8: %4d G9: %4d",
|
||||
modules[i].auxVoltages[5], modules[i].auxVoltages[6],
|
||||
modules[i].auxVoltages[7], modules[i].auxVoltages[8],
|
||||
modules[i].auxVoltages[9]);
|
||||
|
||||
// Print temperatures
|
||||
debug_log(LOG_LEVEL_INFO, " GPIO as temperatures (°C):");
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" G0: %4d G1: %4d G2: %4d G3: %4d G4: %4d",
|
||||
cellTemps[i][0], cellTemps[i][1], cellTemps[i][2],
|
||||
cellTemps[i][3], cellTemps[i][4]);
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" G5: %4d G6: %4d G7: %4d G8: %4d G9: %4d",
|
||||
cellTemps[i][5], cellTemps[i][6], cellTemps[i][7],
|
||||
cellTemps[i][8], cellTemps[i][9]);
|
||||
|
||||
debug_log(LOG_LEVEL_INFO,
|
||||
" Internal temp: %d, VAnalog: %d, VDigital: %d, VRef: %d",
|
||||
modules[i].internalDieTemp, modules[i].analogSupplyVoltage,
|
||||
modules[i].digitalSupplyVoltage, modules[i].refVoltage);
|
||||
|
||||
// Print error flags if any are set
|
||||
bool hasFlags = false;
|
||||
char flagBuffer[128] = "";
|
||||
char *bufPos = flagBuffer;
|
||||
|
||||
if (modules[i].status.CS_FLT) {
|
||||
bufPos = stpcpy(bufPos, "CS_FLT ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.SMED) {
|
||||
bufPos = stpcpy(bufPos, "SMED ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.SED) {
|
||||
bufPos = stpcpy(bufPos, "SED ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.CMED) {
|
||||
bufPos = stpcpy(bufPos, "CMED ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.CED) {
|
||||
bufPos = stpcpy(bufPos, "CED ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VD_UV) {
|
||||
bufPos = stpcpy(bufPos, "VD_UV ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VD_OV) {
|
||||
bufPos = stpcpy(bufPos, "VD_OV ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VA_UV) {
|
||||
bufPos = stpcpy(bufPos, "VA_UV ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VA_OV) {
|
||||
bufPos = stpcpy(bufPos, "VA_OV ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.THSD) {
|
||||
bufPos = stpcpy(bufPos, "THSD ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.SLEEP) {
|
||||
bufPos = stpcpy(bufPos, "SLEEP ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.SPIFLT) {
|
||||
bufPos = stpcpy(bufPos, "SPIFLT ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.COMPARE) {
|
||||
bufPos = stpcpy(bufPos, "COMPARE ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VDE) {
|
||||
bufPos = stpcpy(bufPos, "VDE ");
|
||||
hasFlags = true;
|
||||
}
|
||||
if (modules[i].status.VDEL) {
|
||||
bufPos = stpcpy(bufPos, "VDEL ");
|
||||
hasFlags = true;
|
||||
}
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, " Status flags: %s",
|
||||
hasFlags ? flagBuffer : "[none]");
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, " Conversion counter: %d",
|
||||
modules[i].status.CCTS);
|
||||
|
||||
// Check for over/under voltage
|
||||
if (modules[i].overVoltage || modules[i].underVoltage) {
|
||||
debug_log(LOG_LEVEL_WARNING,
|
||||
" Module %d voltage issues - OV: 0x%08lX, UV: 0x%08lX", i,
|
||||
modules[i].overVoltage, modules[i].underVoltage);
|
||||
}
|
||||
|
||||
debug_log(LOG_LEVEL_INFO, "\n------ Updated at %lu ------", HAL_GetTick());
|
||||
}
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
|
||||
#include "can.h"
|
||||
#include "ts_state_machine.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "can-halal.h"
|
||||
|
||||
ShuntData shunt_data;
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define SWO_LOG_PREFIX "[TS SM] "
|
||||
#include "swo_log.h"
|
||||
|
||||
TSStateHandle ts_state;
|
||||
|
||||
static uint32_t precharge_95_reached_timestamp = 0;
|
||||
@ -24,6 +27,8 @@ void ts_sm_update() {
|
||||
ts_state.current_state = TS_ERROR;
|
||||
}
|
||||
|
||||
auto old_state = ts_state.current_state;
|
||||
|
||||
switch (ts_state.current_state) {
|
||||
case TS_INACTIVE:
|
||||
ts_state.current_state = ts_sm_update_inactive();
|
||||
@ -48,6 +53,12 @@ void ts_sm_update() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ts_state.current_state != old_state) {
|
||||
debug_log(LOG_LEVEL_DEBUG,
|
||||
"Transitioned from %s to %s", TSStateToString(old_state),
|
||||
TSStateToString(ts_state.current_state));
|
||||
}
|
||||
|
||||
ts_sm_set_relay_positions(ts_state.current_state);
|
||||
status_led_state(ts_state.current_state, (TSErrorKind)ts_state.error_type);
|
||||
}
|
||||
@ -82,7 +93,7 @@ TSState ts_sm_update_active() {
|
||||
precharge_opened_timestamp = HAL_GetTick();
|
||||
} else if (precharge_opened_timestamp != 0 &&
|
||||
HAL_GetTick() - precharge_opened_timestamp > 100) {
|
||||
precharge_opened = 1;
|
||||
//precharge_opened = 1;
|
||||
}
|
||||
|
||||
return TS_ACTIVE;
|
||||
@ -102,7 +113,7 @@ TSState ts_sm_update_precharge() {
|
||||
PRECHARGE_95_DURATION) {
|
||||
precharge_95_reached_timestamp = 0;
|
||||
precharge_opened_timestamp = 0;
|
||||
precharge_opened = 0;
|
||||
//precharge_opened = 0;
|
||||
return TS_ACTIVE;
|
||||
}
|
||||
}
|
||||
@ -177,7 +188,7 @@ void ts_sm_set_relay_positions(TSState state) {
|
||||
case TS_CHARGING:
|
||||
ts_sm_set_relay_position(RELAY_NEG, 1);
|
||||
ts_sm_set_relay_position(RELAY_POS, 1);
|
||||
ts_sm_set_relay_position(RELAY_PRECHARGE, !precharge_opened);
|
||||
ts_sm_set_relay_position(RELAY_PRECHARGE, 0);
|
||||
// TODO: Open precharge relay after a while
|
||||
break;
|
||||
case TS_PRECHARGE:
|
||||
@ -192,7 +203,7 @@ void ts_sm_set_relay_positions(TSState state) {
|
||||
void ts_sm_set_relay_position(Relay relay, int closed) {
|
||||
static int neg_closed = 0;
|
||||
static int pos_closed = 0;
|
||||
static int precharge_closed = 0;
|
||||
static int pre_closed = 0;
|
||||
|
||||
GPIO_PinState state = closed ? GPIO_PIN_SET : GPIO_PIN_RESET;
|
||||
switch (relay) {
|
||||
@ -205,7 +216,7 @@ void ts_sm_set_relay_position(Relay relay, int closed) {
|
||||
HAL_GPIO_WritePin(POS_AIR_CTRL_GPIO_Port, POS_AIR_CTRL_Pin, state);
|
||||
break;
|
||||
case RELAY_PRECHARGE:
|
||||
ts_sm_check_close_wait(&precharge_closed, closed);
|
||||
ts_sm_check_close_wait(&pre_closed, closed);
|
||||
HAL_GPIO_WritePin(PRECHARGE_CTRL_GPIO_Port, PRECHARGE_CTRL_Pin, state);
|
||||
break;
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
#include "util.h"
|
||||
#include "main.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
void set_error_led() {
|
||||
#warning "check callers of this function"
|
||||
//HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_SET);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user