Set precharge control to open if the AUX is open
This commit is contained in:
parent
a942a95ec0
commit
2b3c79c11f
|
@ -48,6 +48,7 @@ extern int hv_active;
|
|||
extern int neg_air_closed;
|
||||
extern int pos_air_closed;
|
||||
extern int precharge_closed;
|
||||
extern int precharge_opened;
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
|
|
@ -39,7 +39,7 @@ HAL_StatusTypeDef can_send_status() {
|
|||
}
|
||||
data[0] = (sdc_closed_nodelay << 0) | (ts_error << 1) | (hv_active << 2) |
|
||||
(neg_air_closed << 3) | (pos_air_closed << 4) |
|
||||
(precharge_closed << 5);
|
||||
(precharge_closed << 5) | (precharge_opened << 6);
|
||||
return ftcan_transmit(CAN_ID_AMS_SIGNALS, data, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ int hv_active;
|
|||
int neg_air_closed;
|
||||
int pos_air_closed;
|
||||
int precharge_closed;
|
||||
int precharge_opened = 0;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include "main.h"
|
||||
#include "shunt_monitoring.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "status_led.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include <stdint.h>
|
||||
|
||||
TSStateHandle ts_state;
|
||||
|
@ -11,6 +11,7 @@ TSStateHandle ts_state;
|
|||
static uint32_t precharge_95_reached_timestamp = 0;
|
||||
static uint32_t charging_check_timestamp = 0;
|
||||
static uint32_t discharge_begin_timestamp = 0;
|
||||
static uint32_t precharge_opened_timestamp = 0;
|
||||
|
||||
void ts_sm_init() {
|
||||
ts_state.current_state = TS_INACTIVE;
|
||||
|
@ -77,6 +78,13 @@ TSState ts_sm_update_active() {
|
|||
return TS_DISCHARGE;
|
||||
}
|
||||
|
||||
if (!precharge_closed && precharge_opened_timestamp == 0) {
|
||||
precharge_opened_timestamp = HAL_GetTick();
|
||||
} else if (precharge_opened_timestamp != 0 &&
|
||||
HAL_GetTick() - precharge_opened_timestamp > 100) {
|
||||
precharge_opened = 1;
|
||||
}
|
||||
|
||||
return TS_ACTIVE;
|
||||
}
|
||||
|
||||
|
@ -90,8 +98,11 @@ TSState ts_sm_update_precharge() {
|
|||
uint32_t now = HAL_GetTick();
|
||||
if (precharge_95_reached_timestamp == 0) {
|
||||
precharge_95_reached_timestamp = now;
|
||||
} else if ((now - precharge_95_reached_timestamp) >= PRECHARGE_95_DURATION) {
|
||||
} else if ((now - precharge_95_reached_timestamp) >=
|
||||
PRECHARGE_95_DURATION) {
|
||||
precharge_95_reached_timestamp = 0;
|
||||
precharge_opened_timestamp = 0;
|
||||
precharge_opened = 0;
|
||||
return TS_ACTIVE;
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +177,7 @@ void ts_sm_set_relay_positions(TSState state) {
|
|||
case TS_CHARGING:
|
||||
ts_sm_set_relay_position(RELAY_NEG, 1);
|
||||
ts_sm_set_relay_position(RELAY_POS, 1);
|
||||
ts_sm_set_relay_position(RELAY_PRECHARGE, 1);
|
||||
ts_sm_set_relay_position(RELAY_PRECHARGE, !precharge_opened);
|
||||
// TODO: Open precharge relay after a while
|
||||
break;
|
||||
case TS_PRECHARGE:
|
||||
|
@ -222,7 +233,8 @@ void ts_sm_handle_ams_in(const uint8_t *data) {
|
|||
}
|
||||
}
|
||||
|
||||
void ts_sm_set_error_source(TSErrorSource source, TSErrorKind error_type, bool is_errored) {
|
||||
void ts_sm_set_error_source(TSErrorSource source, TSErrorKind error_type,
|
||||
bool is_errored) {
|
||||
if (is_errored) {
|
||||
ts_state.error_source |= source;
|
||||
ts_state.error_type = error_type;
|
||||
|
|
Loading…
Reference in New Issue