Refactor and clean up codebase

- Removed unused constants and type aliases in app_spi_command_defs.h and temp_sensor.h.
- Simplified ISpiCommandHandler destructor to default.
- Eliminated redundant methods and comments in temp_sensor and usart0 files.
- Consolidated writeU32Le function to app_spi_command_defs.h for reuse.
- Updated comments for clarity and accuracy in task_manager.h and task_runner.cpp.
- Removed hardfault.h as it contained no declarations.
- Cleaned up CANFD and watchdog implementations by removing dead code and unnecessary comments.
- Updated version numbers in config.h to reflect recent changes.
- Enhanced error handling and diagnostics in hardfault handling.
This commit is contained in:
cbb
2026-07-15 02:49:37 +08:00
parent a52d94687b
commit 76da7a3dd6
37 changed files with 1401 additions and 1955 deletions
+5 -50
View File
@@ -5,39 +5,6 @@
class ISpiCommandHandler;
/**
* @brief GD32 侧 SPI 链路状态机:封装按铃状态。
*
* v2 DATA_READY 语义:PB6 低 = 有待发数据,高 = 队列空。
* ESP32 不再操作 PB6,无独立「完成」信号;按铃完成由 ESP32
* 的 CS 读事务本身确认(onCsRelease 按铃响应路径调 onEsp32Complete)。
*
* canRingNow() 总是返回 true,由 requestEsp32Read() 的 m_ringPending
* 检查控制重复按铃。
*/
class SpiLinkState {
public:
/** 是否允许发起新按铃。
* v2 DATA_READY: ESP32 不再操作 PB6,无独立完成信号;
* 总是允许,由 requestEsp32Read() 的 m_ringPending 检查控制重复。 */
bool canRingNow() const { return true; }
/** 发起按铃时调用(v2 下仅保留兼容写法,无实际门禁作用)。 */
void onRingStart() { m_esp32Ready = false; }
/** ESP32 CS 读事务完成确认(onCsRelease 按铃响应路径调用)。 */
void onEsp32Complete() { m_esp32Ready = true; }
/** 按铃超时取消时调用(允许重试,不依赖 EXTI)。 */
void onRingTimeout() { m_esp32Ready = true; }
/** 初始化(首帧允许)。 */
void reset() { m_esp32Ready = true; }
private:
volatile bool m_esp32Ready = true;
};
/**
* @brief APP 运行期 SPI 链路与命令路由模块。
*
@@ -114,11 +81,6 @@ 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; }
@@ -126,11 +88,6 @@ public:
* 0xB0 进 BOOT 等路径需公开调用,避免 0xC1 残留盖住 ACK。 */
void cancelRing();
/** @brief 查询 ESP32 是否已完成上一帧处理(SPIready 上升沿触发)。
* 初始为 true 允许第一次按铃;每次 requestEsp32Read 后置 false,
* ESP32 releaseReady 产生上升沿后由 EXTI 置 true。 */
bool canRingNow() const { return m_linkState.canRingNow(); }
static constexpr uint16_t kRxBufSize = 256U;
static constexpr uint16_t kTxBufSize = 256U;
static constexpr uint16_t kLogBufSize = 256U;
@@ -143,8 +100,7 @@ private:
volatile bool m_csActive = false;
/** 本笔 CS 实际收到的字节数(CS 上升沿时由 RX DMA CHCNT 反算得到)。 */
volatile uint16_t m_rxLen = 0U;
uint16_t m_txLen = 0U;
volatile uint8_t m_txPos = 0U;
volatile uint16_t m_txLen = 0U;
volatile bool m_logPending = false;
bool m_txActiveThisCs = false;
/** RX DMA 接收缓冲(替代旧 RBNE 逐字节累积的 m_rxBuf)。
@@ -159,11 +115,6 @@ private:
volatile bool m_ringPending = false;
/** 按铃超时截止时刻(ms,基于 SysTickTimer::getMs)。 */
volatile uint32_t m_ringDeadline = 0U;
/** 按铃期间暂存的请求帧长度(供 onCsAssert 装入 DMA)。 */
volatile uint16_t m_ringTxLen = 0U;
/** SPI 链路状态机:封装 ESP32 完成信号。 */
SpiLinkState m_linkState;
void configureGpio();
void configureSpi0();
@@ -173,6 +124,10 @@ private:
void onCsRelease();
void processCommand();
/** @brief 设置 m_ringPending=true 并启动超时看护截止时刻。
* 统一 7 处「m_ringPending=true; m_ringDeadline=now+timeout;」赋值模式。 */
void armRingPending();
/** @brief 在 CS 空闲期预装下一笔全双工 DMA(TX + RX)。
* 必须在首个 SCK 之前完成,否则 EXTI CS 下降相对 ESP32 时钟偏晚,
* 整笔事务会收 0 字节。对齐 BOOT SpiOta::armSpiDmasForNextCs。 */