last version before dma

This commit is contained in:
2026-05-07 12:26:13 +03:00
parent 910811df1d
commit ea8663e247
6 changed files with 22166 additions and 22163 deletions
+30 -25
View File
@@ -29,7 +29,8 @@ uint8_t ev_enable_output = 0;
#define CMD_INTERVAL 10
#define MAX_TX_BUFFER_SIZE 256
#define MAX_RX_BUFFER_SIZE 256
#define EVEREST_TIMEOUT_MS 5000u
#define EVEREST_TIMEOUT_WARN_MS 5000u
#define EVEREST_TIMEOUT_STOP_MS 10000u
#define UART3_REINIT_TIMEOUT_MS 1500u
/* Everest requests 500 V -> PSU really gets 300 V / 1 A, state still reports 500 V. */
#define FAKE_EVREQ_VOLTAGE_V 500u
@@ -48,7 +49,8 @@ uint8_t isolation_enable = 0;
static uint32_t last_host_seen = 0;
static uint8_t fake_500_voltage_mode = 0;
static uint8_t everest_timed_out = 0;
static uint32_t last_everest_timeout_log_tick = 0;
static uint8_t everest_timeout_warn_latched = 0;
static uint8_t everest_timeout_stop_latched = 0;
static uint32_t uart3_last_packet_tick = 0;
static uint32_t uart3_last_reinit_tick = 0;
@@ -211,7 +213,27 @@ void CCS_SerialLoop(void) {
(void)replug_watchdog_tick;
(void)replug_watchdog1_tick;
uint8_t host_timed_out = (last_host_seen > 0 && (HAL_GetTick() - last_host_seen) > EVEREST_TIMEOUT_MS);
uint32_t now = HAL_GetTick();
uint8_t host_timeout_warn = (last_host_seen > 0 && (now - last_host_seen) > EVEREST_TIMEOUT_WARN_MS);
uint8_t host_timeout_stop = (last_host_seen > 0 && (now - last_host_seen) > EVEREST_TIMEOUT_STOP_MS);
uint8_t host_timed_out = host_timeout_stop;
if (host_timeout_warn && !everest_timeout_warn_latched) {
log_printf(LOG_ERR, "Everest timeout\n");
everest_timeout_warn_latched = 1;
}
if (host_timeout_stop && !everest_timeout_stop_latched) {
log_printf(LOG_ERR, "Everest timeout, stopping charging...\n");
everest_timeout_stop_latched = 1;
}
if (!host_timeout_warn) {
everest_timeout_warn_latched = 0;
everest_timeout_stop_latched = 0;
}
everest_timed_out = host_timeout_stop;
switch(CCS_ConnectorState){
case CCS_UNKNOWN:
RELAY_Write(RELAY_CP, 0);
@@ -253,7 +275,7 @@ void CCS_SerialLoop(void) {
break;
case CCS_CONNECTED:
RELAY_Write(RELAY_CP, 1);
if(CCS_EvseState < Preparing) {
if((CCS_EvseState < Preparing) || (CCS_EvseState == AuthRequired)) {
CONN_SetState(Preparing);
} else {
CONN_SetState(CCS_EvseState);
@@ -289,26 +311,8 @@ void CCS_SerialLoop(void) {
break;
}
// If Everest timeout happened, keep safe-state and limit log frequency.
// The safe-state must remain until we receive a valid packet from the host.
if (everest_timed_out) {
if (last_everest_timeout_log_tick == 0 ||
(HAL_GetTick() - last_everest_timeout_log_tick) >= EVEREST_TIMEOUT_MS) {
log_printf(LOG_ERR, "Everest timeout\n");
last_everest_timeout_log_tick = HAL_GetTick();
}
CONN.EnableOutput = 0;
CCS_EvseState = Unknown;
CP_SetDuty(100);
if (CCS_ConnectorState != CCS_DISABLED && CCS_ConnectorState != CCS_UNKNOWN) {
CCS_ConnectorState = CCS_DISABLED;
}
} else if (last_host_seen > 0 && (HAL_GetTick() - last_host_seen) > EVEREST_TIMEOUT_MS) {
log_printf(LOG_ERR, "Everest timeout\n");
everest_timed_out = 1;
last_host_seen = HAL_GetTick(); // reset after the first timeout
last_everest_timeout_log_tick = HAL_GetTick();
// 10s timeout: enforce safe-state until host communication recovers.
if (host_timeout_stop) {
CONN.EnableOutput = 0;
CCS_EvseState = Unknown;
CP_SetDuty(100);
@@ -465,7 +469,8 @@ ISR_FAST static void apply_command(uint8_t cmd, const uint8_t* payload, uint16_t
(void)payload_len;
last_host_seen = HAL_GetTick();
everest_timed_out = 0;
last_everest_timeout_log_tick = 0;
everest_timeout_warn_latched = 0;
everest_timeout_stop_latched = 0;
switch (cmd) {
case CMD_E2M_PWM_DUTY: {
const e2m_pwm_duty_t* p = (const e2m_pwm_duty_t*)payload;