forked from achamaikin/CCSModuleSW30Web
Clamp connector current from InfoBlock connector1CurrentLimitA (v1.0.36).
This commit is contained in:
+12
-6
@@ -44,12 +44,18 @@ uint8_t IN_ReadInput(inputNum_t input_n);
|
||||
#define VERSION_OFFSET (0x1E4)
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint32_t serialNumber; // Байты 0-3: серийный номер станции (little-endian)
|
||||
uint8_t stationType; // Байт 4: тип станции
|
||||
uint8_t boardVersion; // Байт 5: версия платы
|
||||
uint8_t addrEdcan; // Байт 6: адрес EDCAN
|
||||
uint8_t maxPower; // Байт 7: максимальная мощность станции (5кВт/bit)
|
||||
uint8_t reserved[56]; // Байты 8-63: зарезервированы
|
||||
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
|
||||
uint16_t connector1CurrentLimitA; // Байты 15-16, A; 0 = legacy PSU_MAX_CURRENT
|
||||
uint8_t reserved[45]; // Байты 17-63
|
||||
} InfoBlock_t;
|
||||
|
||||
extern InfoBlock_t *InfoBlock;
|
||||
|
||||
void Board_LoadInfoBlockLimits(void);
|
||||
uint16_t Board_GetConnectorCurrentLimit_0p1A(void);
|
||||
uint16_t Board_ClampCurrent_0p1A(uint16_t current_0p1A);
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ extern "C" {
|
||||
/* USER CODE BEGIN EC */
|
||||
#define FW_VERSION_MAJOR 1
|
||||
#define FW_VERSION_MINOR 0
|
||||
#define FW_VERSION_PATCH 35
|
||||
#define FW_VERSION_PATCH 36
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
void CCS_SerialLoop(void);
|
||||
void CCS_Init(void);
|
||||
void CCS_UpdateMaxLoadFromInfoBlock(void);
|
||||
void CCS_SendEmergencyStop(void);
|
||||
void CCS_SendStart(void);
|
||||
void CCS_RxEventCallback(UART_HandleTypeDef *huart, uint16_t size);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "board.h"
|
||||
|
||||
#include "charger_config.h"
|
||||
#include "adc.h"
|
||||
#include "main.h"
|
||||
#include "sma_filter.h"
|
||||
@@ -7,6 +8,37 @@
|
||||
|
||||
InfoBlock_t *InfoBlock = (InfoBlock_t *)(VERSION_OFFSET);
|
||||
|
||||
static uint16_t s_connector_max_current_0p1A = (uint16_t)PSU_MAX_CURRENT * 10u;
|
||||
|
||||
static uint16_t Board_ResolveConnectorCurrentLimitA(uint16_t raw_limit_a)
|
||||
{
|
||||
return (raw_limit_a == 0u) ? (uint16_t)PSU_MAX_CURRENT : raw_limit_a;
|
||||
}
|
||||
|
||||
void Board_LoadInfoBlockLimits(void)
|
||||
{
|
||||
const uint16_t limit_a = Board_ResolveConnectorCurrentLimitA(InfoBlock->connector1CurrentLimitA);
|
||||
uint32_t limit_0p1a = (uint32_t)limit_a * 10u;
|
||||
const uint32_t hw_max_0p1a = (uint32_t)PSU_MAX_CURRENT * 10u;
|
||||
|
||||
if (limit_0p1a > hw_max_0p1a) {
|
||||
limit_0p1a = hw_max_0p1a;
|
||||
}
|
||||
|
||||
s_connector_max_current_0p1A = (uint16_t)limit_0p1a;
|
||||
}
|
||||
|
||||
uint16_t Board_GetConnectorCurrentLimit_0p1A(void)
|
||||
{
|
||||
return s_connector_max_current_0p1A;
|
||||
}
|
||||
|
||||
uint16_t Board_ClampCurrent_0p1A(uint16_t current_0p1A)
|
||||
{
|
||||
const uint16_t limit = Board_GetConnectorCurrentLimit_0p1A();
|
||||
return (current_0p1A > limit) ? limit : current_0p1A;
|
||||
}
|
||||
|
||||
uint8_t RELAY_State[RELAY_COUNT];
|
||||
static volatile uint8_t adc_lock = 0;
|
||||
static SMAFilter_t conn_temp_adc_filter[2];
|
||||
|
||||
@@ -214,8 +214,12 @@ int main(void)
|
||||
SC_Init();
|
||||
log_printf(LOG_INFO, "CCS module start\n");
|
||||
ReadVersion();
|
||||
CCS_UpdateMaxLoadFromInfoBlock();
|
||||
log_printf(LOG_INFO, "Serial number: %d\n", infoPacket.serialNumber);
|
||||
log_printf(LOG_INFO, "Board revision: %d\n", infoPacket.boardVersion);
|
||||
log_printf(LOG_INFO, "Connector current limit: %u.%u A\n",
|
||||
(unsigned)(Board_GetConnectorCurrentLimit_0p1A() / 10u),
|
||||
(unsigned)(Board_GetConnectorCurrentLimit_0p1A() % 10u));
|
||||
log_printf(LOG_INFO, "FW version: %d.%d.%d\n", infoPacket.fw_version_major, infoPacket.fw_version_minor, infoPacket.fw_version_patch);
|
||||
CAN1_MinimalReInit();
|
||||
PSU_Init();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "power_setpoint_executor.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "charger_config.h"
|
||||
#include "charger_control.h"
|
||||
#include "debug.h"
|
||||
@@ -39,6 +40,7 @@ void PowerSetpoint_Init(void)
|
||||
void PowerSetpoint_OnCommand(uint16_t voltage_V, uint16_t current_0p1A)
|
||||
{
|
||||
#if PSD_ENABLE
|
||||
current_0p1A = Board_ClampCurrent_0p1A(current_0p1A);
|
||||
pending.voltage_V = voltage_V;
|
||||
pending.current_0p1A = current_0p1A;
|
||||
setpoint_dirty = 1u;
|
||||
|
||||
+9
-3
@@ -381,7 +381,7 @@ void CCS_Init(void){
|
||||
CP_SetDuty(100);
|
||||
CCS_MaxLoad.maxVoltage = PSU_MAX_VOLTAGE; // 1000V
|
||||
CCS_MaxLoad.minVoltage = PSU_MIN_VOLTAGE; //150V
|
||||
CCS_MaxLoad.maxCurrent = PSU_MAX_CURRENT*10; //100A
|
||||
CCS_MaxLoad.maxCurrent = Board_GetConnectorCurrentLimit_0p1A();
|
||||
CCS_MaxLoad.minCurrent = PSU_MIN_CURRENT*10; //1A
|
||||
CCS_MaxLoad.maxPower = PSU_MAX_POWER; //30000W
|
||||
uart3_last_packet_tick = HAL_GetTick();
|
||||
@@ -391,6 +391,11 @@ void CCS_Init(void){
|
||||
log_printf(LOG_INFO, "CCS init\n");
|
||||
}
|
||||
|
||||
void CCS_UpdateMaxLoadFromInfoBlock(void)
|
||||
{
|
||||
CCS_MaxLoad.maxCurrent = Board_GetConnectorCurrentLimit_0p1A();
|
||||
}
|
||||
|
||||
ISR_FAST static uint16_t crc16_ibm(const uint8_t* data, uint16_t length) {
|
||||
uint16_t crc = 0xFFFFu;
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
@@ -549,9 +554,10 @@ ISR_FAST static void apply_command(uint8_t cmd, const uint8_t* payload, uint16_t
|
||||
}
|
||||
case CMD_E2M_SET_OUTPUT_VOLTAGE: {
|
||||
const e2m_set_output_t* p = (const e2m_set_output_t*)payload;
|
||||
const uint16_t clamped_current = Board_ClampCurrent_0p1A(p->current_0p1A);
|
||||
CONN.RequestedVoltage = p->voltage_V;
|
||||
CONN.WantedCurrent = p->current_0p1A;
|
||||
PowerSetpoint_OnCommand(p->voltage_V, p->current_0p1A);
|
||||
CONN.WantedCurrent = clamped_current;
|
||||
PowerSetpoint_OnCommand(p->voltage_V, clamped_current);
|
||||
break;
|
||||
}
|
||||
case CMD_E2M_ISOLATION_CONTROL: {
|
||||
|
||||
@@ -76,6 +76,7 @@ void ReadVersion(){
|
||||
infoPacket.fw_version_major = FW_VERSION_MAJOR;
|
||||
infoPacket.fw_version_minor = FW_VERSION_MINOR;
|
||||
infoPacket.fw_version_patch = FW_VERSION_PATCH;
|
||||
Board_LoadInfoBlockLimits();
|
||||
}
|
||||
|
||||
// Внешняя функция обработки команд (определена в serial_handler.c)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+4384
-4364
File diff suppressed because it is too large
Load Diff
+4384
-4364
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user