fix(esc_lan9252): 修复LAN9252 HBI访问模型和IRQ输出使能问题
- 修正HBI访问模型:将ESC核心CSR(0x0000-0x0FFF)改为通过ECAT_CSR_CMD/DATA 间接端口访问,解决此前直接寻址导致核心寄存器恒读0/写丢弃的问题 - 新增csrRead/csrWrite/pramRead/pramWrite接口,正确实现LAN9252访问端口操作 - 添加PDI就绪检测:等待DL_STATUS bit0置位确认EEPROM加载完成和EtherCAT核心使能 - 实现IRQ引脚输出使能:配置IRQ_CFG和INT_EN寄存器,使EtherCAT事件能到达PB1, 解决PDI_Isr未触发导致SAFEOP->OP无限挂起的问题 - 为ESC_EXMC硬件诊断添加CONFIG_ESC_EXMC_DIAG门控,默认关闭避免影响正常运行 - 修正system_gd32e50x.c中HXTAL故障诊断的寄存器偏移和位设置错
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file app_spi_cmd_init_status.cpp
|
||||
* @brief SPI 0xA3 INIT_STATUS 命令:向 ESP32 上报 APP 初始化状态(1.5.34 新增,1.5.35 扩展故障码)。
|
||||
*
|
||||
* 响应 ACK 25B 布局(与 app_spi_command_defs.h kTypeInitStatus 注释一致):
|
||||
* [0..3] module_mask LE AppInitializer::ModuleBit 成功位图
|
||||
* [4..7] critical_fail_mask LE 失败的 critical 模块位图(0=无 critical 失败)
|
||||
* [8] reset_cause ResetCauseBit 复位源位图
|
||||
* [9] init_state 0=OK 1=degraded 2=critical_fail
|
||||
* [10..11] reserved (0)
|
||||
* [12..24] fault_codes[13] 每模块 1B 故障码(0=成功;编码见 sys/initial.h,
|
||||
* canfd 高 4 位为首个失败通道号)
|
||||
* 1.5.34 只回前 12B;ESP32 按 resp_len≥25 判定故障码数组是否存在,前后兼容。
|
||||
*/
|
||||
|
||||
#include "device/spi/spi_command_handler.h"
|
||||
#include "device/spi/app_spi_command.h"
|
||||
#include "device/spi/app_spi_command_defs.h"
|
||||
#include "sys/initial.h"
|
||||
|
||||
namespace {
|
||||
|
||||
/** @brief 0xA3 响应 payload 长度(12B 基础 + 13B 故障码)。 */
|
||||
static constexpr size_t kInitStatusLen = 12U + 13U;
|
||||
|
||||
/** @brief SPI 0xA3 INIT_STATUS 处理器:应答初始化状态 25B。 */
|
||||
class SpiInitStatusHandler final : public ISpiCommandHandler {
|
||||
public:
|
||||
/** @brief 是否处理该帧类型。 */
|
||||
bool canHandle(uint8_t frame_type) const override
|
||||
{
|
||||
return frame_type == SpiDefs::kTypeInitStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 处理 INIT_STATUS:填充初始化状态与模块故障码并回 0x80。
|
||||
* @param bus 命令总线
|
||||
* @param ctx 请求上下文
|
||||
*/
|
||||
void handle(AppSpiCommand &bus, const SpiCommandContext &ctx) override
|
||||
{
|
||||
uint8_t payload[kInitStatusLen] = {0U};
|
||||
writeU32Le(&payload[0], AppInitializer::moduleMask());
|
||||
writeU32Le(&payload[4], AppInitializer::criticalFailMask());
|
||||
payload[8] = AppInitializer::resetCause();
|
||||
payload[9] = AppInitializer::initState();
|
||||
AppInitializer::faultCodes(&payload[12]);
|
||||
bus.buildResponse(ctx.tx_buf, ctx.tx_buf_size, ctx.tx_len,
|
||||
SpiDefs::kRspAck, payload, sizeof(payload));
|
||||
}
|
||||
};
|
||||
|
||||
static SpiInitStatusHandler s_handler;
|
||||
|
||||
} // namespace
|
||||
|
||||
/** @brief 注册 0xA3 INIT_STATUS 命令处理器。 */
|
||||
void registerSpiInitStatusCommand(AppSpiCommand &bus)
|
||||
{
|
||||
bus.registerHandler(&s_handler);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "device/spi/app_spi_command.h"
|
||||
#include "device/spi/app_spi_command_defs.h"
|
||||
#include "sys/config.h"
|
||||
#include "sys/initial.h"
|
||||
#include "sys/ota_boot_request.h"
|
||||
#include "sys/systick.h"
|
||||
#include "main.h"
|
||||
@@ -68,7 +69,10 @@ void fillGd32AppIdentityPayload(uint8_t *out)
|
||||
|
||||
out[12] = V2_FEAT_MAP_VER;
|
||||
writeU16Le(&out[13], buildAppFeatureFlags());
|
||||
/* [15] reserved = 0 */
|
||||
/* [15] init_state(1.5.34 起):0=OK 1=degraded 2=critical_fail。
|
||||
* 复用原 reserved 字节——旧 ESP32 忽略该字节、旧 GD32 恒 0(恰与 OK 同义),
|
||||
* 因此不 bump feat_map_ver 即前后兼容;详情经 0xA3 INIT_STATUS 查询。 */
|
||||
out[15] = AppInitializer::initState();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -382,6 +382,7 @@ void AppSpiCommand::configureExti()
|
||||
extern void registerSpiBootRequestCommand(AppSpiCommand &bus);
|
||||
extern void registerSpiOtaWaitCommand(AppSpiCommand &bus);
|
||||
extern void registerSpiAppPingCommand(AppSpiCommand &bus);
|
||||
extern void registerSpiInitStatusCommand(AppSpiCommand &bus);
|
||||
extern void registerSpiCanBridgeCommand(AppSpiCommand &bus);
|
||||
extern void registerSpiCanBurstCommand(AppSpiCommand &bus);
|
||||
extern void registerSpiCanFeedbackCommand(AppSpiCommand &bus);
|
||||
@@ -407,6 +408,7 @@ void AppSpiCommand::init()
|
||||
registerSpiBootRequestCommand(AppSpiCommandBus);
|
||||
registerSpiOtaWaitCommand(AppSpiCommandBus);
|
||||
registerSpiAppPingCommand(AppSpiCommandBus);
|
||||
registerSpiInitStatusCommand(AppSpiCommandBus);
|
||||
registerSpiCanBridgeCommand(AppSpiCommandBus);
|
||||
registerSpiCanBurstCommand(AppSpiCommandBus);
|
||||
registerSpiCanFeedbackCommand(AppSpiCommandBus);
|
||||
|
||||
@@ -23,6 +23,15 @@ static constexpr uint8_t kTypeAppPing = 0xA1U;
|
||||
* 0=stop(恢复AF_PP), 1-4=数据pattern(0xFFFF/0x0000/0xAAAA/0x5555),
|
||||
* 5=CS低, 6=RD低, 7=WR低, 8=A1高, 9=A2高。用于 LAN9252 通断测试。 */
|
||||
static constexpr uint8_t kTypeExmcDiag = 0xA2U;
|
||||
/** @brief APP 初始化状态查询(ESP32→GD32,1.5.34 新增):无 payload。
|
||||
* 响应 ACK 25B(1.5.35 起;1.5.34 仅前 12B):
|
||||
* [0..3] module_mask LE(AppInitializer::ModuleBit 成功位图)
|
||||
* [4..7] critical_fail_mask LE(失败的 critical 模块位图,0=无)
|
||||
* [8] reset_cause(ResetCauseBit 位图) [9] init_state(0=OK 1=degraded 2=critical_fail)
|
||||
* [10..11] reserved
|
||||
* [12..24] fault_codes[13](每模块 1B 故障码,0=成功;编码见 sys/initial.h,
|
||||
* canfd = 原因码|(首个失败通道<<4))。位定义与 sys/initial.h 一致。 */
|
||||
static constexpr uint8_t kTypeInitStatus = 0xA3U;
|
||||
static constexpr uint8_t kTypeBootReq = 0xB0U;
|
||||
static constexpr uint8_t kTypeCanSend = 0xC0U;
|
||||
static constexpr uint8_t kTypeCanFeedback = 0xC1U; /**< ESP32 -> GD32 轮询 CAN 反馈快照 */
|
||||
|
||||
Reference in New Issue
Block a user