Make SDC state globally available
This commit is contained in:
parent
6c27b83377
commit
29b411e4af
|
@ -41,7 +41,7 @@ extern "C" {
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EC */
|
/* USER CODE BEGIN EC */
|
||||||
|
extern int sdc_closed;
|
||||||
/* USER CODE END EC */
|
/* USER CODE END EC */
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
|
|
@ -55,7 +55,7 @@ CAN_HandleTypeDef hcan;
|
||||||
UART_HandleTypeDef huart1;
|
UART_HandleTypeDef huart1;
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
|
int sdc_closed = 0;
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
@ -132,6 +132,8 @@ int main(void) {
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
HAL_GPIO_TogglePin(STATUS1_GPIO_Port, STATUS1_Pin);
|
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();
|
slaves_check();
|
||||||
shunt_check();
|
shunt_check();
|
||||||
|
|
|
@ -12,11 +12,6 @@ static uint32_t precharge_95_reached_timestamp = 0;
|
||||||
static uint32_t charging_check_timestamp = 0;
|
static uint32_t charging_check_timestamp = 0;
|
||||||
static uint32_t discharge_begin_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() {
|
void ts_sm_init() {
|
||||||
ts_state.current_state = TS_INACTIVE;
|
ts_state.current_state = TS_INACTIVE;
|
||||||
ts_state.target_state = TS_INACTIVE;
|
ts_state.target_state = TS_INACTIVE;
|
||||||
|
@ -68,7 +63,7 @@ TSState ts_sm_update_inactive() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TSState ts_sm_update_active() {
|
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();
|
discharge_begin_timestamp = HAL_GetTick();
|
||||||
return TS_DISCHARGE;
|
return TS_DISCHARGE;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +72,7 @@ TSState ts_sm_update_active() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TSState ts_sm_update_precharge() {
|
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();
|
discharge_begin_timestamp = HAL_GetTick();
|
||||||
return TS_DISCHARGE;
|
return TS_DISCHARGE;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +114,7 @@ TSState ts_sm_update_error() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TSState ts_sm_update_charging_check() {
|
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();
|
discharge_begin_timestamp = HAL_GetTick();
|
||||||
return TS_DISCHARGE;
|
return TS_DISCHARGE;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +130,7 @@ TSState ts_sm_update_charging_check() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TSState ts_sm_update_charging() {
|
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();
|
discharge_begin_timestamp = HAL_GetTick();
|
||||||
return TS_DISCHARGE;
|
return TS_DISCHARGE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue