bs_bcu_app/bsp/bsp_malloc.h

88 lines
3.7 KiB
C
Raw Blame History

/**
****************************************************************************************************
* @file malloc.c
* @author ヤ嗷秷諷
* @version V1.0
* @date 2024-03-10
* @brief 囀湔奪燴 Й雄
****************************************************************************************************
*/
#ifndef __MALLOC_H
#define __MALLOC_H
#include "drv_sys.h"
/* 摰帋<E691B0><E5B88B>凋葵<E5878B><E891B5><EFBFBD><EFBFBD> */
#define SRAMIN 0 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define SRAMCCM 1 /* CCM<43><4D><EFBFBD><EFBFBD>(甇日<E79487><E697A5><EFBFBD>RAM隞<4D><E99A9E>CPU<50>臭誑霈輸䔮!!!) */
#define SRAMEX 2 /* 憭㚚<E686AD><E39A9A><EFBFBD><EFBFBD><EFBFBD> */
#define SRAMBANK 3 /* 摰帋<E691B0><E5B88B><EFBFBD><E88880><EFBFBD>RAM<41>埈㺭 */
/* 摰帋<E691B0><E5B88B><EFBFBD><EFBFBD>蝞∠<E89D9E>銵函掩<E587BD><E68EA9>,敶枏<E695B6><E69E8F>咎DRAM<41><4D>𧒄<EFBFBD><EFBFBD><EFBFBD>◆雿輻鍂uint32_t蝐餃<E89D90><EFBFBD><EFBFBD>坔虾隞亙<E99A9E>銋㗇<E98A8B>uint16_t嚗䔶誑<E494B6><E8AA91><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>删鍂 */
#define MT_TYPE uint16_t
/* <20><EFBFBD><E8A8AB><EFBFBD><EFBFBD><EFBFBD><E59A97>摮条恣<E69DA1><E681A3><EFBFBD><EFBFBD>删鍂<E588A0><E98D82><EFBFBD><EFBFBD>函征<E587BD>游之撠讛恣蝞堒<E89D9E>撘誩<E69298>銝页<E98A9D>
* size = MEM1_MAX_SIZE + (MEM1_MAX_SIZE / MEM1_BLOCK_SIZE) * sizeof(MT_TYPE)
* 隞兄RAMEX銝箔<E98A9D>嚗众ize = 963 * 1024 + (963 * 1024 / 32) * 2 = 1047744 <20><> 1023KB
* 撌脩䰻<E884A9><EFBFBD>摮睃捆<E79D83><E68D86>(size)嚗峕<E59A97>憭批<E686AD>摮䀹<E691AE><E480B9><EFBFBD>恣蝞堒<E89D9E>撘誩<E69298>銝页<E98A9D>
* MEM1_MAX_SIZE = (MEM1_BLOCK_SIZE * size) / (MEM1_BLOCK_SIZE + sizeof(MT_TYPE))
* 隞丘CM銝箔<E98A9D>, MEM2_MAX_SIZE = (32 * 64) / (32 + 2) = 60.24KB <20><> 60KB
*/
/* mem1<6D><31><EFBFBD><EFBFBD><EFBFBD>㺭霈曉<E99C88>.mem1摰<31><E691B0><EFBFBD><E686AD><EFBFBD><EFBFBD><EFBFBD>SRAM<41>屸𢒰 */
#define MEM1_BLOCK_SIZE 32 /* <20><><EFBFBD><EFBFBD>堒之撠譍蛹32摮𡑒<E691AE> */
#define MEM1_MAX_SIZE 100*1024 /* <20><>憭抒恣<E68A92><E681A3><EFBFBD><EFBFBD> 100K */
#define MEM1_ALLOC_TABLE_SIZE MEM1_MAX_SIZE/MEM1_BLOCK_SIZE /* <20><><EFBFBD>銵典之撠<E4B98B> */
/* mem2<6D><32><EFBFBD><EFBFBD><EFBFBD>㺭霈曉<E99C88>.mem2憭<32><E686AD>CCM,<2C><EFBFBD>蝞∠<E89D9E>CCM(<28><EFBFBD>瘜冽<E7989C>,餈䠷<E9A488><E4A0B7><EFBFBD>RAM,隞<>PU<50>臭誑霈輸䔮!!) */
#define MEM2_BLOCK_SIZE 32 /* <20><><EFBFBD><EFBFBD>堒之撠譍蛹32摮𡑒<E691AE> */
#define MEM2_MAX_SIZE 60 *1024 /* <20><>憭抒恣<E68A92><E681A3><EFBFBD><EFBFBD>60K */
#define MEM2_ALLOC_TABLE_SIZE MEM2_MAX_SIZE/MEM2_BLOCK_SIZE /* <20><><EFBFBD>銵典之撠<E4B98B> */
/* mem3<6D><33><EFBFBD><EFBFBD><EFBFBD>㺭霈曉<E99C88>.mem3<6D><EFBFBD><E887AC>咎RAM */
#define MEM3_BLOCK_SIZE 32 /* <20><><EFBFBD><EFBFBD>堒之撠譍蛹32摮𡑒<E691AE> */
#define MEM3_MAX_SIZE 963 *1024 /* <20><>憭抒恣<E68A92><E681A3><EFBFBD><EFBFBD>963K */
#define MEM3_ALLOC_TABLE_SIZE MEM3_MAX_SIZE/MEM3_BLOCK_SIZE /* <20><><EFBFBD>銵典之撠<E4B98B> */
/* 憒<><E68692>瘝⊥<E7989D>摰帋<E691B0>NULL, 摰帋<E691B0>NULL */
#ifndef NULL
#define NULL 0
#endif
/* <20><><EFBFBD>蝞∠<E89D9E><E288A0><EFBFBD><E689B9><EFBFBD> */
struct _m_mallco_dev
{
void (*init)(uint8_t); /* <20><EFBFBD><E598A5><EFBFBD> */
uint16_t (*perused)(uint8_t); /* <20><><EFBFBD>雿輻鍂<E8BCBB><E98D82> */
uint8_t *membase[SRAMBANK]; /* <20><><EFBFBD><EFBFBD> 蝞∠<E89D9E>SRAMBANK銝芸躹<E88AB8><EFBFBD><E6AFBA><EFBFBD><EFBFBD> */
MT_TYPE *memmap[SRAMBANK]; /* <20><><EFBFBD>蝞∠<E89D9E><E288A0><EFBFBD><E59786>” */
uint8_t memrdy[SRAMBANK]; /* <20><><EFBFBD>蝞∠<E89D9E><E288A0>臬炏撠梁貌 */
};
extern struct _m_mallco_dev mallco_dev; /* <20>皂allco.c<>屸𢒰摰帋<E691B0> */
/* <20><EFBFBD><EFBFBD><EFBFBD>賣㺭 */
void my_mem_init(uint8_t memx); /* <20><><EFBFBD>蝞∠<E89D9E><E288A0><EFBFBD><E598A5>硋遆<E7A18B><E98186>(憭<>/<2F><><EFBFBD><EFBFBD>鍂) */
uint16_t my_mem_perused(uint8_t memx) ; /* <20><EFBFBD><E79195><EFBFBD><EFBFBD>雿輻鍂<E8BCBB><E98D82>(憭<>/<2F><><EFBFBD><EFBFBD>鍂) */
void my_mem_set(void *s, uint8_t c, uint32_t count);/* <20><><EFBFBD>霈曄蔭<E69B84>賣㺭 */
void my_mem_copy(void *des, void *src, uint32_t n); /* <20><><EFBFBD><EFBFBD><EFBFBD><E79181>賣㺭 */
void myfree(uint8_t memx, void *ptr); /* <20><><EFBFBD><EFBFBD>𦠜𦆮(憭㚚<E686AD><EFBFBD>鍂) */
void *mymalloc(uint8_t memx, uint32_t size); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(憭㚚<E686AD><EFBFBD>鍂) */
void *myrealloc(uint8_t memx, void *ptr, uint32_t size); /* <20>齿鰵<E9BDBF><E9B0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(憭㚚<E686AD><EFBFBD>鍂) */
#endif