?? lib_mem.c
字號:
/*
*********************************************************************************************************
* uC/LIB
* CUSTOM LIBRARY MODULES
*
* (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/LIB is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* STANDARD MEMORY OPERATIONS
*
* Filename : lib_mem.c
* Version : V1.35.00
* Programmer(s) : ITJ
* FGK
*********************************************************************************************************
* Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
*
* (a) ALL standard library functions are implemented in the custom library modules :
*
* (1) \<Custom Library Directory>\lib_*.*
*
* (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.*
*
* where
* <Custom Library Directory> directory path for custom library software
* <cpu> directory name for specific processor (CPU)
* <compiler> directory name for specific compiler
*
* (b) Product-specific library functions are implemented in individual products.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define LIB_MEM_MODULE
#include <lib_mem.h>
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
#if (LIB_MEM_CFG_ALLOC_EN == DEF_ENABLED)
MEM_POOL *Mem_PoolTbl; /* Mem pool/seg tbl. */
MEM_POOL Mem_PoolHeap; /* Mem heap pool/seg. */
#ifndef LIB_MEM_CFG_HEAP_BASE_ADDR
CPU_INT08U Mem_Heap[LIB_MEM_CFG_HEAP_SIZE]; /* Mem heap. */
#endif
#endif
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
#if (LIB_MEM_CFG_ALLOC_EN == DEF_ENABLED) /* -------------- MEM POOL FNCTS -------------- */
#if (LIB_MEM_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
static CPU_BOOLEAN Mem_PoolBlkIsValidAddr(MEM_POOL *pmem_pool,
void *pmem_blk);
#endif
static CPU_SIZE_T Mem_PoolSegCalcTotSize(void *pmem_addr,
CPU_SIZE_T blk_nbr,
CPU_SIZE_T blk_size,
CPU_SIZE_T blk_align);
static void *Mem_PoolSegAlloc (MEM_POOL *pmem_pool,
CPU_SIZE_T size,
CPU_SIZE_T align);
#endif
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* Mem_Init()
*
* Description : (1) Initialize Memory Management Module :
*
* (a) Initialize heap memory pool
* (b) Initialize memory pool table
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void Mem_Init (void)
{
#if (LIB_MEM_CFG_ALLOC_EN == DEF_ENABLED)
MEM_POOL *pmem_pool;
/* --------- INIT MEM HEAP SEG / POOL --------- */
pmem_pool = (MEM_POOL *)&Mem_PoolHeap;
pmem_pool->Type = (LIB_MEM_TYPE) LIB_MEM_TYPE_HEAP;
pmem_pool->SegPrevPtr = (MEM_POOL *) 0;
pmem_pool->SegNextPtr = (MEM_POOL *) 0;
pmem_pool->PoolPrevPtr = (MEM_POOL *) 0;
pmem_pool->PoolNextPtr = (MEM_POOL *) 0;
pmem_pool->PoolAddrStart = (void *) 0;
pmem_pool->PoolAddrEnd = (void *) 0;
pmem_pool->PoolPtrs = (void **) 0;
pmem_pool->BlkSize = (CPU_SIZE_T ) 0u;
pmem_pool->BlkNbr = (CPU_SIZE_T ) 0u;
pmem_pool->BlkIx = (MEM_POOL_IX ) 0u;
#ifdef LIB_MEM_CFG_HEAP_BASE_ADDR
pmem_pool->SegAddr = (void *) LIB_MEM_CFG_HEAP_BASE_ADDR;
pmem_pool->SegAddrNextAvail = (void *) LIB_MEM_CFG_HEAP_BASE_ADDR;
#else
pmem_pool->SegAddr = (void *)&Mem_Heap[0];
pmem_pool->SegAddrNextAvail = (void *)&Mem_Heap[0];
#endif
pmem_pool->SegSizeTot = (CPU_SIZE_T ) LIB_MEM_CFG_HEAP_SIZE;
pmem_pool->SegSizeRem = (CPU_SIZE_T ) LIB_MEM_CFG_HEAP_SIZE;
/* ------------ INIT MEM POOL TBL ------------- */
Mem_PoolTbl = &Mem_PoolHeap;
#endif
}
/*$PAGE*/
/*
*********************************************************************************************************
* Mem_Clr()
*
* Description : Clear data buffer (see Note #2).
*
* Argument(s) : pmem Pointer to memory buffer to clear.
*
* size Number of data buffer octets to clear (see Note #1).
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : (1) Null clears allowed (i.e. zero-length clears).
*
* See also 'Mem_Set() Note #1'.
*
* (2) Clear data by setting each data octet to 0.
*********************************************************************************************************
*/
void Mem_Clr (void *pmem,
CPU_SIZE_T size)
{
Mem_Set(pmem,
0u, /* See Note #2. */
size);
}
/*$PAGE*/
/*
*********************************************************************************************************
* Mem_Set()
*
* Description : Fill data buffer with specified data octet.
*
* Argument(s) : pmem Pointer to memory buffer to fill with specified data octet.
*
* data_val Data fill octet value.
*
* size Number of data buffer octets to fill (see Note #1).
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : (1) Null sets allowed (i.e. zero-length sets).
*
* (2) For best CPU performance, optimized to fill data buffer using 'CPU_ALIGN'-sized data
* words.
*
* (a) Since many word-aligned processors REQUIRE that multi-octet words be accessed on
* word-aligned addresses, 'CPU_ALIGN'-sized words MUST be accessed on 'CPU_ALIGN'd
* addresses.
*
* (3) Modulo arithmetic is used to determine whether a memory buffer starts on a 'CPU_ALIGN'
* address boundary.
*
* Modulo arithmetic in ANSI-C REQUIREs operations performed on integer values. Thus,
* address values MUST be cast to an appropriately-sized integer value PRIOR to any
* mem_align_modulo arithmetic operation.
*********************************************************************************************************
*/
void Mem_Set (void *pmem,
CPU_INT08U data_val,
CPU_SIZE_T size)
{
CPU_SIZE_T size_rem;
CPU_ALIGN data_align;
CPU_ALIGN *pmem_align;
CPU_INT08U *pmem_08;
CPU_INT08U mem_align_modulo;
CPU_INT08U i;
if (size < 1) { /* See Note #1. */
return;
}
if (pmem == (void *)0) {
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -