Add TonHe 30kW PSU control with LV/HV restart (v1.0.37).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
raduet
2026-09-23 14:05:53 +02:00
co-authored by Cursor
parent 644fcf1692
commit 10691b77f2
15 changed files with 10132 additions and 8832 deletions
+27 -9
View File
@@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include "charger_config.h"
typedef enum{
RELAY_AUX0 = 0,
@@ -40,22 +41,39 @@ typedef enum{
uint8_t IN_ReadInput(inputNum_t input_n);
// Версия устройства
#define VERSION_OFFSET (0x1E4)
// ConfigBlock: new bootloader at 0x08007800, legacy at 0x080001E4
#define VERSION_OFFSET (0x08007800u)
#define VERSION_OFFSET_LEGACY (0x080001E4u)
typedef struct __attribute__((packed)) {
uint32_t serialNumber; // Байты 0-3
uint8_t stationType; // Байт 4
uint8_t boardVersion; // Байт 5
uint8_t addrEdcan; // Байт 6
uint8_t maxPower; // Байт 7
uint8_t pad[7]; // bytes 8-14, see edcan.h
uint32_t serialNumber; // Байты 0-3
uint8_t stationType; // Байт 4
uint8_t boardVersion; // Байт 5
uint8_t addrEdcan; // Байт 6
uint8_t contactorConfig; // Байт 7
uint8_t connectorConfig; // Байт 8
uint8_t maxPower; // Байт 9, 5 кВт/bit
uint8_t psuType; // Байт 10
uint8_t meterType; // Байт 11
uint8_t balancerType; // Байт 12
uint8_t autostartMode; // Байт 13
uint8_t motorEnable; // Байт 14
uint16_t connector1CurrentLimitA; // Байты 15-16, A; 0 = legacy PSU_MAX_CURRENT
uint8_t reserved[45]; // Байты 17-63
uint16_t connector2CurrentLimitA; // Байты 17-18
uint16_t connector3CurrentLimitA; // Байты 19-20
uint8_t reserved[43]; // Байты 21-63
} InfoBlock_t;
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
_Static_assert(sizeof(InfoBlock_t) == 64, "InfoBlock_t must be 64 bytes");
#endif
extern InfoBlock_t *InfoBlock;
void Board_SelectInfoBlockAddress(void);
void Board_LoadInfoBlockLimits(void);
uint16_t Board_GetConnectorCurrentLimit_0p1A(void);
uint16_t Board_ClampCurrent_0p1A(uint16_t current_0p1A);
PsuType_t Board_GetPsuType(void);
uint16_t Board_GetPsuMaxCurrentA(void);
uint32_t Board_GetPsuMaxPowerW(void);
+17 -1
View File
@@ -7,8 +7,21 @@
#define PSU_MIN_CURRENT 1 //1A/bit
#define PSU_MAX_POWER 40000 //1W/bit
#define PSU_BLOCK_POWER_30KW 30000u
#define PSU_BLOCK_POWER_40KW 40000u
#define PSU_BLOCK_CURRENT_30KW 100u
#define PSU_BLOCK_CURRENT_40KW 133u
#define PSU_NUM 1
/* Values match bootloader-flasher firmwares.json psuTypes[].value (InfoBlock byte 10). */
typedef enum {
PSU_TYPE_NONE = 0,
PSU_TYPE_NIUERA_30KW = 1,
PSU_TYPE_NIUERA_40KW = 2,
PSU_TYPE_TONHE_30KW = 3
} PsuType_t;
/* Dynamic LV clamp (CS60 hv_limit): active only on overload at low bus voltage. */
#define PSU_LV_CLAMP_V 499u
#define PSU_HV_LIMIT_ON_THRESHOLD 480u
@@ -17,7 +30,10 @@
#define PSU_HV_LOAD_CURRENT 300u /* 30.0 A, MeasuredCurrent is 0.1 A/bit */
#define PSU_HV_LIMIT_MAX_COUNT 3u
/* Fast discharge: PSU off/on cycle on step-down setpoint (unloaded bus). */
/* TonHe group start: ≤500 V = LV, >500 V = HV. LV→HV while ON dies; HV→LV stays ON. */
#define TONHE_HV_THRESHOLD_V 500u
/* Fast discharge: Niuera off/on cycle on step-down (unloaded bus). TonHe skips this. */
#define PSD_ENABLE 1u
#define PSD_MAX_CMD_CURRENT_0P1A 20u /* 2.0 A */
#define PSD_MAX_MEASURED_CURRENT_0P1A 30u /* 3.0 A */
+1 -1
View File
@@ -27,7 +27,7 @@ extern "C" {
/* USER CODE BEGIN EC */
#define FW_VERSION_MAJOR 1
#define FW_VERSION_MINOR 0
#define FW_VERSION_PATCH 36
#define FW_VERSION_PATCH 37
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
+1
View File
@@ -7,6 +7,7 @@ void PSU_Init();
void PSU_Enable(uint8_t addr, uint8_t enable);
void PSU_SetVoltageCurrent(uint8_t addr, uint16_t voltage, uint16_t current);
void PSU_ReadWrite(void);
PsuType_t PSU_GetType(void);
// --- Состояние силового модуля (DC30, один PSU) ---