feat(spi): 实现L5单缓冲信用机制并添加事件队列别名

- 在AppSpiCommand中实现g_localCredit信用管理机制
- updateDataReady()函数现在同步g_localCredit状态(有数据时为0,无数据时为1)
- requestEsp32Read()在装载数据前将credit设置为1,装载后通过updateDataReady置0
- 为DATA_READY信号更新注释说明信用机制工作原理
- 添加enqueueEvent()作为requestEsp32Read()的L4别名函数
- 更新相关代码注释以反映新的信用机制实现
This commit is contained in:
cbb
2026-07-14 12:10:01 +08:00
parent 7c05496b89
commit 8bc01dd654
2 changed files with 10 additions and 2 deletions
@@ -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;
}
@@ -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; }