pure sdk for main
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
#ifndef _HGIC_MMPOOL_H_
|
||||
#define _HGIC_MMPOOL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "list.h"
|
||||
|
||||
#define MMPOOL_REGION_MAX (4)
|
||||
struct mmpool {
|
||||
const char *name;
|
||||
uint32 size, free_size;
|
||||
uint8 region_cnt;
|
||||
uint8 align;
|
||||
uint8 headsize;
|
||||
uint8 tailsize;
|
||||
uint8 trace_off;
|
||||
uint8 ofchk_off;
|
||||
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 {
|
||||
const char *name;
|
||||
uint32 size, free_size;
|
||||
uint8 region_cnt;
|
||||
uint8 align;
|
||||
uint8 headsize;
|
||||
uint8 tailsize;
|
||||
uint8 trace_off;
|
||||
uint8 ofchk_off;
|
||||
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 {
|
||||
const char *name;
|
||||
uint32 size, free_size;
|
||||
uint8 region_cnt;
|
||||
uint8 align;
|
||||
uint8 headsize;
|
||||
uint8 tailsize;
|
||||
uint8 trace_off;
|
||||
uint8 ofchk_off;
|
||||
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
|
||||
};
|
||||
|
||||
uint32_t cpu_cycle_diff(uint8_t sub, uint32_t last_cycle);
|
||||
void *mmpool_alloc(struct mmpool *mp, uint32 size, const char *func, int32 line);
|
||||
void mmpool_free(struct mmpool *mp, void *ptr);
|
||||
int32 mmpool_init(struct mmpool *mp, uint32 addr, uint32 size);
|
||||
int32 mmpool_free_state(struct mmpool *mp, uint32 *stat_buf, int32 size, uint32 *tot_size);
|
||||
int32 mmpool_used_state(struct mmpool *mp, uint32 *stat_buf, int32 size, uint32 *tot_size, uint32 mini_size);
|
||||
int32 mmpool_add_region(struct mmpool *mp, uint32 addr, uint32 size);
|
||||
uint32 mmpool_free_size(struct mmpool *mp, uint32 min);
|
||||
int32 mmpool_of_check(struct mmpool *mp, uint32 addr, uint32 size);
|
||||
int32 mmpool_valid_addr(struct mmpool *mp, uint32 addr);
|
||||
int32 mmpool_perfermance(struct mmpool *mp, uint8 alloc, uint32 *values, uint32 count);
|
||||
int32 mmpool_used_list(struct mmpool *mp, uint32_t *list_buf, int32 list_size);
|
||||
void mmpool_dump(struct mmpool *mp);
|
||||
void mmpool_time(struct mmpool *mp, uint32 *alloc_time, uint32 *free_time);
|
||||
|
||||
void *mmpool2_alloc(struct mmpool2 *mp, uint32 size, const char *func, int32 line);
|
||||
void mmpool2_free(struct mmpool2 *mp, void *ptr);
|
||||
int32 mmpool2_init(struct mmpool2 *mp, uint32 addr, uint32 size);
|
||||
int32 mmpool2_free_state(struct mmpool2 *mp, uint32 *stat_buf, int32 size, uint32 *tot_size);
|
||||
int32 mmpool2_used_state(struct mmpool2 *mp, uint32 *stat_buf, int32 size, uint32 *tot_size, uint32 mini_size);
|
||||
int32 mmpool2_add_region(struct mmpool2 *mp, uint32 addr, uint32 size);
|
||||
uint32 mmpool2_free_size(struct mmpool2 *mp, uint32 min);
|
||||
int32 mmpool2_of_check(struct mmpool2 *mp, uint32 addr, uint32 size);
|
||||
int32 mmpool2_valid_addr(struct mmpool2 *mp, uint32 addr);
|
||||
int32 mmpool2_perfermance(struct mmpool2 *mp, uint8 alloc, uint32 *values, uint32 count);
|
||||
int32 mmpool2_used_list(struct mmpool2 *mp, uint32_t *list_buf, int32 list_size);
|
||||
void mmpool2_dump(struct mmpool2 *mp);
|
||||
void mmpool2_time(struct mmpool2 *mp, uint32 *alloc_time, uint32 *free_time);
|
||||
|
||||
void *mmpool3_alloc(struct mmpool3 *mp, uint32 size, const char *func, int32 line);
|
||||
void mmpool3_free(struct mmpool3 *mp, void *ptr);
|
||||
int32 mmpool3_add_region(struct mmpool3 *mp, uint32 addr, uint32 size, uint32 blk_size);
|
||||
int32 mmpool3_init(struct mmpool3 *mp, uint32 addr, uint32 size, uint32 blk_size);
|
||||
uint32 mmpool3_free_size(struct mmpool3 *mp, uint32 min);
|
||||
int32 mmpool3_free_state(struct mmpool3 *mp, uint32 *stat_buf, int32 size, uint32 *tot_size);
|
||||
int32 mmpool3_used_state(struct mmpool3 *mp, uint32 *stat_buf, int32 size, uint32 *tot_size, uint32 mini_size);
|
||||
int32 mmpool3_of_check(struct mmpool3 *mp, uint32 addr, uint32 size);
|
||||
int32 mmpool3_valid_addr(struct mmpool3 *mp, uint32 addr);
|
||||
int32 mmpool3_perfermance(struct mmpool3 *mp, uint8 alloc, uint32 *values, uint32 count);
|
||||
int32 mmpool3_used_list(struct mmpool3 *mp, uint32_t *list_buf, int32 list_size);
|
||||
void mmpool3_dump(struct mmpool3 *mp);
|
||||
void mmpool3_time(struct mmpool3 *mp, uint32 *alloc_time, uint32 *free_time);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#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];
|
||||
};
|
||||
|
||||
#define mpool_free_size(pool) ((pool)->heap_end-(pool)->heap_ptr)
|
||||
int mpool_init(struct mem_pool *pool, unsigned int block_size, unsigned int mem_addr, unsigned int mem_size);
|
||||
void mpool_free(struct mem_pool *pool, void *ptr);
|
||||
void *mpool_alloc(struct mem_pool *pool, unsigned int size);
|
||||
void mpool_state(struct mem_pool *pool, char *state_buf, int32 buf_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
#ifndef _SYS_HEAP_H_
|
||||
#define _SYS_HEAP_H_
|
||||
|
||||
#include "lib/heap/mmpool.h"
|
||||
|
||||
enum SYSHEAP_FLAGS {
|
||||
SYSHEAP_FLAGS_MEM_LEAK_TRACE = (1u << 0),
|
||||
SYSHEAP_FLAGS_MEM_OVERFLOW_CHECK = (1u << 1),
|
||||
SYSHEAP_FLAGS_MEM_ALIGN_16 = (1u << 2),
|
||||
};
|
||||
|
||||
//#define MMPOOL3
|
||||
|
||||
#ifdef MMPOOL3
|
||||
#define MMPOOL mmpool3
|
||||
#elif defined(MMPOOL2)
|
||||
#define MMPOOL mmpool2
|
||||
#else
|
||||
#define MMPOOL mmpool
|
||||
#endif
|
||||
|
||||
struct sys_heap {
|
||||
const char *name;
|
||||
uint32 flags;
|
||||
struct MMPOOL pool;
|
||||
};
|
||||
|
||||
int32 sysheap_init(struct sys_heap *heap, void *heap_start, unsigned int heap_size, unsigned int flags);
|
||||
uint32 sysheap_time(struct sys_heap *heap);
|
||||
void *sysheap_alloc(struct sys_heap *heap, int size, const char *func, int line);
|
||||
void 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, uint32 start, uint32 end);
|
||||
int32 sysheap_add(struct sys_heap *heap, void *heap_start, uint32 heap_size);
|
||||
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);
|
||||
uint32 sysheap_time(struct sys_heap *heap);
|
||||
int sysheap_use_list(struct sys_heap *heap, uint32_t *list_buf, int32 buf_size);
|
||||
void sysheap_dump(struct sys_heap *heap);
|
||||
|
||||
extern struct sys_heap sram_heap;
|
||||
extern struct sys_heap psram_heap;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
#ifndef _SYS_HEAP_PSRAM_H_
|
||||
#define _SYS_HEAP_PSRAM_H_
|
||||
#include "sysheap.h" //主要为了共用SYSHEAP_FLAGS
|
||||
|
||||
|
||||
int sysheap_psram_init(void *heap_start, unsigned int heap_size, unsigned int flags);
|
||||
void *sysheap_psram_alloc(int size, const char *func, int line);
|
||||
void sysheap_psram_free(void *ptr);
|
||||
void sysheap_psram_collect_init(void);
|
||||
int32 sysheap_psram_of_check(void *ptr, uint32 size);
|
||||
void psram_mm_init(void *start,uint32 size);
|
||||
#ifdef MPOOL_ALLOC
|
||||
void sysheap_psram_status(void);
|
||||
#else
|
||||
#define sysheap_status()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user