Обновление

This commit is contained in:
cfif 2025-12-26 15:45:09 +03:00
parent 2b458113ac
commit 31badb40c3
2 changed files with 94 additions and 53 deletions

View File

@ -10,6 +10,7 @@
#include "LoggerToSerialPort.h" #include "LoggerToSerialPort.h"
#include "CmsisRtosThreadUtils.h" #include "CmsisRtosThreadUtils.h"
#include "SystemMutexCmsis.h" #include "SystemMutexCmsis.h"
#include "VarsTabDumpObserver.h"
#define LOG_XCP 1 #define LOG_XCP 1
@ -106,7 +107,7 @@ typedef struct __attribute__ ((packed)) {
uint8_t reserve5: 1; uint8_t reserve5: 1;
uint8_t reserve6: 1; uint8_t reserve6: 1;
uint8_t reserve7: 1; uint8_t reserve7: 1;
uint8_t SLAVE_BLOCK_MODE: 1; uint8_t _SLAVE_BLOCK_MODE: 1;
uint8_t OPTIONAL: 1; uint8_t OPTIONAL: 1;
uint8_t MAX_CTO_; uint8_t MAX_CTO_;
@ -152,7 +153,7 @@ typedef struct __attribute__ ((packed)) {
uint8_t RESERVED1; uint8_t RESERVED1;
uint8_t MASTER_BLOCK_MODE: 1; uint8_t _MASTER_BLOCK_MODE: 1;
uint8_t INTERLEAVED_MODE: 1; uint8_t INTERLEAVED_MODE: 1;
uint8_t RESERVED2: 6; uint8_t RESERVED2: 6;
@ -221,6 +222,9 @@ typedef struct __attribute__ ((packed)) {
#define SECT_SRAM_XCP __attribute__((section (".xcpdata"))) #define SECT_SRAM_XCP __attribute__((section (".xcpdata")))
#define MASTER_BLOCK_MODE 0
#define SLAVE_BLOCK_MODE 0
#define PROGRAM_MASTER_BLOCK_MODE 1 #define PROGRAM_MASTER_BLOCK_MODE 1
#define PROGRAM_MAX_SECTOR 8 #define PROGRAM_MAX_SECTOR 8
#define PROGRAM_MAX_BUF 256 #define PROGRAM_MAX_BUF 256
@ -465,13 +469,13 @@ typedef struct __attribute__ ((packed)) {
eXcpTypeCommand COM; eXcpTypeCommand COM;
uint8_t RESERVED1; uint8_t RESERVED1;
uint8_t MASTER_BLOCK_MODE: 1; uint8_t _MASTER_BLOCK_MODE: 1;
uint8_t INTERLEAVED_MODE: 1; uint8_t INTERLEAVED_MODE: 1;
uint8_t RESERVED2: 1; uint8_t RESERVED2: 1;
uint8_t RESERVED3: 1; uint8_t RESERVED3: 1;
uint8_t RESERVED4: 1; uint8_t RESERVED4: 1;
uint8_t RESERVED5: 1; uint8_t RESERVED5: 1;
uint8_t SLAVE_BLOCK_MODE: 1; uint8_t _SLAVE_BLOCK_MODE: 1;
uint8_t RESERVED6: 1; uint8_t RESERVED6: 1;
uint8_t MAX_CTO_PGM; uint8_t MAX_CTO_PGM;
@ -548,6 +552,14 @@ typedef struct __attribute__ ((packed)) {
} eXcpCommand_SET_CALIBRATION_PAGE_EB; } eXcpCommand_SET_CALIBRATION_PAGE_EB;
typedef struct __attribute__ ((packed)) {
eXcpTypeCommand COM;
uint8_t VERIFICATION_MODE;
uint16_t VERIFICATION_TYPE;
uint32_t VERIFICATION_VALUE;
} eXcpCommand_Program_Verify_C8;
typedef bool (xcp_clear_flash_func)(uint32_t firstPageAddr, uint32_t totalSize); typedef bool (xcp_clear_flash_func)(uint32_t firstPageAddr, uint32_t totalSize);
typedef bool (xcp_write_flash_func)(uint32_t beginPageAddr, void *sourceRamAddr, uint32_t size); typedef bool (xcp_write_flash_func)(uint32_t beginPageAddr, void *sourceRamAddr, uint32_t size);
@ -555,8 +567,9 @@ typedef bool (xcp_write_flash_func)(uint32_t beginPageAddr, void *sourceRamAddr,
typedef struct { typedef struct {
tSerialPortFrameIO *ioCanFrame; tSerialPortFrameIO *ioCanFrame;
tLoggerInterface *logger; tLoggerInterface *logger;
tVarsTabDumpObserver *varsTabDumpObserver;
uint8_t RND; uint8_t RESOURCE;
uint8_t ADR_EXT; uint8_t ADR_EXT;
uint32_t ADR_MTA; uint32_t ADR_MTA;
@ -619,6 +632,7 @@ void CanSerialPortFrameXcpInit(
uint32_t endFlashAdr, uint32_t endFlashAdr,
xcp_clear_flash_func *clear_flash_func, xcp_clear_flash_func *clear_flash_func,
xcp_write_flash_func *write_flash_func, xcp_write_flash_func *write_flash_func,
tVarsTabDumpObserver *varsTabDumpObserver,
tLoggerInterface *logger tLoggerInterface *logger
); );

View File

@ -87,10 +87,13 @@ void CanSerialPortFrameXcpInit(
uint32_t endFlashAdr, uint32_t endFlashAdr,
xcp_clear_flash_func *clear_flash_func, xcp_clear_flash_func *clear_flash_func,
xcp_write_flash_func *write_flash_func, xcp_write_flash_func *write_flash_func,
tVarsTabDumpObserver *varsTabDumpObserver,
tLoggerInterface *logger tLoggerInterface *logger
) { ) {
env->DAQ = DAQ; env->DAQ = DAQ;
env->varsTabDumpObserver = varsTabDumpObserver;
env->ioCanFrame = ioCanFrame; env->ioCanFrame = ioCanFrame;
env->rtcIO = rtcIO; env->rtcIO = rtcIO;
@ -125,7 +128,7 @@ static uint8_t XCP_COMMAND_CONNECT_FF(tCanSerialPortFrameXCP *env) {
xcpCommand_CONNECT->COM = XCP_COMMAND_CONNECT; xcpCommand_CONNECT->COM = XCP_COMMAND_CONNECT;
xcpCommand_CONNECT->CAL_PAG = 0; // Калибровка и пагинация xcpCommand_CONNECT->CAL_PAG = 1; // Калибровка и пагинация
xcpCommand_CONNECT->reserve1 = 0; xcpCommand_CONNECT->reserve1 = 0;
xcpCommand_CONNECT->DAQ = 1; // Поддержка DAQ xcpCommand_CONNECT->DAQ = 1; // Поддержка DAQ
xcpCommand_CONNECT->STIM = 1; // Стимуляция (формирование инициативных запросов) xcpCommand_CONNECT->STIM = 1; // Стимуляция (формирование инициативных запросов)
@ -140,7 +143,7 @@ static uint8_t XCP_COMMAND_CONNECT_FF(tCanSerialPortFrameXCP *env) {
xcpCommand_CONNECT->reserve5 = 0; xcpCommand_CONNECT->reserve5 = 0;
xcpCommand_CONNECT->reserve6 = 0; xcpCommand_CONNECT->reserve6 = 0;
xcpCommand_CONNECT->reserve7 = 0; xcpCommand_CONNECT->reserve7 = 0;
xcpCommand_CONNECT->SLAVE_BLOCK_MODE = 1; // Блочный режим не поддерживается xcpCommand_CONNECT->_SLAVE_BLOCK_MODE = SLAVE_BLOCK_MODE; // Блочный режим не поддерживается
xcpCommand_CONNECT->OPTIONAL = 1; // Поддержка команды XCP_COMMAND_GET_STATUS xcpCommand_CONNECT->OPTIONAL = 1; // Поддержка команды XCP_COMMAND_GET_STATUS
xcpCommand_CONNECT->MAX_CTO_ = MAX_CTO; xcpCommand_CONNECT->MAX_CTO_ = MAX_CTO;
@ -184,7 +187,7 @@ static uint8_t XCP_COMMAND_GET_STATUS_FD(tCanSerialPortFrameXCP *env) {
xcpCommand_GET_STATUS->reserve7 = 0; xcpCommand_GET_STATUS->reserve7 = 0;
xcpCommand_GET_STATUS->reserve8 = 0; xcpCommand_GET_STATUS->reserve8 = 0;
xcpCommand_GET_STATUS->STATE_NUMBER = 0; xcpCommand_GET_STATUS->STATE_NUMBER = 2;
xcpCommand_GET_STATUS->SESSION_CONFIGURATION_ID = 0; xcpCommand_GET_STATUS->SESSION_CONFIGURATION_ID = 0;
@ -204,7 +207,7 @@ static uint8_t XCP_GET_COMM_MODE_INFO_FB(tCanSerialPortFrameXCP *env) {
xcpCommand_GET_COMM_MODE_INFO->RESERVED1 = 0; xcpCommand_GET_COMM_MODE_INFO->RESERVED1 = 0;
xcpCommand_GET_COMM_MODE_INFO->MASTER_BLOCK_MODE = 0; xcpCommand_GET_COMM_MODE_INFO->_MASTER_BLOCK_MODE = MASTER_BLOCK_MODE;
xcpCommand_GET_COMM_MODE_INFO->INTERLEAVED_MODE = 0; xcpCommand_GET_COMM_MODE_INFO->INTERLEAVED_MODE = 0;
xcpCommand_GET_COMM_MODE_INFO->RESERVED2 = 0; xcpCommand_GET_COMM_MODE_INFO->RESERVED2 = 0;
@ -224,8 +227,7 @@ static uint8_t XCP_GET_SEED_F8(tCanSerialPortFrameXCP *env) {
xcpCommand_GET_SEED->COM = XCP_COMMAND_CONNECT; xcpCommand_GET_SEED->COM = XCP_COMMAND_CONNECT;
xcpCommand_GET_SEED->LEN = 4; xcpCommand_GET_SEED->LEN = 4;
xcpCommand_GET_SEED->KEY = 0x11223344; xcpCommand_GET_SEED->KEY = 0x11223344;
env->RESOURCE = request->RESOURCE;
env->RND = request->RESOURCE;
return 6; return 6;
} }
@ -233,7 +235,7 @@ static uint8_t XCP_GET_SEED_F8(tCanSerialPortFrameXCP *env) {
static uint8_t XCP_UNLOCK_F7(tCanSerialPortFrameXCP *env) { static uint8_t XCP_UNLOCK_F7(tCanSerialPortFrameXCP *env) {
eXcpCommand_REQ_UNLOCK *request = (eXcpCommand_REQ_UNLOCK *) env->canFrame.data; eXcpCommand_REQ_UNLOCK *request = (eXcpCommand_REQ_UNLOCK *) env->canFrame.data;
uint32_t securitySeedMy = SeedToKeyHVAC_NAMI(env->RND, 0x11223344); uint32_t securitySeedMy = SeedToKeyHVAC_NAMI(0, 0x11223344);
if (securitySeedMy != request->KEY) { if (securitySeedMy != request->KEY) {
env->response[0] = XCP_COMMAND_DISCONNECT; env->response[0] = XCP_COMMAND_DISCONNECT;
@ -276,48 +278,56 @@ static uint8_t XCP_COMMAND_UPLOAD_F5(tCanSerialPortFrameXCP *env) {
env->response[0] = XCP_COMMAND_CONNECT; env->response[0] = XCP_COMMAND_CONNECT;
if (request->COUNT == 0) {
if (SLAVE_BLOCK_MODE) {
if (request->COUNT == 0) {
#if (LOG_XCP == 1) #if (LOG_XCP == 1)
PrintfDebug(env->response, 1); PrintfDebug(env->response, 1);
LoggerFormatInfo(LOGGER, LOG_SIGN, "< [%d] %s", 1, strPrintfDebug) LoggerFormatInfo(LOGGER, LOG_SIGN, "< [%d] %s", 1, strPrintfDebug)
#endif #endif
env->ioCanFrame->transmit(env->ioCanFrame->env, env->response, 1, PROTOCOL_CAN_ADR_XCP, env->ioCanFrame->transmit(env->ioCanFrame->env, env->response, 1, PROTOCOL_CAN_ADR_XCP,
PROTOCOL_CAN_TYPE_XCP, PROTOCOL_CAN_TYPE_XCP,
1000); 1000);
return 0;
}
uint8_t fullBlock = request->COUNT / 7;
uint8_t tailBlock = request->COUNT % 7;
for (uint8_t i = 0; i < fullBlock; ++i) {
memcpy(&env->response[1], (uint8_t *) (env->ADR_MTA), request->COUNT);
env->ADR_MTA += 7;
#if (LOG_XCP == 1)
PrintfDebug(env->response, 7 + 1);
LoggerFormatInfo(LOGGER, LOG_SIGN, "< [%d] %s", 7 + 1, strPrintfDebug)
#endif
env->ioCanFrame->transmit(env->ioCanFrame->env, env->response, 7 + 1, PROTOCOL_CAN_ADR_XCP,
PROTOCOL_CAN_TYPE_XCP,
1000);
}
if (tailBlock > 0) {
memcpy(&env->response[1], (uint8_t *) (env->ADR_MTA), tailBlock);
env->ADR_MTA += tailBlock;
#if (LOG_XCP == 1)
PrintfDebug(env->response, tailBlock + 1);
LoggerFormatInfo(LOGGER, LOG_SIGN, "< [%d] %s", tailBlock + 1, strPrintfDebug)
#endif
env->ioCanFrame->transmit(env->ioCanFrame->env, env->response, tailBlock + 1, PROTOCOL_CAN_ADR_XCP,
PROTOCOL_CAN_TYPE_XCP, 1000);
}
return 0; return 0;
} } else {
uint8_t fullBlock = request->COUNT / 7;
uint8_t tailBlock = request->COUNT % 7;
for (uint8_t i = 0; i < fullBlock; ++i) {
memcpy(&env->response[1], (uint8_t *) (env->ADR_MTA), request->COUNT); memcpy(&env->response[1], (uint8_t *) (env->ADR_MTA), request->COUNT);
env->ADR_MTA += 7; env->ADR_MTA += request->COUNT;
#if (LOG_XCP == 1) return request->COUNT + 1;
PrintfDebug(env->response, 7 + 1);
LoggerFormatInfo(LOGGER, LOG_SIGN, "< [%d] %s", 7 + 1, strPrintfDebug)
#endif
env->ioCanFrame->transmit(env->ioCanFrame->env, env->response, 7 + 1, PROTOCOL_CAN_ADR_XCP,
PROTOCOL_CAN_TYPE_XCP,
1000);
} }
if (tailBlock > 0) {
memcpy(&env->response[1], (uint8_t *) (env->ADR_MTA), tailBlock);
env->ADR_MTA += tailBlock;
#if (LOG_XCP == 1)
PrintfDebug(env->response, tailBlock + 1);
LoggerFormatInfo(LOGGER, LOG_SIGN, "< [%d] %s", tailBlock + 1, strPrintfDebug)
#endif
env->ioCanFrame->transmit(env->ioCanFrame->env, env->response, tailBlock + 1, PROTOCOL_CAN_ADR_XCP,
PROTOCOL_CAN_TYPE_XCP, 1000);
}
return 0;
} }
static uint8_t XCP_COMMAND_SHORT_UPLOAD_F4(tCanSerialPortFrameXCP *env) { static uint8_t XCP_COMMAND_SHORT_UPLOAD_F4(tCanSerialPortFrameXCP *env) {
@ -751,13 +761,13 @@ static uint8_t XCP_PROGRAM_START_D2(tCanSerialPortFrameXCP *env) {
response->COM = XCP_COMMAND_CONNECT; response->COM = XCP_COMMAND_CONNECT;
response->RESERVED1 = 0; response->RESERVED1 = 0;
response->MASTER_BLOCK_MODE = PROGRAM_MASTER_BLOCK_MODE; response->_MASTER_BLOCK_MODE = PROGRAM_MASTER_BLOCK_MODE;
response->INTERLEAVED_MODE = 0; response->INTERLEAVED_MODE = 0;
response->RESERVED2 = 0; response->RESERVED2 = 0;
response->RESERVED3 = 0; response->RESERVED3 = 0;
response->RESERVED4 = 0; response->RESERVED4 = 0;
response->RESERVED5 = 0; response->RESERVED5 = 0;
response->SLAVE_BLOCK_MODE = 1; response->_SLAVE_BLOCK_MODE = SLAVE_BLOCK_MODE;
response->RESERVED6 = 0; response->RESERVED6 = 0;
response->MAX_CTO_PGM = 8; response->MAX_CTO_PGM = 8;
@ -820,6 +830,22 @@ static uint8_t XCP_PROGRAM_D0(tCanSerialPortFrameXCP *env) {
return 1; return 1;
} }
static uint8_t PROGRAM_VERIFY_C8(tCanSerialPortFrameXCP *env) {
eXcpCommand_Program_Verify_C8 *request = (eXcpCommand_Program_Verify_C8 *) env->canFrame.data;
if (env->bufWriteFlashCount > 0) {
bool result = env->write_flash_func(env->bufWriteFlashAdr, env->bufWriteFlash, env->bufWriteFlashCount);
env->bufWriteFlashCount = 0;
}
VarsTabDumpObserverCalib_Load(env->varsTabDumpObserver);
env->response[0] = XCP_COMMAND_CONNECT;
return 1;
}
static uint8_t XCP_PROGRAM_NEXT_CA(tCanSerialPortFrameXCP *env) { static uint8_t XCP_PROGRAM_NEXT_CA(tCanSerialPortFrameXCP *env) {
eXcpCommand_Program_ProgramNext_D0_CA *request = (eXcpCommand_Program_ProgramNext_D0_CA *) env->canFrame.data; eXcpCommand_Program_ProgramNext_D0_CA *request = (eXcpCommand_Program_ProgramNext_D0_CA *) env->canFrame.data;
@ -837,6 +863,7 @@ static uint8_t XCP_PROGRAM_RESET_CF(tCanSerialPortFrameXCP *env) {
if (env->bufWriteFlashCount > 0) { if (env->bufWriteFlashCount > 0) {
bool result = env->write_flash_func(env->bufWriteFlashAdr, env->bufWriteFlash, env->bufWriteFlashCount); bool result = env->write_flash_func(env->bufWriteFlashAdr, env->bufWriteFlash, env->bufWriteFlashCount);
env->bufWriteFlashCount = 0;
} }
return 1; return 1;
@ -1110,7 +1137,7 @@ const eXcp_com xcp_com[256] = {
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {NULL, ""},
{NULL, ""}, {PROGRAM_VERIFY_C8, "PROGRAM_VERIFY_C8"},
{NULL, ""}, {NULL, ""},
{XCP_PROGRAM_NEXT_CA, "XCP_PROGRAM_NEXT_CA"}, {XCP_PROGRAM_NEXT_CA, "XCP_PROGRAM_NEXT_CA"},
{NULL, ""}, {NULL, ""},
@ -1185,7 +1212,7 @@ uint8_t vCanSerialPortFrameXcpReceive(tCanSerialPortFrameXCP *env, uint32 timeou
if (com > 0xBF) { // CMD if (com > 0xBF) { // CMD
#if (LOG_XCP == 1) #if (LOG_XCP == 1)
if (com != 0xD0) { if ((com != 0xD0) && (com != 0xF5)) {
PrintfDebug(env->canFrame.data, env->canFrame.dlc); PrintfDebug(env->canFrame.data, env->canFrame.dlc);
LoggerFormatInfo(LOGGER, LOG_SIGN, "> %s [%d] %s", xcp_com[com].desc, env->canFrame.dlc, strPrintfDebug) LoggerFormatInfo(LOGGER, LOG_SIGN, "> %s [%d] %s", xcp_com[com].desc, env->canFrame.dlc, strPrintfDebug)
} }
@ -1194,10 +1221,10 @@ uint8_t vCanSerialPortFrameXcpReceive(tCanSerialPortFrameXCP *env, uint32 timeou
response_size = xcp_com[com].func(env); response_size = xcp_com[com].func(env);
if ((response_size) && (env->response[0] != 0xF5)) { if (response_size) {
#if (LOG_XCP == 1) #if (LOG_XCP == 1)
if (com != 0xD0) { if ((com != 0xD0) && (com != 0xF5)) {
PrintfDebug(env->response, response_size); PrintfDebug(env->response, response_size);
LoggerFormatInfo(LOGGER, LOG_SIGN, "< [%d] %s", response_size, strPrintfDebug) LoggerFormatInfo(LOGGER, LOG_SIGN, "< [%d] %s", response_size, strPrintfDebug)
} }