Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources

This commit is contained in:
2026-07-06 11:30:13 +08:00
commit e76462eeb7
3451 changed files with 1415300 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
#ifndef _HGIC_MMPOOL_H_
#define _HGIC_MMPOOL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "list.h"
#define MMPOOL_OBJ \
const char *name;\
uint32 size, free_size;\
uint8 region_cnt, align, headsize, tailsize, trace_off, ofchk_off;
struct mmpool_base {
MMPOOL_OBJ;
};
#define MMPOOL_REGION_MAX (4)
struct mmpool1 {
MMPOOL_OBJ;
uint32 regions[MMPOOL_REGION_MAX][2];
struct list_head free_list;
struct list_head used_list;
#ifdef MMPOOL_PERF_COUNT
uint32 tot_alloc, tot_free;
uint32 alloc_perf[MMPOOL_PERF_COUNT];
uint32 free_perf[MMPOOL_PERF_COUNT];
#endif
};
#define MMPOOL2_REGION_MAX (4)
#define MMPOOL2_FRAG_LOG (12)
struct mmpool2 {
MMPOOL_OBJ;
uint32 regions[MMPOOL2_REGION_MAX][2];
struct list_head free_list[MMPOOL2_FRAG_LOG];
struct list_head used_list;
#ifdef MMPOOL_PERF_COUNT
uint32 tot_alloc, tot_free;
uint32 alloc_perf[MMPOOL_PERF_COUNT];
uint32 free_perf[MMPOOL_PERF_COUNT];
#endif
};
#define MMPOOL3_REGION_MAX (4)
#define MMPOOL3_FRAG_LOG (12)
struct mmpool3_region {
uint32 start, end;
uint32 blk_size, blocks, blk_cnt;
struct list_head block_list;
};
struct mmpool3 {
MMPOOL_OBJ;
uint8 min_size;
struct mmpool3_region regions[MMPOOL3_REGION_MAX];
struct list_head used_list;
struct list_head frag_list[MMPOOL3_FRAG_LOG];
#ifdef MMPOOL_PERF_COUNT
uint32 tot_alloc, tot_free;
uint32 alloc_perf[MMPOOL_PERF_COUNT];
uint32 free_perf[MMPOOL_PERF_COUNT];
#endif
};
struct mmpool_ops {
void *(*alloc)(void *mp, uint32 size, const char *func, int32 line);
int32(*free)(void *mp, void *ptr);
int32(*init)(void *mp, uint32 addr, uint32 size, uint32 blk_size);
int32(*free_state)(void *mp, uint32 *stat_buf, int32 size, uint32 *tot_size);
int32(*used_state)(void *mp, uint32 *stat_buf, int32 size, uint32 *tot_size, uint32 mini_size);
int32(*add_region)(void *mp, uint32 addr, uint32 size, uint32 blk_size);
int32(*of_check)(void *mp, uint32 addr, uint32 size);
int32(*valid_addr)(void *pool, uint32 addr, uint8 first);
int32(*perfermance)(void *mp, uint8 alloc, uint32 *values, uint32 count);
void (*dump)(void *mp);
void (*time)(void *mp, uint32 *alloc_time, uint32 *free_time);
int32 (*used_list)(void *pool, uint32_t *list_buf, int32 list_size);
};
extern const struct mmpool_ops mmpool1_ops;
extern const struct mmpool_ops mmpool2_ops;
extern const struct mmpool_ops mmpool3_ops;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,40 @@
#ifndef _MEM_POOL_H_
#define _MEM_POOL_H_
#ifdef __cplusplus
extern "C" {
#endif
#define LOG_MAX (12)
/*free frag list*/
struct frag_list {
struct frag_list *next;
struct frag_list *prev;
};
struct mem_pool {
unsigned int block_size: 24, init:1, rev: 7;
unsigned int block_count;
unsigned int heap_start;
unsigned int heap_end;
unsigned int heap_ptr;
unsigned int heap_base;
unsigned int blocks;
struct frag_list frags[LOG_MAX];
#ifdef MMPOOL_PERF_COUNT
uint32 alloc_perf[MMPOOL_PERF_COUNT];
uint32 free_perf[MMPOOL_PERF_COUNT];
#endif
};
#define mpool_free_size(pool) ((pool)->heap_end-(pool)->heap_ptr)
int32 mpool_init(struct mem_pool *pool, uint32 block_size, uint32 mem_addr, uint32 mem_size);
void mpool_free(struct mem_pool *pool, void *ptr);
void *mpool_alloc(struct mem_pool *pool, uint32 size);
void mpool_state(struct mem_pool *pool, char *state_buf, int32 buf_size);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,28 @@
#ifndef _HGIC_SDK_MTRACE_H_
#define _HGIC_SDK_MTRACE_H_
#ifdef __cplusplus
extern "C" {
#endif
struct mtrace_entry {
void *ptr;
const char *func;
int line;
int size;
};
struct mtrace {
int size;
struct mtrace_entry *entrys;
};
void mtrace_print(struct mtrace *mt);
void mtrace_add(struct mtrace *mt, void *ptr, const char *func, int line, int size);
void mtrace_del(struct mtrace *mt, void *ptr);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,120 @@
#ifndef _SYS_HEAP_H_
#define _SYS_HEAP_H_
#include "lib/heap/mmpool.h"
#ifdef __cplusplus
extern "C" {
#endif
enum SYSHEAP_FLAGS {
SYSHEAP_FLAGS_MEM_LEAK_TRACE = (1u << 0),
SYSHEAP_FLAGS_MEM_OVERFLOW_CHECK = (1u << 1),
SYSHEAP_FLAGS_MEM_ALIGN_16 = (1u << 2),
SYSHEAP_FLAGS_MEM_ALIGN_32 = (1u << 3),
SYSHEAP_FLAGS_MEM_TAIL_ALIGN_4 = (1u << 4),
SYSHEAP_FLAGS_MEM_TAIL_ALIGN_16 = (1u << 5),
SYSHEAP_FLAGS_MEM_TAIL_ALIGN_32 = (1u << 6),
};
struct sys_heap {
const char *name;
const struct mmpool_ops *ops;
struct mmpool_base pool;
};
struct sys_sramheap {
const char *name;
const struct mmpool_ops *ops;
struct mmpool1 pool;
//可以修改为mmpool3, 同时修改malloc_init函数sram_heap.ops = &mmpool3_ops;
};
struct sys_psramheap {
const char *name;
const struct mmpool_ops *ops;
struct mmpool1 pool;
//可以修改为mmpool3, 同时修改malloc_psram_init函数psram_heap.ops = &mmpool3_ops;
};
struct sys_av_heap {
const char *name;
const struct mmpool_ops *ops;
struct mmpool1 pool;
//可以修改为mmpool3, 同时修改初始化函数的ops赋值
};
void *__malloc(struct sys_heap *heap, int size, void *lr);
void __free(struct sys_heap *heap, void *ptr, void *lr);
void *__zalloc(struct sys_heap *heap, int size, void *lr);
void *__realloc(struct sys_heap *heap, void *ptr, int size, void *lr);
void *__malloc_t(struct sys_heap *heap, int size, const char *func, int line);
void __free_t(struct sys_heap *heap, void *ptr, const char *func, int line);
void *__zalloc_t(struct sys_heap *heap, int size, const char *func, int line);
void *__realloc_t(struct sys_heap *heap, void *ptr, int size, const char *func, int line);
int32 _sysheap_init(struct sys_heap *heap, void *heap_start, uint32 heap_size, uint32 flags);
void *_sysheap_alloc(struct sys_heap *heap, int size, const char *func, int line);
int32 _sysheap_free(struct sys_heap *heap, void *ptr);
uint32 _sysheap_freesize(struct sys_heap *heap);
uint32 _sysheap_totalsize(struct sys_heap *heap);
void _sysheap_collect_init(struct sys_heap *heap);
int32 _sysheap_add(struct sys_heap *heap, uint32 start_addr, uint32 end_addr);
int32 _sysheap_of_check(struct sys_heap *heap, void *ptr, uint32 size);
void _sysheap_status(struct sys_heap *heap, uint32 *status_buf, int32 buf_size, uint32 mini_size);
int32 _sysheap_valid_addr(struct sys_heap *heap, void *ptr, uint8 first);
uint32 _sysheap_time(struct sys_heap *heap);
int32 _sysheap_used_list(struct sys_heap *heap, uint32 *list_buf, int32 buf_size);
void _sysheap_dump(struct sys_heap *heap);
#define sysheap_init(heap, heap_start, heap_size, flags) \
_sysheap_init((struct sys_heap *)(heap), heap_start, heap_size, flags)
#define sysheap_time(heap)\
_sysheap_time((struct sys_heap *)(heap))
#define sysheap_alloc(heap, size, func, line)\
_sysheap_alloc((struct sys_heap *)(heap), size, (const char *)func, line)
#define sysheap_free(heap, ptr)\
_sysheap_free((struct sys_heap *)(heap), ptr)
#define sysheap_freesize(heap)\
_sysheap_freesize((struct sys_heap *)(heap))
#define sysheap_totalsize(heap)\
_sysheap_totalsize((struct sys_heap *)(heap))
#define sysheap_collect_init(heap)\
_sysheap_collect_init((struct sys_heap *)(heap))
#define sysheap_add(heap, start_addr, end_addr)\
_sysheap_add((struct sys_heap *)(heap), start_addr, end_addr)
#define sysheap_of_check(heap, ptr, size)\
_sysheap_of_check((struct sys_heap *)(heap), ptr, size)
#define sysheap_status(heap, status_buf, buf_size, mini_size)\
_sysheap_status((struct sys_heap *)(heap), status_buf, buf_size, mini_size)
#define sysheap_valid_addr(heap, ptr, first)\
_sysheap_valid_addr((struct sys_heap *)(heap), ptr, first)
#define sysheap_time(heap)\
_sysheap_time((struct sys_heap *)(heap))
#define sysheap_used_list(heap, list_buf, buf_size)\
_sysheap_used_list((struct sys_heap *)(heap), list_buf, buf_size)
#define sysheap_dump(heap)\
_sysheap_dump((struct sys_heap *)(heap))
extern struct sys_sramheap sram_heap;
extern struct sys_psramheap psram_heap;
#endif
#ifdef __cplusplus
}
#endif