Skip to content

Commit

Permalink
FSG ELECTRICAL INSPECTIONS
Browse files Browse the repository at this point in the history
new error library
removed health signals (only lvms check)
new cli commands
updated micro-libs
fix: lv errors

fsg version
  • Loading branch information
gmazzucchi committed Aug 23, 2024
1 parent 5bb4eb4 commit 3ff3bc4
Show file tree
Hide file tree
Showing 21 changed files with 340 additions and 830 deletions.
24 changes: 14 additions & 10 deletions Core/Inc/bms_lv_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
primary_lv_cooling_aggressiveness_handler}

#define LV_VOLTAGE_CHECKS_DISABLED_TIMEOUT_ms (5000U)
#define MIN_CHARGER_CURRENT_THRESHOLD_mA (1500.0f)
#define MIN_CHARGER_CURRENT_THRESHOLD_mA (2500.0f)
#define MIN_BATTERY_CURRENT_THRESHOLD_mA (50.0f)
#define LVMS_THRESHOLD_mV (20000)
#define HEALTH_STATUS_CHECK_ENABLED (0U)
#define WAIT_BEFORE_CHECKING_LVMS_ms (2000U)

#define COOLING_TYPE_POLYNOMIAL (0u)
#define COOLING_TYPE_PID (1u)
Expand All @@ -45,8 +48,8 @@
#define MIN_BATTERY_VOLTAGE_mV ((MIN_CELL_VOLTAGE_V * 1000.0f) * 6.0f)
#define MAX_CELL_TEMP (60.0f)
#define MIN_CELL_TEMP (8.0f)
#define WARNING_VOLTAGE_V (3.5f)
#define BUZZER_WARNING_INTERVAL (90000U)
#define WARNING_VOLTAGE_V (3.3f)
#define BUZZER_WARNING_INTERVAL (60000U)

// Max current output allowed
#define MAX_CURRENT_mA (18000.0f)
Expand Down Expand Up @@ -159,9 +162,9 @@ enum mcp_controls_bank_b {
#define HEALTH_LVMS_OUT_INDEX (5U)
#define HEALTH_SIGNALS_N (6U)

#define HEALTH_SAFE_STATUS_CHG_CONNECT_ONLY_MCU_PW (0b000010)
#define HEALTH_SAFE_STATUS_MCU_ON_BAT_ONLY (0b000100)
#define HEALTH_SAFE_STATUS_CAR_ON_CHG_ONLY (0b001011)
// #define HEALTH_SAFE_STATUS_CHG_CONNECT_ONLY_MCU_PW (0b000010) // not safe (?)
#define HEALTH_SAFE_STATUS_MCU_ON_BAT_ONLY (0b000100)
// #define HEALTH_SAFE_STATUS_CAR_ON_CHG_ONLY (0b001011) // not safe (?)
#define HEALTH_SAFE_STATUS_CHG_BATT (0b001110)
#define HEALTH_SAFE_STATUS_CAR_ON_BAT_ONLY (0b001111)
#define HEALTH_SAFE_STATUS_RELAY_CLOSED_CHG_CAR_KEEP_CLOSED (0b011110)
Expand Down Expand Up @@ -248,9 +251,10 @@ void monitor_get_temperatures(float *);
int set_discharge(int state);
int set_rfe_frg(int state);
void set_relay(uint8_t status);
void send_primary_debug_1_signals(float field_1, float field_2, float field_3, float field_4);
void send_primary_debug_2_signals(float field_1, float field_2, float field_3, float field_4);
void send_primary_debug_3_signals(float field_1, float field_2, float field_3, float field_4);
void send_primary_debug_4_signals(float field_1, float field_2, float field_3, float field_4);
void send_primary_debug_1_signals(float field_1, float field_2, float field_3);
void send_primary_debug_2_signals(float field_1, float field_2, float field_3);
void send_primary_debug_3_signals(float field_1, float field_2, float field_3);
void send_primary_debug_4_signals(float field_1, float field_2, float field_3);
uint8_t get_health_status(void);

#endif // BMS_LV_CONFIG_H
55 changes: 55 additions & 0 deletions Core/Inc/error_simple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef ERROR_SIMPLE_H
#define ERROR_SIMPLE_H

#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define ERROR_SIMPLE_COUNTER_THRESHOLD (10U)
#define ERROR_SIMPLE_DUMP_SIZE (50U)

typedef enum {
ERROR_GROUP_BMS_LV_CELL_UNDERVOLTAGE,
ERROR_GROUP_BMS_LV_CELL_OVERVOLTAGE,
ERROR_GROUP_BMS_LV_OPEN_WIRE,
ERROR_GROUP_BMS_LV_ADC,
ERROR_GROUP_BMS_LV_CAN,
ERROR_GROUP_BMS_LV_SPI,
ERROR_GROUP_BMS_LV_OVER_CURRENT,
ERROR_GROUP_BMS_LV_CELL_UNDER_TEMPERATURE,
ERROR_GROUP_BMS_LV_CELL_OVER_TEMPERATURE,
ERROR_GROUP_BMS_LV_MCP23017,
ERROR_GROUP_BMS_LV_HEALTH,
N_ERROR_GROUPS
} error_simple_groups_t;

typedef struct {
error_simple_groups_t group;
size_t instance;
} error_simple_dump_element_t;

#define ERROR_GROUP_BMS_LV_CELL_UNDERVOLTAGE_N_INSTANCES (6U)
#define ERROR_GROUP_BMS_LV_CELL_OVERVOLTAGE_N_INSTANCES (6U)
#define ERROR_GROUP_BMS_LV_OPEN_WIRE_N_INSTANCES (1U)
#define ERROR_GROUP_BMS_LV_ADC_N_INSTANCES (1U)
#define ERROR_GROUP_BMS_LV_CAN_N_INSTANCES (2U)
#define ERROR_GROUP_BMS_LV_SPI_N_INSTANCES (1U)
#define ERROR_GROUP_BMS_LV_OVER_CURRENT_N_INSTANCES (3U)
#define ERROR_GROUP_BMS_LV_CELL_UNDER_TEMPERATURE_N_INSTANCES (12U)
#define ERROR_GROUP_BMS_LV_CELL_OVER_TEMPERATURE_N_INSTANCES (12U)
#define ERROR_GROUP_BMS_LV_MCP23017_N_INSTANCES (1U)
#define ERROR_GROUP_BMS_LV_HEALTH_N_INSTANCES (1U)

#define ERROR_TOGGLE_IF(condition, group, instance) ((condition) ? error_simple_set(group, instance) : error_simple_reset(group, instance))

int error_simple_set(error_simple_groups_t group, size_t instance);
int error_simple_reset(error_simple_groups_t group, size_t instance);
int error_simple_routine(void);
size_t get_expired_errors(void);

extern error_simple_dump_element_t error_simple_dump[ERROR_SIMPLE_DUMP_SIZE];

size_t _error_simple_from_group_and_instance_to_index(error_simple_groups_t group, size_t instance);

#endif // ERROR_SIMPLE_H
237 changes: 0 additions & 237 deletions Core/Inc/lv_errors.h

This file was deleted.

2 changes: 2 additions & 0 deletions Core/Inc/usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void MX_USART1_UART_Init(void);

/* USER CODE BEGIN Prototypes */

void print(const char *fmt, ...);

/* USER CODE END Prototypes */

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion Core/Lib/micro-libs
Submodule micro-libs updated 1 files
+2 −2 ucli/inc/ucli.h
6 changes: 3 additions & 3 deletions Core/Src/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/* USER CODE BEGIN 0 */
#include "current_transducer.h"
#include "lv_errors.h"
#include "error_simple.h"
#include "usart.h"

#include <stdio.h>
Expand Down Expand Up @@ -68,7 +68,7 @@ void adc_routine_start(void) {

set_mux_addr();
if (HAL_ADC_Start_DMA(&hadc2, (uint32_t *)adc2_raw, adc2_ch_n_values) != HAL_OK) {
error_set(ERROR_GROUP_BMS_LV_ADC, 0, HAL_GetTick());
error_simple_set(ERROR_GROUP_BMS_LV_ADC, 0);
};
// TODO: start vrefint calibration
}
Expand Down Expand Up @@ -101,7 +101,7 @@ void adc_routine(void) {
set_mux_addr();
if (HAL_ADC_Start_DMA(&hadc2, (uint32_t *)adc2_raw, adc2_ch_n_values) != HAL_OK) {
return;
// error_set(BMS_LV_ADC, 0, HAL_GetTick()); // TODO: setting the error is too strong, consider other options
// error_simple_set(BMS_LV_ADC, 0); // TODO: setting the error is too strong, consider other options
}
adc2_conversion_ended = 0;
}
Expand Down
Loading

0 comments on commit 3ff3bc4

Please sign in to comment.