feat(boot): 添加SPI OTA功能并更新配置
- 添加SpiOta.h和SpiOta.cpp文件以实现SPI OTA功能 - 在项目配置中添加SPI_I2S外设组件支持 - 设置外部晶振值为8MHz (HXTAL_VALUE=8000000U) - 调整ROM0大小从512KB减小到2KB以适应引导程序需求 - 移除评估板相关文件和看门狗驱动文件以优化存储空间
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
#ifndef __SPI_OTA_H__
|
||||
#define __SPI_OTA_H__
|
||||
|
||||
#include "OTA.h"
|
||||
|
||||
/**
|
||||
* @file SpiOta.h
|
||||
* @brief SPI OTA 从机协议头文件(PendSV 延迟响应版)。
|
||||
*
|
||||
* CS 释放后,EXTI ISR 只做轻量校验(SOF + LEN + CRC),
|
||||
* 校验通过则触发 PendSV(最低优先级 ISR),由 PendSV 调用
|
||||
* handleLinkMessage 完成帧处理和响应准备。
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
SPI_OTA_CMD_REQ = 0x01,
|
||||
SPI_OTA_CMD_DATA = 0x02,
|
||||
SPI_OTA_CMD_CANCEL = 0x03,
|
||||
SPI_OTA_RSP_ACK = 0x80,
|
||||
SPI_OTA_RSP_WAIT = 0x81,
|
||||
SPI_OTA_RSP_ERROR = 0x82
|
||||
} spi_ota_frame_type_t;
|
||||
|
||||
class SpiOta {
|
||||
public:
|
||||
static constexpr u8 kSof = 0xA5U;
|
||||
static constexpr u16 kRxBufSize = 256U;
|
||||
static constexpr u16 kTxBufSize = 128U;
|
||||
static constexpr u16 kFrameOverhead = 5U;
|
||||
static constexpr u16 kIsrLogBufSize = 128U;
|
||||
|
||||
static void init();
|
||||
static void poll();
|
||||
static void setSender(OTAHandler *handler);
|
||||
static void onCsAssert();
|
||||
static void onCsRelease();
|
||||
static void configureGpio();
|
||||
static void configureSpi0();
|
||||
static void configureExti();
|
||||
static void onSpiInterrupt();
|
||||
static void onCsExtiInterrupt();
|
||||
static void feedRxBytes(const u8 *data, u16 len);
|
||||
static bool hasTxFrame();
|
||||
static u16 copyTxFrame(u8 *out, u16 max_len);
|
||||
|
||||
/** @brief EXTI ISR 内轻量校验,通过则触发 PendSV。 */
|
||||
static void isrValidateAndPend();
|
||||
/** @brief PendSV ISR 内执行帧处理和响应准备。 */
|
||||
static void onPendSvProcess();
|
||||
/** @brief ISR 内轻量日志写入延迟打印缓冲。 */
|
||||
static void isrLogFrame(const char *tag, const u8 *data, u16 len);
|
||||
|
||||
/* ---- PendSV 需要访问的成员放 public ---- */
|
||||
static OTAHandler *s_otaHandler;
|
||||
static volatile bool s_csActive;
|
||||
static volatile u16 s_rxStreamLen;
|
||||
static volatile u16 s_txStreamPos;
|
||||
static u8 s_rxStream[kRxBufSize];
|
||||
static u8 s_txBuf[kTxBufSize];
|
||||
static volatile u16 s_txLen;
|
||||
static volatile bool s_txPending;
|
||||
static volatile bool s_isrLogPending;
|
||||
static u8 s_isrLogBuf[kIsrLogBufSize];
|
||||
static u16 s_isrLogLen;
|
||||
static volatile bool s_pendSVPending;
|
||||
|
||||
private:
|
||||
static u8 crc8(const u8 *data, u16 len);
|
||||
static bool buildFrame(spi_ota_frame_type_t type, const u8 *payload, u16 payload_len,
|
||||
u8 *out, u16 *out_len);
|
||||
static bool tryParseFrame(const u8 *frame, u16 frame_len,
|
||||
spi_ota_frame_type_t *type,
|
||||
const u8 **payload,
|
||||
u16 *payload_len);
|
||||
static ota_link_msg_type_t mapMsgType(spi_ota_frame_type_t type);
|
||||
static void sender(ota_link_tx_type_t type, u8 len, const u8 *data);
|
||||
static void queueTxFrame(const u8 *frame, u16 len);
|
||||
static uint32_t enterCritical();
|
||||
static void exitCritical(uint32_t primask);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 引脚约定:CS=PA15, SCK=PB3, MISO=PB4, MOSI=PB5
|
||||
*/
|
||||
|
||||
void spi_ota_init(void);
|
||||
void spi_ota_poll(void);
|
||||
void spi_ota_set_sender(OTAHandler *handler);
|
||||
void spi_ota_on_cs_assert(void);
|
||||
void spi_ota_on_cs_release(void);
|
||||
void spi_ota_gpio_init(void);
|
||||
void spi_ota_spi0_init(void);
|
||||
void spi_ota_exti_init(void);
|
||||
void spi_ota_irq_handler(void);
|
||||
void spi_ota_cs_exti_handler(void);
|
||||
void spi_ota_feed_rx_bytes(const u8 *data, u16 len);
|
||||
bool spi_ota_has_tx_frame(void);
|
||||
u16 spi_ota_copy_tx_frame(u8 *out, u16 max_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user