#ifndef __CONFIG_H__ #define __CONFIG_H__ #include "stdint.h" #define EEPDEBUG 0 #define DEBUG_OTA 0 // Flash分区配置 constexpr u32 BOOTLOADER_SIZE = 0x4000; // 16KB constexpr u32 APP_START_ADDR = 0x08010000; // APP起始地址 0x08004000 constexpr u32 APP2_START_ADDR = 0x08010000; // APP2起始地址 constexpr u32 APP_MAX_SIZE = 0xC000; // 48KB constexpr u32 FMC_PAGE_SIZE = 0x400; // 1KB // CANFD配置 constexpr u32 CANFD_OTA_REQ_ID = 0x00000100; constexpr u32 CANFD_OTA_DATA_ID = 0x00000101; constexpr u32 CANFD_OTA_ACK_ID = 0x00000102; constexpr u32 CANFD_OTA_WAIT_ID = 0x00000103; // 设备唯一ID寄存器地址 (GD32C10x系列) constexpr u32 DEVICE_SERIAL_ADDR_MSB = 0x1FFFF7E8; // 最高32位 constexpr u32 DEVICE_SERIAL_ADDR_MID = 0x1FFFF7EC; // 中间32位 constexpr u32 DEVICE_SERIAL_ADDR_LSB = 0x1FFFF7F0; // 最低32位 // CANFD数据段最大64字节,我们用1字节序号 + 48字节数据 + 1字节CRC校验 constexpr u32 OTA_PACKET_SIZE = 48; typedef struct { u32 packet_num; // 包序号 u8 data[OTA_PACKET_SIZE]; // 48字节有效数据 u32 crc32; // 简单校验 } canfd_ota_packet_t; // 定义一个联合体类型用于float和byte数组之间的转换 typedef union { u32 u; u8 b[4]; } u32_union_t; // 添加辅助函数用于从u8数组中解包float类型数据 static inline u32_union_t unpack_bytes_to_float(u8 *buffer, u16 offset) { u32_union_t u32_union; u32_union.b[0] = buffer[offset]; u32_union.b[1] = buffer[offset + 1]; u32_union.b[2] = buffer[offset + 2]; u32_union.b[3] = buffer[offset + 3]; return u32_union; } // 其他 constexpr u32 OTA_TIMEOUT = 10000; constexpr u8 SIZE_U32 = sizeof(uint32_t); constexpr u8 SIZE_FLOAT = sizeof(float); #endif