Files
CCU621M/BSP/externalflash/flash_upgrade.h
T

60 lines
1.8 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.
/**
* @file flash_upgrade.h
* @brief 固件升级兼容头文件(整合自 CCU601E_D BSP/spi_Flash/flash_upgrade.h
*
* CCU621_M 平台:升级相关常量、类型与接口与 CCU601E_D 保持一致。
*/
#ifndef __FLASH_UPGRADE_H__
#define __FLASH_UPGRADE_H__
#include <stdint.h>
#include "main.h"
#include "externalflash/flash_external_data.h"
/* 扇区大小 (4KB) */
#define SECTOR_SIZE 4096
/* 数据包大小 */
#define PACKET_SIZE (1024)
/* 头部信息扇区 (第一个扇区) */
#define HEADER_SECTOR_ADDR UPGRADE_START_ADDR
#define HEADER_SECTOR_SIZE SECTOR_SIZE
/* 程序数据起始地址 (第二个扇区开始) */
#define PROGRAM_START_ADDR (UPGRADE_START_ADDR + HEADER_SECTOR_SIZE)
#define PROGRAM_MAX_SIZE (UPGRADE_TOTAL_SIZE - HEADER_SECTOR_SIZE)
/* 升级标志定义 */
#define UPGRADE_FLAG_IDLE 0x00
#define UPGRADE_FLAG_NEED_UP 0x55AA
#define UPGRADE_FLAG_DONE 0xAA55
#define UPGRADE_FLAG_ERROR 0xEEFF
/* 升级头部信息结构 */
#pragma pack(push, 1)
typedef struct {
uint16_t upgrade_flag;
uint32_t file_size;
uint32_t packet_count;
uint32_t crc32;
uint32_t timestamp;
uint8_t version[16];
uint8_t reserved[32];
} upgrade_header_t;
#pragma pack(pop)
/* 函数声明 */
int upgrade_init(void);
int upgrade_read_header(upgrade_header_t *header);
int upgrade_write_packet(uint32_t packet_index, const uint8_t *data, uint32_t data_len);
int upgrade_read_packet(uint32_t packet_index, uint8_t *data, uint32_t *data_len);
int upgrade_success_update_header(upgrade_header_t *header);
int upgrade_erase_program_area(void);
int upgrade_erase_program_area_for_size(uint32_t firmware_bytes);
/** 擦除循环中让出 CPU,读 BLE/TCP 入站(默认 weak 空实现,tcp_server 覆盖) */
void upgrade_erase_yield(void);
#endif /* __FLASH_UPGRADE_H__ */