diff --git a/Core/Inc/main.h b/Core/Inc/main.h index beb171b..49bae33 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -41,7 +41,7 @@ extern "C" { /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ - +extern int sdc_closed; /* USER CODE END EC */ /* Exported macro ------------------------------------------------------------*/ diff --git a/Core/Src/main.c b/Core/Src/main.c index 6178e7f..435abfe 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -55,7 +55,7 @@ CAN_HandleTypeDef hcan; UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */ - +int sdc_closed = 0; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -132,6 +132,8 @@ int main(void) { /* USER CODE BEGIN 3 */ HAL_GPIO_TogglePin(STATUS1_GPIO_Port, STATUS1_Pin); + sdc_closed = HAL_GPIO_ReadPin(SDC_VOLTAGE_GPIO_Port, SDC_VOLTAGE_Pin) == + GPIO_PIN_SET; slaves_check(); shunt_check(); diff --git a/Core/Src/ts_state_machine.c b/Core/Src/ts_state_machine.c index 9d3c993..4c027fa 100644 --- a/Core/Src/ts_state_machine.c +++ b/Core/Src/ts_state_machine.c @@ -12,11 +12,6 @@ static uint32_t precharge_95_reached_timestamp = 0; static uint32_t charging_check_timestamp = 0; static uint32_t discharge_begin_timestamp = 0; -static int sdc_is_closed() { - return HAL_GPIO_ReadPin(SDC_VOLTAGE_GPIO_Port, SDC_VOLTAGE_Pin) == - GPIO_PIN_SET; -} - void ts_sm_init() { ts_state.current_state = TS_INACTIVE; ts_state.target_state = TS_INACTIVE; @@ -68,7 +63,7 @@ TSState ts_sm_update_inactive() { } TSState ts_sm_update_active() { - if (ts_state.target_state == TS_INACTIVE || !sdc_is_closed()) { + if (ts_state.target_state == TS_INACTIVE || !sdc_closed) { discharge_begin_timestamp = HAL_GetTick(); return TS_DISCHARGE; } @@ -77,7 +72,7 @@ TSState ts_sm_update_active() { } TSState ts_sm_update_precharge() { - if (ts_state.target_state == TS_INACTIVE || !sdc_is_closed()) { + if (ts_state.target_state == TS_INACTIVE || !sdc_closed) { discharge_begin_timestamp = HAL_GetTick(); return TS_DISCHARGE; } @@ -119,7 +114,7 @@ TSState ts_sm_update_error() { } TSState ts_sm_update_charging_check() { - if (ts_state.target_state == TS_INACTIVE || !sdc_is_closed()) { + if (ts_state.target_state == TS_INACTIVE || !sdc_closed) { discharge_begin_timestamp = HAL_GetTick(); return TS_DISCHARGE; } @@ -135,7 +130,7 @@ TSState ts_sm_update_charging_check() { } TSState ts_sm_update_charging() { - if (ts_state.target_state == TS_INACTIVE || !sdc_is_closed()) { + if (ts_state.target_state == TS_INACTIVE || !sdc_closed) { discharge_begin_timestamp = HAL_GetTick(); return TS_DISCHARGE; }