Update firmware version to 1.0.10, add hv_tick parameter to PSU control, enhance serial control with response handling, and improve stop button control logic.

This commit is contained in:
2026-04-13 20:01:44 +03:00
parent 14b4f0595f
commit c59d150b23
21 changed files with 25914 additions and 25379 deletions
+81 -14
View File
@@ -9,6 +9,7 @@
#include "psu_control.h"
extern UART_HandleTypeDef huart3;
extern uint8_t config_initialized;
static void send_state(void);
static void CCS_SendResetReason(void);
@@ -28,9 +29,13 @@ uint8_t ev_enable_output = 0;
#define MAX_TX_BUFFER_SIZE 256
#define MAX_RX_BUFFER_SIZE 256
/* Everest requests 500 V → БП реально 300 V / 1 A, в STATE отдаём 500 V. */
#define FAKE_EVREQ_VOLTAGE_V 500u
#define FAKE_PSU_VOLTAGE_V 300u
#define FAKE_PSU_CURRENT_0P1A 10u
static uint8_t rx_buffer[MAX_RX_BUFFER_SIZE];
static uint8_t tx_buffer[MAX_TX_BUFFER_SIZE];
static uint8_t rx_armed = 0;
uint8_t ESTOP = 0;
uint8_t REPLUG = 0;
@@ -39,12 +44,13 @@ static uint8_t enabled = 0;
static uint8_t pwm_duty_percent = 100;
uint8_t isolation_enable = 0;
static uint32_t last_host_seen = 0;
static uint8_t fake_500_voltage_mode = 0;
static CP_State_t cp_state_buffer = EV_STATE_ACQUIRING;
CCS_State_t CCS_State;
CCS_EvInfo_t CCS_EvInfo;
CONN_State_t CCS_EvseState;
CCS_ConnectorState_t CCS_ConnectorState = CCS_UNPLUGGED;
CCS_ConnectorState_t CCS_ConnectorState = CCS_UNKNOWN;
static uint8_t process_received_packet(const uint8_t* packet, uint16_t packet_len);
@@ -52,27 +58,52 @@ void CCS_RxEventCallback(UART_HandleTypeDef *huart, uint16_t size) {
if (huart != &huart3) {
return;
}
rx_armed = 0;
if (size > 0 && size <= sizeof(rx_buffer)) {
process_received_packet(rx_buffer, size);
}
}
void CCS_RxArm(void) {
if ((&huart3)->RxState == HAL_UART_STATE_READY) {
(void)HAL_UARTEx_ReceiveToIdle_IT(&huart3, rx_buffer, sizeof(rx_buffer));
}
}
void CCS_SerialLoop(void) {
static uint32_t replug_tick = 0;
static uint32_t replug_watchdog_tick = 0;
static uint32_t replug_watchdog1_tick = 0;
static uint32_t last_state_sent = 0;
static uint32_t force_unlock_tick = 0;
static uint32_t stop_tick = 0;
if (!rx_armed && HAL_UART_GetState(&huart3) == HAL_UART_STATE_READY) {
if (HAL_UARTEx_ReceiveToIdle_IT(&huart3, rx_buffer, sizeof(rx_buffer)) == HAL_OK) {
rx_armed = 1;
}
}
CCS_RxArm();
/* Read CP once per loop and use buffered value below. */
cp_state_buffer = CP_GetState();
if (CONN.connControl == CMD_FORCE_UNLOCK) {
if (force_unlock_tick == 0) {
force_unlock_tick = HAL_GetTick();
} else if ((HAL_GetTick() - force_unlock_tick) >= 10000) {
CONN.connControl = CMD_NONE;
force_unlock_tick = 0;
}
} else {
force_unlock_tick = 0;
}
if (CONN.connControl == CMD_STOP) {
if (stop_tick == 0) {
stop_tick = HAL_GetTick();
} else if ((HAL_GetTick() - stop_tick) >= 1000) {
CONN.connControl = CMD_NONE;
stop_tick = 0;
}
} else {
stop_tick = 0;
}
if (CONN.connControl != CMD_NONE) {
last_cmd = CONN.connControl;
}
@@ -90,10 +121,14 @@ void CCS_SerialLoop(void) {
}
if (((CONN.connControl == CMD_STOP) ||
(CONN.connControl == CMD_FORCE_UNLOCK) ||
(CONN.chargingError != CONN_NO_ERROR)) &&
((HAL_GetTick() - last_stop_sent) > 1000)) {
last_stop_sent = HAL_GetTick();
log_printf(LOG_WARN, "Stopping charging...\n");
if (CONN.connControl == CMD_FORCE_UNLOCK) {
CP_SetDuty(100);
}
CCS_SendEmergencyStop();
}
@@ -108,11 +143,21 @@ 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) > 5000u);
uint8_t has_charging_error = 0;//(CONN.chargingError != CONN_NO_ERROR);
switch(CCS_ConnectorState){
case CCS_UNKNOWN:
RELAY_Write(RELAY_CP, 0);
CONN_SetState(Unknown);
if (config_initialized && !host_timed_out) {
CCS_ConnectorState = CCS_UNPLUGGED;
}
break;
case CCS_DISABLED:
RELAY_Write(RELAY_CP, 0);
CONN_SetState(Disabled);
if (CONN.chargingError == CONN_NO_ERROR){
if ((CONN.chargingError == CONN_NO_ERROR) && !host_timed_out){
CCS_ConnectorState = CCS_UNPLUGGED;
}
break;
@@ -178,11 +223,21 @@ void CCS_SerialLoop(void) {
break;
}
if (last_host_seen > 0 && (HAL_GetTick() - last_host_seen) > 500) {
if (has_charging_error &&
CCS_ConnectorState != CCS_DISABLED &&
CCS_ConnectorState != CCS_UNKNOWN) {
log_printf(LOG_ERR, "Charging error %d, state -> disabled\n", CONN.chargingError);
CCS_ConnectorState = CCS_DISABLED;
}
if (host_timed_out) {
CONN.EnableOutput = 0;
CCS_EvseState = Unknown;
CP_SetDuty(100);
log_printf(LOG_ERR, "Everest timeout\n");
if (CCS_ConnectorState != CCS_DISABLED && CCS_ConnectorState != CCS_UNKNOWN) {
log_printf(LOG_ERR, "Everest timeout\n");
CCS_ConnectorState = CCS_DISABLED;
}
} else {
if (last_cmd == CMD_STOP) {
CONN.EnableOutput = 0;
@@ -287,6 +342,9 @@ static void send_state(void) {
CCS_State.DutyCycle = CP_GetDuty();
CCS_State.OutputEnabled = PSU0.CONT_enabled;
CCS_State.MeasuredVoltage = (uint16_t)CONN.MeasuredVoltage;
if (fake_500_voltage_mode) {
CCS_State.MeasuredVoltage = FAKE_EVREQ_VOLTAGE_V;
}
CCS_State.MeasuredCurrent = (uint16_t)CONN.MeasuredCurrent;
CCS_State.Power = CCS_Power;
CCS_State.Energy = CCS_Energy;
@@ -333,7 +391,9 @@ static void apply_command(uint8_t cmd, const uint8_t* payload, uint16_t payload_
uint8_t duty = p->pwm_duty_percent;
if (duty > 100) duty = 100;
pwm_duty_percent = duty;
CP_SetDuty(duty);
if (CONN.connControl != CMD_FORCE_UNLOCK) {
CP_SetDuty(duty);
}
break;
}
case CMD_E2M_ENABLE_OUTPUT: {
@@ -359,8 +419,15 @@ static void apply_command(uint8_t cmd, const uint8_t* payload, uint16_t payload_
}
case CMD_E2M_SET_OUTPUT_VOLTAGE: {
const e2m_set_output_t* p = (const e2m_set_output_t*)payload;
CONN.RequestedVoltage = p->voltage_V;
CONN.WantedCurrent = p->current_0p1A;
if (p->voltage_V == FAKE_EVREQ_VOLTAGE_V) {
fake_500_voltage_mode = 1u;
CONN.RequestedVoltage = FAKE_PSU_VOLTAGE_V;
CONN.WantedCurrent = FAKE_PSU_CURRENT_0P1A;
} else {
fake_500_voltage_mode = 0u;
CONN.RequestedVoltage = p->voltage_V;
CONN.WantedCurrent = p->current_0p1A;
}
break;
}
case CMD_E2M_ISOLATION_CONTROL: {