cleanup, some error handling

This commit is contained in:
Kilian Bracher 2024-07-04 20:01:30 +02:00
parent b86d165c41
commit 79f69333a5
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
4 changed files with 15 additions and 11 deletions

View File

@ -37,7 +37,6 @@ typedef enum { // states -> 3 bit. valid transitions: (all could t
} State; } State;
typedef struct { typedef struct {
uint16_t bms_timeout : 1; uint16_t bms_timeout : 1;
uint16_t bms_fault : 1; uint16_t bms_fault : 1;
uint16_t temperature_error : 1; uint16_t temperature_error : 1;
@ -46,7 +45,8 @@ typedef struct {
uint16_t voltage_error : 1; uint16_t voltage_error : 1;
uint16_t voltage_missing : 1; uint16_t voltage_missing : 1;
uint16_t state_transition_fail : 1; uint16_t state_transition_fail : 1;
uint16_t eeprom_error : 1;
uint16_t : 7; // padding
} ErrorKind; } ErrorKind;
//typedef enum {} WarningKind; //typedef enum {} WarningKind;
@ -59,8 +59,8 @@ typedef struct {
} StateHandle; } StateHandle;
extern StateHandle state; extern StateHandle state;
static bool relay_closed = 0; static bool relay_closed = 0; //NOTE: unused?
static bool precharge_closed = 0; static bool precharge_closed = 0; //NOTE: unused?
extern int16_t RELAY_BAT_SIDE_VOLTAGE; extern int16_t RELAY_BAT_SIDE_VOLTAGE;
extern int16_t RELAY_ESC_SIDE_VOLTAGE; extern int16_t RELAY_ESC_SIDE_VOLTAGE;
extern int16_t CURRENT_MEASUREMENT; extern int16_t CURRENT_MEASUREMENT;

View File

@ -13,7 +13,7 @@ TIM_HandleTypeDef *powerground, *battery_cooling, *esc_cooling;
void PWM_control_init(TIM_HandleTypeDef* pg, TIM_HandleTypeDef* bat_cool, TIM_HandleTypeDef* esc_cool){ void PWM_control_init(TIM_HandleTypeDef* pg, TIM_HandleTypeDef* bat_cool, TIM_HandleTypeDef* esc_cool){
powerground_status = 0; powerground_status = 0;
battery_cooling_status = 0; //battery_cooling_status = 0;
powerground = pg; powerground = pg;
battery_cooling = bat_cool; battery_cooling = bat_cool;

View File

@ -8,7 +8,7 @@
//#define CAN_ID_IN 0x501 //#define CAN_ID_IN 0x501
//#define CAN_ID_OUT 0x502 //#define CAN_ID_OUT 0x502
int can_delay_manager = 0; static uint32_t can_delay_manager = 0;
void can_init(CAN_HandleTypeDef* hcan) { void can_init(CAN_HandleTypeDef* hcan) {
ftcan_init(hcan); ftcan_init(hcan);
ftcan_add_filter(CAN_ID_IN, 0xFFF); ftcan_add_filter(CAN_ID_IN, 0xFFF);

View File

@ -5,7 +5,6 @@
#include "main.h" #include "main.h"
#include "stm32f3xx_hal.h" #include "stm32f3xx_hal.h"
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
StateHandle state; StateHandle state;
int16_t RELAY_BAT_SIDE_VOLTAGE; int16_t RELAY_BAT_SIDE_VOLTAGE;
@ -13,7 +12,7 @@ int16_t RELAY_ESC_SIDE_VOLTAGE;
int16_t CURRENT_MEASUREMENT; int16_t CURRENT_MEASUREMENT;
uint8_t powerground_status; uint8_t powerground_status;
uint32_t timestamp; static uint32_t timestamp;
void sm_init(){ void sm_init(){
state.current_state = STATE_INACTIVE; state.current_state = STATE_INACTIVE;
@ -79,7 +78,7 @@ State sm_update_precharge(){
PWM_set_throttle(); PWM_set_throttle();
return STATE_READY; return STATE_READY;
} }
break; return STATE_PRECHARGE;
case STATE_DISCHARGE: case STATE_DISCHARGE:
return STATE_DISCHARGE; return STATE_DISCHARGE;
default: default:
@ -112,8 +111,7 @@ State sm_update_active(){
State sm_update_discharge(){ State sm_update_discharge(){
switch (state.target_state) { switch (state.target_state) {
case STATE_DISCHARGE: case STATE_DISCHARGE:
if (RELAY_ESC_SIDE_VOLTAGE < 5000) return (RELAY_ESC_SIDE_VOLTAGE < 5000) ? STATE_INACTIVE : STATE_DISCHARGE;
return STATE_INACTIVE;
case STATE_PRECHARGE: // if CAN Signal 1000 0000 then get ready case STATE_PRECHARGE: // if CAN Signal 1000 0000 then get ready
return STATE_PRECHARGE; return STATE_PRECHARGE;
default: default:
@ -259,12 +257,18 @@ void sm_check_errors(){
case SEK_UNDERTEMP: case SEK_UNDERTEMP:
case SEK_TOO_FEW_TEMPS: case SEK_TOO_FEW_TEMPS:
state.error_type.temperature_error = 1; state.error_type.temperature_error = 1;
break;
case SEK_OVERVOLT: case SEK_OVERVOLT:
case SEK_UNDERVOLT: case SEK_UNDERVOLT:
case SEK_OPENWIRE: case SEK_OPENWIRE:
state.error_type.voltage_error = 1;
break;
case SEK_EEPROM_ERR: case SEK_EEPROM_ERR:
state.error_type.eeprom_error = 1;
break;
case SEK_INTERNAL_BMS_TIMEOUT: case SEK_INTERNAL_BMS_TIMEOUT:
state.error_type.bms_timeout = 1; state.error_type.bms_timeout = 1;
break;
case SEK_INTERNAL_BMS_CHECKSUM_FAIL: case SEK_INTERNAL_BMS_CHECKSUM_FAIL:
case SEK_INTERNAL_BMS_OVERTEMP: case SEK_INTERNAL_BMS_OVERTEMP:
case SEK_INTERNAL_BMS_FAULT: case SEK_INTERNAL_BMS_FAULT: