Skip to content

Commit

Permalink
fix: fsg 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonidotpy committed Aug 17, 2024
1 parent c74b120 commit 3f60519
Show file tree
Hide file tree
Showing 7 changed files with 2,438 additions and 2,414 deletions.
2 changes: 1 addition & 1 deletion fenice_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static const uint8_t TEMP_SENSOR_ADDRESS_CODING[TEMP_SENSORS_PER_STRIP] = {000,
#define AIRN_CHECK_TIMEOUT 1000
#define PRECHARGE_TIMEOUT 20000 // 13000 // ms
#define AIRP_CHECK_TIMEOUT 1000
#define CELLBOARD_COMM_TIMEOUT 500
#define CELLBOARD_COMM_TIMEOUT 100

// How much does a balancing cycle last (ms)
#define BAL_CYCLE_LENGTH 30000
Expand Down
2 changes: 1 addition & 1 deletion mainboard/Inc/error/error_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdint.h>
#include <stdlib.h>

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

typedef enum {
Expand Down
1 change: 1 addition & 0 deletions mainboard/Src/measures.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void measures_check_flags() {
if (_MEASURE_CHECK_INTERVAL(MEASURE_INTERVAL_200MS)) {
// Send info via CANS
can_car_send(PRIMARY_HV_DEBUG_SIGNALS_FRAME_ID);
can_car_send(PRIMARY_DEBUG_SIGNAL_2_FRAME_ID);
}
// 500 ms interval
if (_MEASURE_CHECK_INTERVAL(MEASURE_INTERVAL_500MS)) {
Expand Down
10 changes: 5 additions & 5 deletions mainboard/Src/pack/internal_voltage.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ HAL_StatusTypeDef internal_voltage_measure() {
internal_voltages.bat = volts[MAX22530_VBATT_CHANNEL - 1];

// Check if difference between readings from the ADC and cellboards is greater than 10V
if (fabsf(CONVERT_VALUE_TO_INTERNAL_VOLTAGE(internal_voltages.bat) - CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_sum())) > INTERNAL_VOLTAGE_MAX_DELTA) {
error_simple_set(ERROR_GROUP_ERROR_INT_VOLTAGE_MISMATCH, 0);
} else {
error_simple_reset(ERROR_GROUP_ERROR_INT_VOLTAGE_MISMATCH, 0);
}
// if (fabsf(CONVERT_VALUE_TO_INTERNAL_VOLTAGE(internal_voltages.bat) - CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_sum())) > INTERNAL_VOLTAGE_MAX_DELTA) {
// error_simple_set(ERROR_GROUP_ERROR_INT_VOLTAGE_MISMATCH, 0);
// } else {
// error_simple_reset(ERROR_GROUP_ERROR_INT_VOLTAGE_MISMATCH, 0);
// }
return HAL_OK;
}

Expand Down
12 changes: 8 additions & 4 deletions mainboard/Src/pack/temperature.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ void temperature_init() {
}
void temperature_check_errors() {
float max_temp = CONVERT_VALUE_TO_TEMPERATURE(temperature_get_max());

if (max_temp > CELL_MAX_TEMPERATURE) {
if (max_temp > CELL_MAX_TEMPERATURE)
error_simple_set(ERROR_GROUP_ERROR_CELL_OVER_TEMPERATURE, 0);
} else {
else
error_simple_reset(ERROR_GROUP_ERROR_CELL_OVER_TEMPERATURE, 0);
}

float min_temp = CONVERT_VALUE_TO_TEMPERATURE(temperature_get_min());
if (min_temp < -15.f)
error_simple_set(ERROR_GROUP_ERROR_CELL_UNDER_TEMPERATURE, 0);
else
error_simple_reset(ERROR_GROUP_ERROR_CELL_UNDER_TEMPERATURE, 0);

// Temperature sensors disconnected
#if !defined(TEMP_GROUP_ERROR_ENABLE) && defined(TEMP_ERROR_ENABLE)
Expand Down
69 changes: 33 additions & 36 deletions mainboard/Src/peripherals/can_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ void can_car_init() {

HAL_StatusTypeDef can_send(CAN_HandleTypeDef * hcan, uint8_t * buffer, CAN_TxHeaderTypeDef * header) {
// Wait for free mailboxes
if(_can_wait(hcan, 3) != HAL_OK)
if(_can_wait(hcan, 3) != HAL_OK) {
return HAL_TIMEOUT;
}

uint32_t mailbox = 0;
// if (hcan == &CAR_CAN && header->StdId == 0)
Expand All @@ -130,11 +131,10 @@ HAL_StatusTypeDef can_send(CAN_HandleTypeDef * hcan, uint8_t * buffer, CAN_TxHea
// Add message to a free mailbox
HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(hcan, header, buffer, &mailbox);
if (status != HAL_OK) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 0);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
} else {
error_simple_reset(ERROR_GROUP_ERROR_CAN, 0);
error_simple_reset(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
}

return status;
}
HAL_StatusTypeDef can_car_send(uint16_t id) {
Expand Down Expand Up @@ -567,22 +567,18 @@ HAL_StatusTypeDef can_car_send(uint16_t id) {
return HAL_ERROR;
tx_header.DLC = data_len;
}
// else if (id == PRIMARY_DEBUG_SIGNAL_2_FRAME_ID) {
// Error err[ERROR_INSTANCE_COUNT] = { 0 };
// error_dump_running(err);


// primary_debug_signal_2_t raw_debug;
// primary_debug_signal_2_converted_t conv_debug = {
// .device_id = primary_debug_signal_2_device_id_hv_mainboard,
// .field_1 = err[0].group / (float)ERROR_GROUP_COUNT,
// .field_2 = err[0].is_running,
// .field_3 = err[0].is_expired
// };
else if (id == PRIMARY_DEBUG_SIGNAL_2_FRAME_ID) {
float volt = CONVERT_VALUE_TO_INTERNAL_VOLTAGE(internal_voltage_get_bat());

primary_debug_signal_2_t raw_debug;
primary_debug_signal_2_converted_t conv_debug = {
.device_id = primary_debug_signal_2_device_id_hv_mainboard,
.field_1 = volt / 600.f,
};

// primary_debug_signal_2_conversion_to_raw_struct(&raw_debug, &conv_debug);
// tx_header.DLC = primary_debug_signal_2_pack(buffer, &raw_debug, PRIMARY_DEBUG_SIGNAL_2_BYTE_SIZE);
// }
primary_debug_signal_2_conversion_to_raw_struct(&raw_debug, &conv_debug);
tx_header.DLC = primary_debug_signal_2_pack(buffer, &raw_debug, PRIMARY_DEBUG_SIGNAL_2_BYTE_SIZE);
}
else
return HAL_ERROR;

Expand Down Expand Up @@ -640,9 +636,10 @@ HAL_StatusTypeDef can_bms_send(uint16_t id) {

tx_header.DLC = data_len;
}
else
else {
error_simple_set(ERROR_GROUP_ERROR_CAN, 0);
return HAL_ERROR;

}
return can_send(&BMS_CAN, buffer, &tx_header);
}

Expand All @@ -652,14 +649,14 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) {

// Check for communication errors
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_header, rx_data) != HAL_OK) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
cli_bms_debug("CAN: Error receiving message", 29);
return;
}

if (hcan->Instance == BMS_CAN.Instance) {
// Reset can errors
error_simple_reset(ERROR_GROUP_ERROR_CAN, 1);
error_simple_reset(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);

// Forward data to the cellboards
if (rx_header.StdId >= BMS_FLASH_CELLBOARD_0_TX_FRAME_ID && rx_header.StdId <= BMS_FLASH_CELLBOARD_5_RX_FRAME_ID) {
Expand All @@ -679,7 +676,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) {
bms_voltages_converted_t conv_volts = { 0 };

if (bms_voltages_unpack(&raw_volts, rx_data, BMS_VOLTAGES_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
bms_voltages_raw_to_conversion_struct(&conv_volts, &raw_volts);
Expand Down Expand Up @@ -720,7 +717,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) {
bms_voltages_info_converted_t conv_volts = { 0 };

if (bms_voltages_info_unpack(&raw_volts, rx_data, BMS_VOLTAGES_INFO_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
bms_voltages_info_raw_to_conversion_struct(&conv_volts, &raw_volts);
Expand All @@ -739,7 +736,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) {
bms_temperatures_converted_t conv_temps = { 0 };

if (bms_temperatures_unpack(&raw_temps, rx_data, BMS_TEMPERATURES_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
bms_temperatures_raw_to_conversion_struct(&conv_temps, &raw_temps);
Expand Down Expand Up @@ -826,7 +823,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) {
bms_temperatures_info_converted_t conv_temps = { 0 };

if (bms_temperatures_info_unpack(&raw_temps, rx_data, BMS_TEMPERATURES_INFO_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
bms_temperatures_info_raw_to_conversion_struct(&conv_temps, &raw_temps);
Expand All @@ -848,7 +845,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) {
bms_board_status_converted_t conv_status = { 0 };

if (bms_board_status_unpack(&raw_status, rx_data, BMS_BOARD_STATUS_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
bms_board_status_raw_to_conversion_struct(&conv_status, &raw_status);
Expand Down Expand Up @@ -933,7 +930,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) {
bms_cellboard_version_converted_t conv_version = { 0 };

if (bms_cellboard_version_unpack(&raw_version, rx_data, BMS_CELLBOARD_VERSION_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
bms_cellboard_version_raw_to_conversion_struct(&conv_version, &raw_version);
Expand Down Expand Up @@ -976,13 +973,13 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) {

// Check for communication errors
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO1, &rx_header, rx_data) != HAL_OK) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
cli_bms_debug("CAN: Error receiving message", 29);
return;
}

if (hcan->Instance == CAR_CAN.Instance) {
error_simple_reset(ERROR_GROUP_ERROR_CAN, 1);
error_simple_reset(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);

if (rx_header.StdId >= BMS_FLASH_CELLBOARD_0_TX_FRAME_ID && rx_header.StdId <= BMS_FLASH_CELLBOARD_5_RX_FRAME_ID) {
CAN_TxHeaderTypeDef tx_header = {
Expand All @@ -1005,7 +1002,7 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) {
primary_hv_set_status_ecu_converted_t conv_ts_status = { 0 };

if (primary_hv_set_status_ecu_unpack(&raw_ts_status, rx_data, PRIMARY_HV_SET_STATUS_ECU_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
primary_hv_set_status_ecu_raw_to_conversion_struct(&conv_ts_status, &raw_ts_status);
Expand All @@ -1027,7 +1024,7 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) {
primary_hv_set_balancing_status_handcart_converted_t conv_bal_status = { 0 };

if (primary_hv_set_balancing_status_handcart_unpack(&raw_bal_status, rx_data, PRIMARY_HV_SET_BALANCING_STATUS_HANDCART_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
primary_hv_set_balancing_status_handcart_raw_to_conversion_struct(&conv_bal_status, &raw_bal_status);
Expand All @@ -1040,7 +1037,7 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) {
primary_handcart_status_converted_t conv_handcart_status = { 0 };

if (primary_handcart_status_unpack(&raw_handcart_status, rx_data, PRIMARY_HANDCART_STATUS_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
primary_handcart_status_raw_to_conversion_struct(&conv_handcart_status, &raw_handcart_status);
Expand Down Expand Up @@ -1084,7 +1081,7 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) {
primary_hv_set_fans_status_converted_t conv_fans = { 0 };

if (primary_hv_set_fans_status_unpack(&raw_fans, rx_data, PRIMARY_HV_SET_FANS_STATUS_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
primary_hv_set_fans_status_raw_to_conversion_struct(&conv_fans, &raw_fans);
Expand All @@ -1098,7 +1095,7 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) {
primary_hv_jmp_to_blt_converted_t conv_jmp;

if (primary_hv_jmp_to_blt_unpack(&raw_jmp, rx_data, PRIMARY_HV_JMP_TO_BLT_BYTE_SIZE) < 0) {
error_simple_set(ERROR_GROUP_ERROR_CAN, 1);
error_simple_set(ERROR_GROUP_ERROR_CAN, hcan->Instance != BMS_CAN.Instance);
return;
}
primary_hv_jmp_to_blt_raw_to_conversion_struct(&conv_jmp, &raw_jmp);
Expand Down
Loading

0 comments on commit 3f60519

Please sign in to comment.