Files
DCU_APP/GD32E508_DCU_APP/device/app_spi_cmd_ping.cpp
T
cbb 86c0ec730b feat(canfd): 添加CANFD发送邮箱占用处理机制
当CAN控制器因总线无ACK导致邮箱卡死时,实现两段式恢复策略:
1) 短自旋轮询邮箱状态,大多数场景下可避免触发abort而不丢帧
2) 若仍全部PENDING则只中止第一个占用邮箱,限制最坏丢帧数量为1帧

添加了tx_abort_count诊断计数器用于监控该情况,并引入SysTick延时功能

refactor(spi-cmd): 优化SPI命令日志输出格式

将CAN发送相关日志改为统一的格式化函数输出,增加数据字段十六进制显示功能,
并扩大日志缓冲区大小从128到256字节以支持更详细的日志信息

chore(spi-command): 添加SPI帧类型分类和非刷写帧日志记录

新增isFlashRelatedFrame函数区分刷写相关帧类型,在处理命令时对非刷写帧进行日志记录

perf(diagnostic): 在诊断打印中添加发送中止计数统计

更新诊断信息打印格式,增加tx_abort计数项,便于监控CAN发送异常情况
2026-06-25 01:11:31 +08:00

56 lines
2.0 KiB
C++

#include "device/spi_command_handler.h"
#include "device/app_spi_command.h"
#include "device/app_spi_command_defs.h"
#include "sys/config.h"
#include "main.h"
#include <cstring>
namespace {
class SpiAppPingHandler final : public ISpiCommandHandler {
public:
bool canHandle(uint8_t frame_type) const override
{
return frame_type == SpiDefs::kTypeAppPing;
}
void handle(AppSpiCommand &bus, const SpiCommandContext &ctx) override
{
uint8_t alive_payload[19];
std::memset(alive_payload, 0, sizeof(alive_payload));
alive_payload[0] = 0xA1U; /* magic */
alive_payload[1] = 0x55U; /* APP version tag */
alive_payload[2] = (uint8_t)APP_FW_VERSION_MAJOR;
alive_payload[3] = (uint8_t)APP_FW_VERSION_MINOR;
alive_payload[4] = (uint8_t)APP_FW_VERSION_PATCH;
alive_payload[5] = (uint8_t)APP_FW_VERSION_BUILD;
alive_payload[6] = 0xAAU; /* BOOT version tag */
const volatile uint32_t *bv0 = (const volatile uint32_t *)CONFIG_BOOT_VERSION_ADDR0;
const volatile uint32_t *bv1 = (const volatile uint32_t *)CONFIG_BOOT_VERSION_ADDR1;
uint32_t bw0 = *bv0;
uint32_t bw1 = *bv1;
alive_payload[7] = (uint8_t)(bw0 & 0xFFU);
alive_payload[8] = (uint8_t)((bw0 >> 16) & 0xFFU);
alive_payload[9] = (uint8_t)(bw1 & 0xFFU);
alive_payload[10] = (uint8_t)((bw1 >> 16) & 0xFFU);
alive_payload[11] = (uint8_t)(g_app_uptime_sec & 0xFFU);
alive_payload[12] = (uint8_t)((g_app_uptime_sec >> 8) & 0xFFU);
alive_payload[13] = (uint8_t)((g_app_uptime_sec >> 16) & 0xFFU);
alive_payload[14] = (uint8_t)((g_app_uptime_sec >> 24) & 0xFFU);
bus.buildResponse(ctx.tx_buf, ctx.tx_buf_size, ctx.tx_len,
SpiDefs::kRspAck, alive_payload, sizeof(alive_payload));
}
};
static SpiAppPingHandler s_handler;
} // namespace
void registerSpiAppPingCommand(AppSpiCommand &bus)
{
bus.registerHandler(&s_handler);
}