feat(device_exmc): 添加GD32E508 EXMC外设支持用于LAN9252通信
添加EXMC 16-bit并行总线驱动实现,用于LAN9252 ESC通信。 在cproject.yml中添加device_exmc组和相关源文件,包括 gd32e50x_exmc.c/h文件,并更新头文件搜索路径。 由于GigaDevice DFP未将EXMC注册为CMSIS组件,需要本地编入 RTE/Device目录下的EXMC源文件以支持LAN9252并行总线功能。 fix(canfd): 优化CANFD驱动中的条件编译和DLC处理逻辑 将CANFD相关的配置项从硬编码改为使用sys/config.h中的配置。 添加对DLC=0情况的支持(表示无数据负载的远程帧), 修正了数据长度检查逻辑,确保DLC为0时不需要提供数据指针。 同时重构了调试代码的条件编译,使用CONFIG_CAN_STARTUP_DIAG_VERBOSE 等配置开关控制调试输出函数的编译。 refactor(ethercat): 统一配置项管理,移除硬编码常量 将EtherCAT相关配置项从硬编码改为统一的sys/config.h配置, 提升代码可维护性。 docs(spi): 更新SPI命令响应缓冲区大小说明 更新CAN桥接和ID快照命令的响应payload大小计算说明, 统一使用AppSpiCommand::kTxBufSize - V2_OVERHEAD作为上限。
This commit is contained in:
@@ -45,7 +45,8 @@ public:
|
||||
|
||||
void handle(AppSpiCommand &bus, const SpiCommandContext &ctx) override
|
||||
{
|
||||
if (ctx.payload_len < 6U) {
|
||||
/* 最短 5 字节:ch(1)+id(4);DLC=0(如 CANFD_BOOT)合法,勿再要求 ≥6 */
|
||||
if (ctx.payload_len < 5U) {
|
||||
#if (CONFIG_SPI_APP_LOG_ENABLE != 0)
|
||||
char log_msg[AppSpiCommand::kLogBufSize] = {};
|
||||
(void)snprintf(log_msg, sizeof(log_msg),
|
||||
@@ -64,8 +65,8 @@ public:
|
||||
| (static_cast<uint32_t>(ctx.payload[2]) << 16)
|
||||
| (static_cast<uint32_t>(ctx.payload[3]) << 8)
|
||||
| static_cast<uint32_t>(ctx.payload[4]);
|
||||
const uint8_t *can_data = &ctx.payload[5];
|
||||
const uint8_t can_dlc = static_cast<uint8_t>(ctx.payload_len - 5U);
|
||||
const uint8_t *can_data = (can_dlc > 0U) ? &ctx.payload[5] : nullptr;
|
||||
|
||||
if (can_ch >= 3U) {
|
||||
postCanSendLog(bus, "ERROR(channel)", can_ch, can_id, can_data, can_dlc);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* 请求 payload:
|
||||
* [0] channel 0/1/2
|
||||
* [1] page 页号(0 = 条目 0~7,1 = 条目 8~15)
|
||||
* 应答 payload(变长,最大 kTxBufSize - overhead = 123 字节):
|
||||
* 应答 payload(变长;上限 = AppSpiCommand::kTxBufSize - V2_OVERHEAD = 256-20 = 236):
|
||||
* [0] channel
|
||||
* [1] page
|
||||
* [2] total_count 该通道当前条目总数
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "device/canfd.h"
|
||||
#include "sys/config.h"
|
||||
#include "sys/ota_boot_request.h"
|
||||
#include "spi_link_v2.h"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
@@ -46,7 +47,9 @@
|
||||
* 全局作用域的 canFeedbackPushStep() 共同复用) ---- */
|
||||
|
||||
static constexpr uint8_t kFeedbackChannelCount = 3U;
|
||||
static constexpr uint16_t kFeedbackPayloadLen = 123U; /* kTxBufSize=128 - overhead=5 */
|
||||
/* 业务 payload 上限:APP TX 缓冲 256 - v2 帧开销 20 = 236(与 ESP32 kFeedbackPayloadLen 一致) */
|
||||
static constexpr uint16_t kFeedbackPayloadLen =
|
||||
static_cast<uint16_t>(AppSpiCommand::kTxBufSize - V2_OVERHEAD);
|
||||
static constexpr uint8_t kPageEntries = 8U;
|
||||
static constexpr uint16_t kFixedHeaderLen = 28U; /* ch(1)+page(1)+total(1)+cnt(1)+mode(1)+seq(4)+rx(4)+tx(4)+drop(4)+err(4)+tec(1)+rec(1)+bus_state(1) */
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
* [0] channel 0/1/2
|
||||
* [1] page 页号(0 = 条目 0~7,1 = 条目 8~15)
|
||||
*
|
||||
* 应答 payload(变长,最大 kTxBufSize - 5 = 123 字节):
|
||||
* 应答 payload(变长;上限 = AppSpiCommand::kTxBufSize - V2_OVERHEAD = 256-20 = 236):
|
||||
* [0] channel
|
||||
* [1] page
|
||||
* [2] total_count 该通道当前条目总数
|
||||
* [3] entry_count 本页实际条目数
|
||||
* [4..] 条目逐条拼接:
|
||||
* id(4LE) + seq(4LE) + rx_count(4LE) + dlc(1) + flags(1) + data(dlc)
|
||||
* id(4LE) + seq(4LE) + rx_count(4LE) + dlc(1) + flags(1) + rsv(2) + data(dlc)
|
||||
* 每条 = 16 + dlc 字节
|
||||
*/
|
||||
|
||||
@@ -22,13 +22,15 @@
|
||||
#include "device/spi/app_spi_command.h"
|
||||
#include "device/spi/app_spi_command_defs.h"
|
||||
#include "device/canfd.h"
|
||||
#include "spi_link_v2.h"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint8_t kPageEntries = 8U;
|
||||
constexpr uint16_t kMaxPayloadLen = 123U; /* kTxBufSize=128 - overhead=5 */
|
||||
constexpr uint16_t kMaxPayloadLen =
|
||||
static_cast<uint16_t>(AppSpiCommand::kTxBufSize - V2_OVERHEAD);
|
||||
|
||||
class SpiIdSnapshotHandler final : public ISpiCommandHandler {
|
||||
public:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@
|
||||
#define DEVICE_APP_SPI_COMMAND_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "sys/config.h"
|
||||
|
||||
class ISpiCommandHandler;
|
||||
|
||||
@@ -88,21 +89,20 @@ public:
|
||||
* 0xB0 进 BOOT 等路径需公开调用,避免 0xC1 残留盖住 ACK。 */
|
||||
void cancelRing();
|
||||
|
||||
static constexpr uint16_t kRxBufSize = 256U;
|
||||
static constexpr uint16_t kTxBufSize = 256U;
|
||||
static constexpr uint16_t kLogBufSize = 256U;
|
||||
static constexpr uint16_t kRxBufSize = CONFIG_SPI_RX_BUF_SIZE;
|
||||
static constexpr uint16_t kTxBufSize = CONFIG_SPI_TX_BUF_SIZE;
|
||||
static constexpr uint16_t kLogBufSize = CONFIG_SPI_LOG_BUF_SIZE;
|
||||
|
||||
private:
|
||||
static constexpr uint8_t kMaxCommands = 8U;
|
||||
/** GD32 主动按铃超时(ms):ESP32 未在该时间内来读则放弃。 */
|
||||
static constexpr uint32_t kRingTimeoutMs = 50U;
|
||||
static constexpr uint8_t kMaxCommands = CONFIG_SPI_MAX_COMMANDS;
|
||||
/** GD32 主动按铃超时(ms):见 CONFIG_SPI_RING_TIMEOUT_MS。 */
|
||||
static constexpr uint32_t kRingTimeoutMs = CONFIG_SPI_RING_TIMEOUT_MS;
|
||||
|
||||
volatile bool m_csActive = false;
|
||||
/** 本笔 CS 实际收到的字节数(CS 上升沿时由 RX DMA CHCNT 反算得到)。 */
|
||||
volatile uint16_t m_rxLen = 0U;
|
||||
volatile uint16_t m_txLen = 0U;
|
||||
volatile bool m_logPending = false;
|
||||
bool m_txActiveThisCs = false;
|
||||
/** RX DMA 接收缓冲(替代旧 RBNE 逐字节累积的 m_rxBuf)。
|
||||
* CS 上升沿时 m_rxLen 为本笔实际收到的字节数,本缓冲前 m_rxLen 字节有效。 */
|
||||
uint8_t m_rxBuf[kRxBufSize] = {};
|
||||
@@ -124,8 +124,10 @@ private:
|
||||
void onCsRelease();
|
||||
void processCommand();
|
||||
|
||||
/** @brief 设置 m_ringPending=true 并启动超时看护截止时刻。
|
||||
* 统一 7 处「m_ringPending=true; m_ringDeadline=now+timeout;」赋值模式。 */
|
||||
/** @brief 响应装载完成后的统一收尾:按铃 + updateDataReady。 */
|
||||
void finishResponseAndReady();
|
||||
|
||||
/** @brief 设置 m_ringPending=true 并启动超时看护截止时刻。 */
|
||||
void armRingPending();
|
||||
|
||||
/** @brief 在 CS 空闲期预装下一笔全双工 DMA(TX + RX)。
|
||||
|
||||
Reference in New Issue
Block a user