栈整改不抬栈:删旧档迁移、FIL静态化、日志行缓冲按模块收紧、钩子脱离HAL,defaultTask链5312→2776B

This commit is contained in:
2026-10-10 10:17:00 +08:00
parent 5c978465c9
commit 0779d3a075
54 changed files with 3203 additions and 2770 deletions
+4 -3
View File
@@ -1,6 +1,6 @@
# App/cfg/ — 配置引擎
> **`/config.ini` 配置引擎**:分层解析、持久化(原子写)、旧档迁移。
> **`/config.ini` 配置引擎**:分层解析、持久化(原子写)。
> 属主 = **defaultTask**(单任务收敛,静态态);其它任务不得直接触碰。
## 文件一览
@@ -18,10 +18,11 @@
- **零分配共享核心**:核心逻辑不含任何分配符号,动态内存收进平台后端
(`cfg_store_alloc/free`:MCU→`pvPortMalloc`,模拟器→宿主堆)
- **原子写**:写 `/config.TMP` 后 `f_rename` 替换,避免掉电损坏
- **旧档迁移**:首启时把旧格式转换为当前格式(`net_cfg_legacy.c` 负责网络段)
- **旧档迁移已删除(2026-10-10)**:旧格式 `/cfg/netcfg.bin` 不再读取——存在则被忽略(不读、
不删、不迁移),配置回落工厂默认;`net_cfg_legacy.c/h` 与 `cfg_store_legacy_path()` 已移除
- **自研代码禁用 C 库堆分配**:MicroLIB 堆仅 512B(`malloc` 必返回 NULL)
## 相关文档
- `docs/子系统设计/配置文件设计说明.md` — 完整设计(分层/解析/持久化/迁移)
- `docs/子系统设计/配置文件设计说明.md` — 完整设计(分层/解析/持久化)
- `docs/子系统设计/网络配置说明.md` — 网络段
+4
View File
@@ -41,6 +41,10 @@
#include "sys_log.h" /* 配置读写失败上报自检记录(双端共享接口,MCU 端 preboot/队列安全) */
/* 深调用链模块(配置引擎在 defaultTask 启动链与保存链上,下接 FatFS → FTL):
* 日志行缓冲收到 128 B(默认 192)。本模块最长行 "load: file %luB > %uB, corrupt,
* factory template regenerated" 渲染后 ≈ 91 B(含时间戳 21 + 标签)< 128 → 不截断 */
#define DBG_LINE_BUF_MAX 128U
#define DBG_TAG "[CFG]"
#include "dbg_log.h"
+2 -2
View File
@@ -103,8 +103,8 @@ const char *cfg_store_config_path(void);
/* 函数功能:取配置文件临时文件路径(write_atomic 内部用) */
const char *cfg_store_tmp_path(void);
/* 函数功能:取旧版配置遗留文件路径(net_cfg_legacy 迁移用) */
const char *cfg_store_legacy_path(void);
/* 注:旧版遗留档 getter `cfg_store_legacy_path()` 已于 2026-10-10 随旧档迁移
* net_cfg_legacy 一并删除(旧格式 /cfg/netcfg.bin 不再兼容、不再读取) */
#ifdef __cplusplus
}
+13 -11
View File
@@ -2,7 +2,7 @@
* 模块名称:cfg_file_store (MCU 后端)
* 模块功能:cfg_file 存储后端——NAND 上 FatFS 文件 /config.ini(卷根,8.3 合规);
* 原子写 = 临时文件 config.TMP(与目标同目录)+ f_rename;mtime 变更令牌 =
* (fdate << 16) | fmtime;旧版遗留文件 /cfg/netcfg.bin 供迁移读取
* (fdate << 16) | fmtime
* 适用平台:STM32F407ZGTx
* 作者:王建锋
* 创建日期:2026-09-14
@@ -37,7 +37,6 @@
static const char s_path[] = "/config.ini";
static const char s_path_tmp[] = "/config.TMP";
static const char s_path_legacy[] = "/cfg/netcfg.bin";
/* 函数定义区 */
@@ -49,9 +48,14 @@ static const char s_path_legacy[] = "/cfg/netcfg.bin";
* p_nread - 实际读字节数输出(不可为 NULL) size_t *
* 返回值:0 - 成功;-1 - 文件缺失/读失败 int
* 限定条件:卷已挂载(未挂载时 f_open 返回 FR_NO_SYSTEM,转 -1)
* 函数说明:FIL 为**函数级 static**而非局部——本 FatFs 移植 FF_FS_TINY=0,
* `FIL` 内含 `buf[FF_MAX_SS]`=512 B(Lib/FatFs/ff.h),一个局部对象就吃掉
* 528 B 栈,是配置/syslog 调用链栈深的主要来源(2026-10-10 栈预算整改)。
* 安全性:整个 FIL 生命周期都在 `vol_lock_wait()/release()` 区间内,
* 跨任务访问被卷锁串行化,且本函数不递归、不嵌套自身
*/
int cfg_store_read(const char *p_path, uint8_t *p_buf, size_t cap, size_t *p_nread) {
FIL f;
static FIL f; /* static:省 528 B 栈;卷锁内串行使用 */
FRESULT fr;
UINT br = 0u;
@@ -116,9 +120,11 @@ static int s_build_tmp_path(const char *p_path, char *p_out, size_t cap) {
* len - 数据长度 size_t
* 返回值:0 - 成功;-1 - 写/改名失败(目标文件保持不动,临时文件清理) int
* 限定条件:卷已挂载;中途失败(含掉电)不损坏目标文件
* 函数说明:`FIL` 用函数级 static 而非局部(FF_FS_TINY=0 → 单个 FIL = 528 B 栈);
* 与 cfg_store_read 各持自己的 static 对象,互不共享,且全程在卷锁区间内
*/
int cfg_store_write_atomic(const char *p_path, const uint8_t *p_buf, size_t len) {
FIL f;
static FIL f; /* static:省 528 B 栈;卷锁内串行使用 */
FRESULT fr;
UINT bw = 0u;
char tmp_path[CFG_STORE_TMP_PATH_MAX];
@@ -233,14 +239,10 @@ const char *cfg_store_tmp_path(void) {
}
/*
* 函数功能:取旧版配置遗留文件路径
* 入口参数:无
* 返回值:"/cfg/netcfg.bin"(旧 NCFG 二进制格式) const char *
* 限定条件:无
* 旧版遗留文件 /cfg/netcfg.bin 的路径 getter(cfg_store_legacy_path)已于
* 2026-10-10 随旧档迁移 net_cfg_legacy 一并删除:无调用者即无必要保留
* (留着"看起来还支持旧档"的入口会误导后续维护)
*/
const char *cfg_store_legacy_path(void) {
return s_path_legacy;
}
/*
* 函数功能:分配共享核心临时缓冲(FreeRTOS 堆)