Files
DCU_APP/GD32E508_DCU_APP/sys/ota_boot_request.h
T
cbb 33037bc5a3 feat(spi): 实现SPI同步通信协议和主动推送机制
- 实现新的SPI同步帧格式,采用0xA5 0x5A起始符和CRC32校验,提升通信可靠性
- 添加GD32与ESP32间的握手机制,通过PB6开漏输出实现SPIready线与控制
- 实现异步OTA启动机制,将Flash操作延迟到主循环执行,避免SPI ISR阻塞
- 改进CAN反馈命令处理,提取通用payload构建函数支持主动推送模式
- 实现GD32主动按铃机制,循环推送CAN反馈数据到ESP32,减少轮询开销
- 添加SPI通信超时保护和死锁防护机制,确保系统稳定性
2026-07-08 02:51:24 +08:00

55 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef SYS_OTA_BOOT_REQUEST_H
#define SYS_OTA_BOOT_REQUEST_H
#include <stdint.h>
/**
* @brief DCU_APP 进入 Bootloader OTA 窗口控制模块。
* @note ESP32 通过 CAN-FD 发送受保护命令,APP 写 OTA 标志后软复位,
* Bootloader 下次启动会停留在 OTA 等待窗口。
*/
class OtaBootRequest {
public:
/** @brief 初始化内部状态。 */
static void init();
/**
* @brief 尝试处理一帧 CAN 接收报文。
* @param[in] channel 报文来源 CAN 通道。
* @param[in] id 报文 ID。
* @param[in] data 报文负载。
* @param[in] length 报文负载长度。
* @retval true 该报文已被 OTA/BOOT 控制模块消费。
* @retval false 该报文不是 OTA/BOOT 控制报文。
*/
static bool handleCanFrame(uint8_t channel, uint32_t id, const uint8_t *data, uint8_t length);
/**
* @brief 设置 Bootloader OTA 等待标志并安排软复位。
* @retval true 标志写入成功,稍后会复位进入 Bootloader。
* @retval false Flash 标志写入失败。
* @note 此函数会执行 Flash 操作(可能擦页 20-30ms),不可在 ISR 内调用。
*/
static bool requestEnterBoot();
/**
* @brief 异步请求进入 Bootloader(ISR 安全)。
* @note 仅设置 pending 标志,Flash 操作和复位由 process() 在主循环执行。
* 用于 SPI EXTI ISR 内的 0xB0 命令处理,避免 Flash 擦除阻塞 SPI 中断。
*/
static void requestEnterBootAsync();
/** @brief 若已确认进入 BOOT 请求,则延迟片刻后复位。 */
static void process();
/** @brief 查询是否已收到进入 Bootloader 请求(等待复位中)。
* 供主循环在复位前停止主动按铃等可能干扰 OTA 的操作。 */
static bool isRebootPending() { return s_rebootPending; }
private:
static volatile bool s_rebootPending;
static volatile bool s_bootRequestPending; ///< 0xB0 异步请求标志,process() 中执行 Flash 操作
};
#endif /* SYS_OTA_BOOT_REQUEST_H */