修复了一个malloc的问题

This commit is contained in:
2026-09-18 17:46:46 +08:00
parent 2d0ec356ad
commit abec4bf592
9 changed files with 941 additions and 37 deletions
+38
View File
@@ -8,11 +8,15 @@
* 创建日期:2026-09-14
* 修改记录:
* v1.0 2026-09-14 王建锋 创建初始版本
* v1.1 2026-09-18 王建锋 增 cfg_store_alloc / cfg_store_free / cfg_store_heap_free:
* 共享核心临时缓冲改走 FreeRTOS 堆(P0-1,MicroLIB C 堆仅 512B)
*/
/* 头文件包含区 */
#include <string.h>
#include "FreeRTOS.h"
#include "cfg_file_store.h"
#include "ff.h"
@@ -156,3 +160,37 @@ const char *cfg_store_tmp_path(void) {
const char *cfg_store_legacy_path(void) {
return s_path_legacy;
}
/*
* 函数功能:分配共享核心临时缓冲(FreeRTOS 堆)
* 入口参数:size - 字节数 size_t
* 返回值:缓冲指针(内容未清零);失败返回 NULL void *
* 限定条件:任务上下文调用(heap_4 内部临界区自护);释放必须用 cfg_store_free
* 函数说明:MCU 端 MicroLIB C 堆仅 512B(startup Heap_Size=0x200),共享核心的 KB 级
* 缓冲若走 C 库 malloc 必然返回 NULL,故统一由本接口取 FreeRTOS 堆(P0-1)
*/
void *cfg_store_alloc(size_t size) {
return pvPortMalloc(size);
}
/*
* 函数功能:释放 cfg_store_alloc 分配的临时缓冲
* 入口参数:p_buf - 缓冲指针(NULL 安全) void *
* 返回值:无
* 限定条件:p_buf 必须来自 cfg_store_alloc(禁止释放栈地址或 C 库指针)
*/
void cfg_store_free(void *p_buf) {
if (p_buf != NULL) {
vPortFree(p_buf);
}
}
/*
* 函数功能:FreeRTOS 堆当前空闲字节数(分配失败诊断)
* 入口参数:无
* 返回值:空闲字节数(未计入碎片影响) uint32_t
* 限定条件:无
*/
uint32_t cfg_store_heap_free(void) {
return (uint32_t)xPortGetFreeHeapSize();
}