📄 lib_mem.h
字号:
#define LIB_MEM_ERR_INVALID_BLK_ALIGN 10132u /* Invalid mem pool blk align. */
#define LIB_MEM_ERR_INVALID_BLK_IX 10133u /* Invalid mem pool ix. */
#define LIB_MEM_ERR_INVALID_BLK_ADDR 10135u /* Invalid mem pool blk addr. */
#define LIB_MEM_ERR_INVALID_BLK_ADDR_IN_POOL 10136u /* Mem pool blk addr already in mem pool. */
#define LIB_MEM_ERR_SEG_EMPTY 10200u /* Mem seg empty; i.e. NO avail mem in seg. */
#define LIB_MEM_ERR_SEG_OVF 10201u /* Mem seg ovf; i.e. req'd mem ovfs rem mem in seg. */
#define LIB_MEM_ERR_POOL_FULL 10205u /* Mem pool full; i.e. all mem blks avail in mem pool. */
#define LIB_MEM_ERR_POOL_EMPTY 10206u /* Mem pool empty; i.e. NO mem blks avail in mem pool. */
#define LIB_MEM_ERR_HEAP_NOT_FOUND 10210u /* Heap seg NOT found. */
#define LIB_MEM_ERR_HEAP_EMPTY 10211u /* Heap seg empty; i.e. NO avail mem in heap. */
#define LIB_MEM_ERR_HEAP_OVF 10212u /* Heap seg ovf; i.e. req'd mem ovfs rem mem in heap. */
/*
*********************************************************************************************************
* MEMORY LIBRARY TYPE DEFINES
*
* Note(s) : (1) LIB_MEM_TYPE_&&& #define values specifically chosen as ASCII representations of the memory
* library types. Memory displays of memory library objects will display the library TYPEs
* with their chosen ASCII names.
*********************************************************************************************************
*/
#define LIB_MEM_TYPE_NONE CPU_TYPE_CREATE('N', 'O', 'N', 'E')
#define LIB_MEM_TYPE_HEAP CPU_TYPE_CREATE('H', 'E', 'A', 'P')
#define LIB_MEM_TYPE_POOL CPU_TYPE_CREATE('P', 'O', 'O', 'L')
/*$PAGE*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LIB MEM TYPE
*
* Note(s) : (1) 'LIB_MEM_TYPE' declared as 'CPU_INT32U' & all 'LIB_MEM_TYPE's #define'd with large, non-trivial
* values to trap & discard invalid/corrupted library memory objects based on 'LIB_MEM_TYPE'.
*********************************************************************************************************
*/
typedef CPU_INT32U LIB_MEM_TYPE;
/*
*********************************************************************************************************
* MEMORY POOL TABLE IX TYPE
*
* Note(s) : (1) MEM_POOL_IX_NONE SHOULD be #define'd based on 'MEM_POOL_IX' data type declared.
*********************************************************************************************************
*/
typedef CPU_INT16U MEM_POOL_IX;
#define MEM_POOL_IX_NONE DEF_INT_16U_MAX_VAL /* Define as max unsigned val (see Note #1). */
#define MEM_POOL_IX_MIN 1u
#define MEM_POOL_IX_MAX (MEM_POOL_IX_NONE - 1u)
/*$PAGE*/
/*
*********************************************************************************************************
* MEMORY POOL DATA TYPES
*
* MEMORY SEGMENT
* ----------------
* MEMORY POOL'S | | <----
* POINTERS TO | MEMORY | |
* MEM_POOL MEMORY BLOCKS | BLOCKS | |
* |----------------| |---------| | -------- | |
* | O------------------> | O--------------------> | | | |
* |----------------| |---------| | | | | |
* | Pool Addr Ptrs | | O------------- | -------- | |
* | Pool Size | |---------| | | | |
* |----------------| | | | | -------- | |
* | Blk Size | | | --------> | | | |
* | Blk Nbr | | | | | | | |
* | Blk Ix | | . | | -------- | |
* |----------------| | . | | | |
* |----------------| | . | | . | |
* | O----------------- | | | . | |
* |----------------| | | | | . | |
* | O------------ | | | | | |
* |----------------| | | |---------| | -------- | |
* | Seg Size Tot | | | | O--------------------> | | | |
* | Seg Size Rem | | | |---------| | | | | |
* |----------------| | | | | | -------- | |
* | Seg List Ptrs | | | |---------| | | |
* |----------------| | | | ------------ | |
* | | | | <--------
* | | | | | |
* | | | | | |
* | | | | | |
* | | | | | |
* | | | | | |
* | | ---------------- | |
* | | | |
* | -------------------------------------------------- |
* | |
* -----------------------------------------------------------
*
*********************************************************************************************************
*/
typedef struct mem_pool MEM_POOL;
/* --------------------- MEM POOL --------------------- */
struct mem_pool {
LIB_MEM_TYPE Type; /* Pool type : LIB_TYPE_POOL or LIB_TYPE_HEAP. */
MEM_POOL *SegPrevPtr; /* Ptr to PREV mem seg. */
MEM_POOL *SegNextPtr; /* Ptr to NEXT mem seg. */
MEM_POOL *PoolPrevPtr; /* Ptr to PREV mem pool. */
MEM_POOL *PoolNextPtr; /* Ptr to NEXT mem pool. */
void *PoolAddrStart; /* Ptr to start of mem seg for mem pool blks. */
void *PoolAddrEnd; /* Ptr to end of mem seg for mem pool blks. */
void **PoolPtrs; /* Ptr to mem pool's array of blk ptrs. */
MEM_POOL_IX BlkIx; /* Ix into mem pool's array of blk ptrs. */
CPU_SIZE_T PoolSize; /* Size of mem pool (in octets). */
CPU_SIZE_T BlkNbr; /* Nbr of mem pool blks. */
CPU_SIZE_T BlkSize; /* Size of mem pool blks (in octets). */
CPU_SIZE_T BlkAlign; /* Align of mem pool blks (in octets). */
/* --------------------- MEM SEG ---------------------- */
void *SegAddr; /* Ptr to mem seg's base/start addr. */
void *SegAddrNextAvail; /* Ptr to mem seg's next avail addr. */
CPU_SIZE_T SegSizeTot; /* Tot size of mem seg (in octets). */
CPU_SIZE_T SegSizeRem; /* Rem size of mem seg (in octets). */
};
/*$PAGE*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MEMORY DATA VALUE MACRO'S
*
* Note(s) : (1) (a) Some variables & variable buffers to pass & receive data values MUST start on appropriate
* CPU word-aligned addresses. This is required because most word-aligned processors are more
* efficient & may even REQUIRE that multi-octet words start on CPU word-aligned addresses.
*
* (1) For 16-bit word-aligned processors, this means that
*
* all 16- & 32-bit words MUST start on addresses that are multiples of 2 octets
*
* (2) For 32-bit word-aligned processors, this means that
*
* all 16-bit words MUST start on addresses that are multiples of 2 octets
* all 32-bit words MUST start on addresses that are multiples of 4 octets
*
* (b) However, some data values macro's appropriately access data values from any CPU addresses,
* word-aligned or not. Thus for processors that require data word alignment, data words can
* be accessed to/from any CPU address, word-aligned or not, without generating data-word-
* alignment exceptions/faults.
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* ENDIAN WORD ORDER MACRO'S
*
* Description : Convert data values to & from big-, little, or host-endian CPU word order.
*
* Argument(s) : val Data value to convert (see Notes #1 & #2).
*
* Return(s) : Converted data value (see Notes #1 & #2).
*
* Caller(s) : Application.
*
* Note(s) : (1) Convert data values to the desired data-word order :
*
* MEM_VAL_BIG_TO_LITTLE_xx() Convert big- endian data values
* to little- endian data values
* MEM_VAL_LITTLE_TO_BIG_xx() Convert little- endian data values
* to big- endian data values
* MEM_VAL_xxx_TO_HOST_xx() Convert big-/little-endian data values
* to host- endian data values
* MEM_VAL_HOST_TO_xxx_xx() Convert host- endian data values
* to big-/little-endian data values
*
* See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
*
* (2) 'val' data value to convert & any variable to receive the returned conversion MUST
* start on appropriate CPU word-aligned addresses.
*
* See also 'MEMORY DATA VALUE MACRO'S Note #1a'.
*
* (3) MEM_VAL_COPY_xxx() macro's are more efficient than generic endian word order macro's &
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -