/* * Copyright (c) 2026, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2026-03-06 user first version */ #ifndef __ECODE_H__ #define __ECODE_H__ #include #include /* 魔数:用于标识分区已被初始化 ("ECOD" 的 ASCII) */ #define ECODE_MAGIC 0xEC0DE09D #define ECODE_VERSION 3 #include "peri.h" extern struct rtc_time time_now; /* 错误码枚举(与原一致) */ typedef enum { e_reboot = 1, e_clearecode, e_test_fun, e_update_timeout, e_bak_restore, e_bak_backup, e_update, e_update_ok, e_update_fail, e_update_WSUCC, e_update_WFAIL, e_hardfault, e_iwdg, e_mqtt0_outtime, e_BL, e_typeMAX } ecode_list; typedef struct __attribute__((packed)) { struct TM time_stamp; // 时间戳 uint16_t code; // 异常码 uint16_t para; // 附带参数 uint32_t num; // 序号(全局递增) char detail[50]; // 内容 } ecode_record_t; /* 模块初始化(可显式调用,也可由内部自动触发) */ int ecode_init(void); /* 写入一条记录(与原有函数名完全一致) */ void Recode_e_code(ecode_list code, uint16_t para, char *detail); /* 读取最新第 index 条记录(index=0 为最新) */ int ecode_read(uint32_t index, ecode_record_t *rec); /* 获取当前有效记录总数 */ uint32_t ecode_get_count(void); /* 清空所有记录(重置头部,并可选擦除数据区) */ void ecode_clear(void); #endif /* __ECODE_H__ */