feat: S12 — vcucmd 3-state command from VCU (replaces binary vcustop) #10

Open
bastian wants to merge 3 commits from feat/s12-vcucmd-3state into fix/canmap-revert-clear-add-reentrancy-guard
3 changed files with 97 additions and 20 deletions
Showing only changes of commit aae23f53a6 - Show all commits
+31 -2
View File
@@ -109,7 +109,7 @@
VALUE_ENTRY(c3udc, "V", 2035 ) \ VALUE_ENTRY(c3udc, "V", 2035 ) \
VALUE_ENTRY(c3idc, "A", 2036 ) \ VALUE_ENTRY(c3idc, "A", 2036 ) \
VALUE_ENTRY(tmpobcmax, "°C", 2051 ) \ VALUE_ENTRY(tmpobcmax, "°C", 2051 ) \
VALUE_ENTRY(vcustop, OFFON, 2052 ) \ VALUE_ENTRY(vcucmd, VCUCMDS, 2052 ) \
VALUE_ENTRY(test_time, "s", 3000 ) \ VALUE_ENTRY(test_time, "s", 3000 ) \
VALUE_ENTRY(test_timer_flag, "X", 3001 ) \ VALUE_ENTRY(test_timer_flag, "X", 3001 ) \
VALUE_ENTRY(test_timer_icvalue, "X", 3002 ) \ VALUE_ENTRY(test_timer_icvalue, "X", 3002 ) \
@@ -119,6 +119,12 @@
#define OPMODES "0=Off, 1=Run" #define OPMODES "0=Off, 1=Run"
#define CHARGERS "1=Charger1, 2=Charger2, 4=Charger3" #define CHARGERS "1=Charger1, 2=Charger2, 4=Charger3"
#define OFFON "0=Off, 1=On" #define OFFON "0=Off, 1=On"
// SKUDAK-S12: VCU→charger control command on 0x212 byte 3. Mirrors the Dilong
// path's OBC_ControlCMD vocabulary exactly so VCU code paths can be reused.
// 0 = Charging — VCU wants current to flow; walk to / hold at EVSEACTIVATE
// 1 = Stopped — VCU is not driving a cycle; sit in OFF/WAITSTART/ENABLE
// 2 = Complete — VCU has terminated the cycle; drop to STOP
#define VCUCMDS "0=Charging, 1=Stopped, 2=Complete"
#define CHFLAGS "0=None, 1=Enabled, 2=Fault, 4=CheckAlive" #define CHFLAGS "0=None, 1=Enabled, 2=Fault, 4=CheckAlive"
#define STATES "0=Off, 1=WaitStart, 2=Enable, 3=Activate, 4=Run, 5=Stop" #define STATES "0=Off, 1=WaitStart, 2=Enable, 3=Activate, 4=Run, 5=Stop"
#define INPUTS "0=Type2, 1=Type2-3P, 2=Type1, 3=Manual, 4=Manual-3P, 5=Type2-Auto" #define INPUTS "0=Type2, 1=Type2-3P, 2=Type1, 3=Manual, 4=Manual-3P, 5=Type2-Auto"
@@ -151,7 +157,18 @@
// it sets vcustop=1; ChargerStateMachine's EVSEACTIVATE case transitions to // it sets vcustop=1; ChargerStateMachine's EVSEACTIVATE case transitions to
// STOP immediately, the J1772 CP signal drops, EVSE stops delivering AC, // STOP immediately, the J1772 CP signal drops, EVSE stops delivering AC,
// VCU_IsCharging() returns 0, water pumps power down naturally. // VCU_IsCharging() returns 0, water pumps power down naturally.
#define VERSTR STRINGIFY(4=VER-S11) // -S12 promotes byte 3 from a binary vcustop flag to the full 3-state
// VCUCMDS vocabulary (0=Charging, 1=Stopped, 2=Complete), matching the
// Dilong OBC_ControlCMD exactly. The internal FSM now obeys vcucmd for
// lifecycle transitions: ENABLE only advances to ACTIVATE on Charging, STOP
// returns to OFF when vcucmd flips back to Charging/Stopped (fixes the
// "raise ChargeLimit mid-COMPLETE doesn't resume" wedge — teslacharger was
// stuck in STOP because STOP only exited on CheckUnplugged). The self-
// decided EVSEACTIVATE exits (CheckVoltage, CheckTimeout) are stripped; the
// VCU is now authoritative for when charging starts and stops. The charger
// retains hardware-level wisdom: CheckUnplugged() still forces OFF from any
// state, and CheckStartCondition() still gates OFF→WAITSTART on EVSE pilot.
#define VERSTR STRINGIFY(4=VER-S12)
/***** enums ******/ /***** enums ******/
@@ -175,6 +192,18 @@ enum states
STOP STOP
}; };
// SKUDAK-S12: VCU→charger command vocabulary on 0x212 byte 3. Must match
// the values exposed via VCUCMDS enum string AND the VCU's
// VCU_OIOBCCommand_t enum (stm32-hal-vcu Core/Inc/applications/charger/
// charger_types.h). Updating one without the others silently breaks the
// charge state machine, so keep them in lock-step.
enum vcucmds
{
VCUCMD_CHARGING = 0,
VCUCMD_STOPPED = 1,
VCUCMD_COMPLETE = 2
};
enum _canspeeds enum _canspeeds
{ {
CAN_PERIOD_100MS = 0, CAN_PERIOD_100MS = 0,
+52 -10
View File
@@ -299,10 +299,26 @@ void CalcAcCurrentLimit()
Param::SetFloat(Param::aclim, iacLim); Param::SetFloat(Param::aclim, iacLim);
} }
// SKUDAK-S12: VCU is authoritative for charge-cycle lifecycle. The charger
// keeps hardware-level wisdom (EVSE pilot detection, plug-out safety,
// fault detection, current ramping) but obeys vcucmd for "should I be
// charging right now?" — exactly mirroring the Dilong OBC_ControlCMD
// pattern so the VCU's two charger paths can share code/state.
//
// VCUCMDS vocabulary (see include/param_prj.h):
// 0 Charging — VCU wants current; walk to / hold at EVSEACTIVATE
// 1 Stopped — VCU has no active cycle; sit idle (no current)
// 2 Complete — VCU has terminated the cycle; drop to STOP
//
// Self-decided exits from EVSEACTIVATE (CheckVoltage, CheckTimeout) are
// gone — those were band-aids for the absence of an authoritative VCU
// stop signal. CheckUnplugged() still owns hardware safety from every
// state; CheckChargerFaults() still bails on real module faults.
void ChargerStateMachine() void ChargerStateMachine()
{ {
static states state = OFF; static states state = OFF;
int configuredChargers = Param::GetInt(Param::chargerena); int configuredChargers = Param::GetInt(Param::chargerena);
int vcucmd = Param::GetInt(Param::vcucmd);
if (!Param::GetBool(Param::enable)) if (!Param::GetBool(Param::enable))
{ {
@@ -316,6 +332,9 @@ void ChargerStateMachine()
Param::SetInt(Param::opmode, 0); Param::SetInt(Param::opmode, 0);
DisableAll(); DisableAll();
// OFF→WAITSTART requires hardware-level start condition (EVSE pilot
// or non-EVSE input). vcucmd is checked downstream — we still walk
// up to ENABLE on plug-in so the modules are ready when VCU says go.
if (CheckStartCondition()) if (CheckStartCondition())
{ {
startTime = rtc_get_counter_val(); startTime = rtc_get_counter_val();
@@ -334,7 +353,15 @@ void ChargerStateMachine()
DigIo::ch2ena_out.Set(); DigIo::ch2ena_out.Set();
if (configuredChargers & 4) if (configuredChargers & 4)
DigIo::ch3ena_out.Set(); DigIo::ch3ena_out.Set();
// Hold here until VCU says go (vcucmd=Charging) or terminates
// (vcucmd=Complete). Stopped keeps us armed but idle.
if (vcucmd == VCUCMD_COMPLETE)
state = STOP;
else if (vcucmd == VCUCMD_CHARGING)
state = ACTIVATE; state = ACTIVATE;
else if (CheckUnplugged())
state = OFF;
break; break;
case ACTIVATE: case ACTIVATE:
Param::SetInt(Param::opmode, 1); Param::SetInt(Param::opmode, 1);
@@ -353,21 +380,28 @@ void ChargerStateMachine()
DigIo::evseact_out.Set(); DigIo::evseact_out.Set();
DigIo::acpres_out.Set(); DigIo::acpres_out.Set();
// SKUDAK-S11: explicit VCU stop command takes priority over every // VCU command is the primary exit. CheckUnplugged + CheckChargerFaults
// other exit condition. When the VCU's BMS-side gate determines the // remain for hardware safety; the self-decided CheckVoltage/CheckTimeout
// charge session is complete (or the user lowered ChargeLimit below // exits are gone (S12 — VCU is authoritative).
// current SOC), it sets vcustop=1 on 0x212 byte 3. We obey if (vcucmd == VCUCMD_COMPLETE)
// immediately — drop AC pres + EVSE-active GPIOs and transition to
// STOP. Mirrors how the Dilong path's OBC_ControlCMD = Stopped works.
// Replaces the brittle udclim=200V mechanism from -S10.
if (Param::GetInt(Param::vcustop))
{ {
DigIo::acpres_out.Clear(); DigIo::acpres_out.Clear();
DigIo::evseact_out.Clear(); DigIo::evseact_out.Clear();
state = STOP; state = STOP;
} }
else if (CheckVoltage() || CheckTimeout()) else if (vcucmd == VCUCMD_STOPPED)
state = STOP; {
// VCU revoked the charge command (e.g. user lowered limit below
// current SOC but BMS isn't full yet). Park HV-armed in ENABLE
// ready to resume on the next Charging command.
DigIo::ch1act_out.Clear();
DigIo::ch2act_out.Clear();
DigIo::ch3act_out.Clear();
DigIo::acpres_out.Clear();
DigIo::evseact_out.Clear();
Param::SetInt(Param::opmode, 0);
state = ENABLE;
}
else if (CheckUnplugged()) else if (CheckUnplugged())
{ {
DigIo::acpres_out.Clear(); DigIo::acpres_out.Clear();
@@ -386,6 +420,14 @@ void ChargerStateMachine()
if (CheckUnplugged()) if (CheckUnplugged())
state = OFF; state = OFF;
// S12 fix for the "raise ChargeLimit mid-COMPLETE wedges in STOP"
// bug: when VCU clears Complete (latch released because user raised
// limit above current SOC), drop to OFF so the natural OFF→WAITSTART
// →ENABLE→ACTIVATE→EVSEACTIVATE flow restarts charging next tick.
// Previously STOP only exited on physical unplug — wedge on every
// limit-raise.
else if (vcucmd != VCUCMD_COMPLETE)
state = OFF;
break; break;
} }
+13 -7
View File
@@ -100,7 +100,7 @@ void ChargerCAN::MapMessages(CanMap* can)
can->AddSend(Param::aclim, 0x44c, 16, 16, 1500); can->AddSend(Param::aclim, 0x44c, 16, 16, 1500);
can->AddSend(Param::opmode, 0x44c, 32, 8, 154, 100); can->AddSend(Param::opmode, 0x44c, 32, 8, 154, 100);
/***** SKUDAK VCU command RX (0x212) — SKUDAK-516 chglim + S10 udclim + S11 stop *****/ /***** SKUDAK VCU command RX (0x212) — SKUDAK-516 chglim + S10 udclim + S12 vcucmd *****/
// Byte 0: ChargeLimit_pct (0-100). Param::Change(vcuchglim) translates // Byte 0: ChargeLimit_pct (0-100). Param::Change(vcuchglim) translates
// % to udcspnt setpoint (see src/main.cpp). // % to udcspnt setpoint (see src/main.cpp).
// Bytes 1-2: udclim_V (uint16 LE). DEPRECATED in -S11 but mapping kept for // Bytes 1-2: udclim_V (uint16 LE). DEPRECATED in -S11 but mapping kept for
@@ -111,17 +111,23 @@ void ChargerCAN::MapMessages(CanMap* can)
// contactors, never accumulating 10 ticks > udclim. Defensive // contactors, never accumulating 10 ticks > udclim. Defensive
// clamp in Param::Change(udclim) ignores values < 50 V (would // clamp in Param::Change(udclim) ignores values < 50 V (would
// otherwise turn an old-VCU bench into a never-charges brick). // otherwise turn an old-VCU bench into a never-charges brick).
// Byte 3: vcustop (uint8, NEW in -S11). 0 = no override / normal state // Byte 3: vcucmd (uint8, S12 — was binary vcustop in S11). Three states
// machine. 1 = VCU commands STOP. Checked at the top of // mirror the Dilong OBC_ControlCMD vocabulary 1:1 so VCU code
// EVSEACTIVATE in ChargerStateMachine; transition to STOP fires // paths can be reused across charger families:
// within one 100 ms tick. Mirrors how the Dilong path uses // 0 = Charging — walk to / hold at EVSEACTIVATE, produce current
// OBC_ControlCMD = Stopped to authoritatively halt charging. // 1 = Stopped — sit idle in OFF/WAITSTART/ENABLE, no current
// 2 = Complete — VCU declares cycle done; drop to STOP
// VCU is now authoritative for lifecycle. Self-decided
// EVSEACTIVATE exits (CheckVoltage, CheckTimeout) are gone;
// STOP also exits to OFF when vcucmd flips back from Complete
// to Stopped/Charging so the natural restart path runs (fixes
// the "raise limit mid-COMPLETE doesn't resume" wedge in S11).
// Bytes 4-7: reserved 0x00. // Bytes 4-7: reserved 0x00.
// VCU broadcasts every 200 ms once teslacharger detected; charger holds // VCU broadcasts every 200 ms once teslacharger detected; charger holds
// last received values if VCU goes silent. // last received values if VCU goes silent.
can->AddRecv(Param::vcuchglim, 0x212, 0, 8, 1); can->AddRecv(Param::vcuchglim, 0x212, 0, 8, 1);
can->AddRecv(Param::udclim, 0x212, 8, 16, 1); can->AddRecv(Param::udclim, 0x212, 8, 16, 1);
can->AddRecv(Param::vcustop, 0x212, 24, 8, 1); can->AddRecv(Param::vcucmd, 0x212, 24, 8, 1);
/***** SKUDAK VCU telemetry (0x211) — SKUDAK-448 expanded charger telemetry *****/ /***** SKUDAK VCU telemetry (0x211) — SKUDAK-448 expanded charger telemetry *****/
// Byte 0: state (0=Off, 1=WaitStart, 2=Enable, 3=Activate, 4=Run, 5=Stop) // Byte 0: state (0=Off, 1=WaitStart, 2=Enable, 3=Activate, 4=Run, 5=Stop)