From 8bc01dd654641833bf7ed548aa57e4048d24e07c Mon Sep 17 00:00:00 2001 From: cbb <2625274797@qq.com> Date: Tue, 14 Jul 2026 12:10:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(spi):=20=E5=AE=9E=E7=8E=B0L5=E5=8D=95?= =?UTF-8?q?=E7=BC=93=E5=86=B2=E4=BF=A1=E7=94=A8=E6=9C=BA=E5=88=B6=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=8B=E4=BB=B6=E9=98=9F=E5=88=97=E5=88=AB?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在AppSpiCommand中实现g_localCredit信用管理机制 - updateDataReady()函数现在同步g_localCredit状态(有数据时为0,无数据时为1) - requestEsp32Read()在装载数据前将credit设置为1,装载后通过updateDataReady置0 - 为DATA_READY信号更新注释说明信用机制工作原理 - 添加enqueueEvent()作为requestEsp32Read()的L4别名函数 - 更新相关代码注释以反映新的信用机制实现 --- GD32E508_DCU_APP/device/spi/app_spi_command.cpp | 7 +++++-- GD32E508_DCU_APP/device/spi/app_spi_command.h | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/GD32E508_DCU_APP/device/spi/app_spi_command.cpp b/GD32E508_DCU_APP/device/spi/app_spi_command.cpp index 65fad46..a2b00fc 100644 --- a/GD32E508_DCU_APP/device/spi/app_spi_command.cpp +++ b/GD32E508_DCU_APP/device/spi/app_spi_command.cpp @@ -252,11 +252,12 @@ void AppSpiCommand::setSpiReady(bool ready) } /* v2 DATA_READY: PB6 低 = 有待发数据,高 = 队列空。 - * 替代旧 BUSY/READY 语义中所有 setSpiReady 调用。 */ + * L5:同步 g_localCredit(单缓冲 0/1)。 */ void AppSpiCommand::updateDataReady() { const bool has_data = (m_txLen > 0U) || m_ringPending; setSpiReady(!has_data); + g_localCredit = has_data ? 0U : 1U; } void AppSpiCommand::configureSpi0() @@ -641,6 +642,8 @@ bool AppSpiCommand::requestEsp32Read(uint8_t frame_type, const uint8_t *payload, * 主动按铃帧使用 V2_FLAG_EVENT,session/seq 从 v2 状态全局变量取; * session 未建立时 session_id 填 0。 */ const uint32_t sess = g_v2Active ? g_sessionId : 0U; + /* L5:单缓冲 — 装载前 credit 报 1,装载后 updateDataReady 置 0 */ + g_localCredit = 1U; size_t built_len = 0U; if (!v2_build_frame(frame_type, V2_FLAG_EVENT, sess, g_txSeq, 0U, (uint8_t)g_localCredit, @@ -661,7 +664,7 @@ bool AppSpiCommand::requestEsp32Read(uint8_t frame_type, const uint8_t *payload, m_linkState.onRingStart(); /* v2 DATA_READY: 已设 m_ringPending=true 且 m_txLen>0, - * updateDataReady() 据此拉低 PB6,通知 ESP32「有待发数据」。 */ + * updateDataReady() 据此拉低 PB6,并置 g_localCredit=0。 */ updateDataReady(); return true; } diff --git a/GD32E508_DCU_APP/device/spi/app_spi_command.h b/GD32E508_DCU_APP/device/spi/app_spi_command.h index 30cd9e7..943d854 100644 --- a/GD32E508_DCU_APP/device/spi/app_spi_command.h +++ b/GD32E508_DCU_APP/device/spi/app_spi_command.h @@ -118,6 +118,11 @@ public: */ bool requestEsp32Read(uint8_t frame_type, const uint8_t *payload, uint16_t payload_len); + /** @brief L4 别名:主动事件入队(当前等同 requestEsp32Read)。 */ + bool enqueueEvent(uint8_t frame_type, const uint8_t *payload, uint16_t payload_len) { + return requestEsp32Read(frame_type, payload, payload_len); + } + /** @brief 查询当前是否有未读按铃(ESP32 尚未来读)。 */ bool isRingPending() const { return m_ringPending; }