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 23, 2024
1 parent 3f60519 commit 9754531
Show file tree
Hide file tree
Showing 5 changed files with 2,693 additions and 2,659 deletions.
2 changes: 1 addition & 1 deletion fenice_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static const uint8_t TEMP_SENSOR_ADDRESS_CODING[TEMP_SENSORS_PER_STRIP] = {000,
/**
* Cell's limit voltages (mV * 10)
*/
#define CELL_MIN_VOLTAGE 28000
#define CELL_MIN_VOLTAGE 25000
#define CELL_WARN_VOLTAGE 30000
#define CELL_MAX_VOLTAGE 42000

Expand Down
3 changes: 2 additions & 1 deletion mainboard/Inc/error/error_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include <stdint.h>
#include <stdlib.h>

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

typedef enum {
Expand Down
33 changes: 25 additions & 8 deletions mainboard/Src/bms_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ bms_state_t do_fatal_error(state_data_t *data) {
/* Your Code Here */

// Check errors and feedbacks
if (get_expired_errors() == 0 && feedback_is_ok(FEEDBACK_FATAL_ERROR_MASK, FEEDBACK_FATAL_ERROR_HIGH))
if (get_expired_errors() == 0 && feedback_is_ok(FEEDBACK_FATAL_ERROR_MASK, FEEDBACK_FATAL_ERROR_HIGH)) {
next_state = STATE_IDLE;
}

switch (next_state) {
case NO_CHANGE:
Expand All @@ -230,12 +231,18 @@ bms_state_t do_wait_airn_close(state_data_t *data) {
/* Your Code Here */

// Check fatal errors
if (get_expired_errors() > 0)
if (get_expired_errors() > 0) {
next_state = STATE_FATAL_ERROR;
else if (_requested_ts_off() || airn_timeout)
}
else if (_requested_ts_off() || airn_timeout) {
next_state = STATE_IDLE;
else if (feedback_is_ok(FEEDBACK_AIRN_CHECK_MASK, FEEDBACK_AIRN_CHECK_HIGH))
}
else if (!feedback_is_ok(FEEDBACK_SD_END, FEEDBACK_AIRN_CHECK_HIGH)) {
next_state = STATE_IDLE;
}
else if (feedback_is_ok(FEEDBACK_AIRN_CHECK_MASK, FEEDBACK_AIRN_CHECK_HIGH)) {
next_state = STATE_WAIT_TS_PRECHARGE;
}

switch (next_state) {
case NO_CHANGE:
Expand All @@ -262,17 +269,23 @@ bms_state_t do_wait_ts_precharge(state_data_t *data) {
/* Your Code Here */

// Check fatal errors
if (get_expired_errors() > 0)
if (get_expired_errors() > 0) {
next_state = STATE_FATAL_ERROR;
}
else if (_requested_ts_off() || precharge_timeout) {
if (precharge_timeout)
cli_bms_debug("Precharge timeout", 17);
if (_requested_ts_off())
cli_bms_debug("Requested TS off", 16);
next_state = STATE_IDLE;
}
else if (feedback_is_ok(FEEDBACK_PRECHARGE_CHECK_MASK, FEEDBACK_PRECHARGE_CHECK_HIGH) && internal_voltage_is_precharge_complete())
next_state = STATE_WAIT_AIRP_CLOSE;
else if (!feedback_is_ok(FEEDBACK_SD_END, FEEDBACK_PRECHARGE_CHECK_HIGH)) {
next_state = STATE_IDLE;
}
else if (feedback_is_ok(FEEDBACK_PRECHARGE_CHECK_MASK, FEEDBACK_PRECHARGE_CHECK_HIGH) && internal_voltage_is_precharge_complete()) {
next_state = STATE_WAIT_AIRP_CLOSE;
}


switch (next_state) {
case NO_CHANGE:
Expand Down Expand Up @@ -305,8 +318,12 @@ bms_state_t do_wait_airp_close(state_data_t *data) {
cli_bms_debug("AIR+ timeout", 12);
next_state = STATE_IDLE;
}
else if (feedback_is_ok(FEEDBACK_AIRP_CHECK_MASK, FEEDBACK_AIRP_CHECK_HIGH))
else if (!feedback_is_ok(FEEDBACK_SD_END, FEEDBACK_AIRN_CHECK_HIGH)) {
next_state = STATE_IDLE;
}
else if (feedback_is_ok(FEEDBACK_AIRP_CHECK_MASK, FEEDBACK_AIRP_CHECK_HIGH)) {
next_state = STATE_TS_ON;
}

switch (next_state) {
case NO_CHANGE:
Expand Down
15 changes: 14 additions & 1 deletion mainboard/Src/error/error_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static uint8_t error_simple_state[ERROR_SIMPLE_STATE_SIZE];
static size_t error_expired = 0;
error_simple_dump_element_t error_simple_dump[ERROR_SIMPLE_DUMP_SIZE] = {0};

static size_t can_comm_cnt[ERROR_GROUP_ERROR_CAN_N_INSTANCES] = { 0U };

size_t _error_simple_from_group_and_instance_to_index(error_simple_groups_t group, size_t instance) {
uint32_t retidx = 0;
for (size_t i = 0; i < group && i < N_ERROR_GROUPS; i++) {
Expand Down Expand Up @@ -69,14 +71,25 @@ int error_simple_set(error_simple_groups_t group, size_t instance) {
if (group >= N_ERROR_GROUPS || instance >= error_instances[group]) {
return -1;
}
(error_simple_state[_error_simple_from_group_and_instance_to_index(group, instance)])++;
if (group == ERROR_GROUP_ERROR_CAN) {
if (++can_comm_cnt[instance] >= ERROR_SIMPLE_COUNTER_THRESHOLD_CAN_COMM) {
error_simple_state[_error_simple_from_group_and_instance_to_index(group, instance)] = ERROR_SIMPLE_COUNTER_THRESHOLD + 1U;
}
}
else {
++error_simple_state[_error_simple_from_group_and_instance_to_index(group, instance)];
}
return 0;
}

int error_simple_reset(error_simple_groups_t group, size_t instance) {
if (group >= N_ERROR_GROUPS || instance >= error_instances[group]) {
return -1;
}

if (group == ERROR_GROUP_ERROR_CAN) {
can_comm_cnt[instance] = 0U;
}
error_simple_state[_error_simple_from_group_and_instance_to_index(group, instance)] = 0;
return 0;
}
Expand Down
Loading

0 comments on commit 9754531

Please sign in to comment.