diff options
Diffstat (limited to 'src/mem.c')
| -rw-r--r-- | src/mem.c | 37 |
1 files changed, 22 insertions, 15 deletions
@@ -54,6 +54,15 @@ /** * memory item on the small mem */ + +#define DBG_TAG "kernel.mem" +#ifdef RT_DEBUG_MEM +#define DBG_LVL DBG_LOG +#else +#define DBG_LVL DBG_WARNING +#endif /* defined (RT_DEBUG_MEM) */ +#include <rtdbg.h> + struct rt_small_mem_item { rt_ubase_t pool_ptr; /**< small memory object addr */ @@ -213,8 +222,8 @@ rt_smem_t rt_smem_init(const char *name, /* point to begin address of heap */ small_mem->heap_ptr = (rt_uint8_t *)begin_align; - RT_DEBUG_LOG(RT_DEBUG_MEM, ("mem init, heap begin address 0x%x, size %d\n", - (rt_ubase_t)small_mem->heap_ptr, small_mem->mem_size_aligned)); + LOG_D("mem init, heap begin address 0x%x, size %d", + (rt_ubase_t)small_mem->heap_ptr, small_mem->mem_size_aligned); /* initialize the start of the heap */ mem = (struct rt_small_mem_item *)small_mem->heap_ptr; @@ -290,12 +299,12 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size) if (size != RT_ALIGN(size, RT_ALIGN_SIZE)) { - RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d, but align to %d\n", - size, RT_ALIGN(size, RT_ALIGN_SIZE))); + LOG_D("malloc size %d, but align to %d", + size, RT_ALIGN(size, RT_ALIGN_SIZE)); } else { - RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d\n", size)); + LOG_D("malloc size %d", size); } small_mem = (struct rt_small_mem *)m; @@ -308,7 +317,7 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size) if (size > small_mem->mem_size_aligned) { - RT_DEBUG_LOG(RT_DEBUG_MEM, ("no memory\n")); + LOG_D("no memory"); return RT_NULL; } @@ -393,10 +402,9 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size) RT_ASSERT((rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0); RT_ASSERT((((rt_ubase_t)mem) & (RT_ALIGN_SIZE - 1)) == 0); - RT_DEBUG_LOG(RT_DEBUG_MEM, - ("allocate memory at 0x%x, size: %d\n", - (rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM), - (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - small_mem->heap_ptr)))); + LOG_D("allocate memory at 0x%x, size: %d", + (rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM), + (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - small_mem->heap_ptr))); /* return the memory data except mem struct */ return (rt_uint8_t *)mem + SIZEOF_STRUCT_MEM; @@ -435,7 +443,7 @@ void *rt_smem_realloc(rt_smem_t m, void *rmem, rt_size_t newsize) newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE); if (newsize > small_mem->mem_size_aligned) { - RT_DEBUG_LOG(RT_DEBUG_MEM, ("realloc: out of memory\n")); + LOG_D("realloc: out of memory"); return RT_NULL; } @@ -534,10 +542,9 @@ void rt_smem_free(void *rmem) (rt_uint8_t *)rmem < (rt_uint8_t *)small_mem->heap_end); RT_ASSERT(MEM_POOL(&small_mem->heap_ptr[mem->next]) == small_mem); - RT_DEBUG_LOG(RT_DEBUG_MEM, - ("release memory 0x%x, size: %d\n", - (rt_ubase_t)rmem, - (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - small_mem->heap_ptr)))); + LOG_D("release memory 0x%x, size: %d", + (rt_ubase_t)rmem, + (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - small_mem->heap_ptr))); /* ... and is now unused. */ mem->pool_ptr = MEM_FREED(); |
