add a new command list_memheap() into finsh
and unify the coding style in memheap.c git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2151 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
f19d8aa591
commit
43f2bfc013
|
@ -26,6 +26,7 @@
|
|||
* 2009-05-30 Bernard add list_device
|
||||
* 2010-04-21 yi.qiu add list_module
|
||||
* 2012-04-29 goprife improve the command line auto-complete feature.
|
||||
* 2012-06-02 lgnq add list_memheap
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
@ -60,8 +61,6 @@ long version(void)
|
|||
}
|
||||
FINSH_FUNCTION_EXPORT(version, show RT-Thread version information);
|
||||
|
||||
#define rt_list_entry(node, type, member) \
|
||||
((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
|
||||
extern struct rt_object_information rt_object_container[];
|
||||
|
||||
static long _list_thread(struct rt_list_node *list)
|
||||
|
@ -91,8 +90,8 @@ static long _list_thread(struct rt_list_node* list)
|
|||
thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr),
|
||||
thread->remaining_tick,
|
||||
thread->error);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -111,7 +110,9 @@ static void show_wait_queue(struct rt_list_node* list)
|
|||
{
|
||||
thread = rt_list_entry(node, struct rt_thread, tlist);
|
||||
rt_kprintf("%s", thread->name);
|
||||
if (node->next != list) rt_kprintf("/");
|
||||
|
||||
if (node->next != list)
|
||||
rt_kprintf("/");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,6 +280,32 @@ long list_msgqueue(void)
|
|||
FINSH_FUNCTION_EXPORT(list_msgqueue, list message queue in system)
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_MEMHEAP
|
||||
static long _list_memheap(struct rt_list_node *list)
|
||||
{
|
||||
struct rt_memheap *mh;
|
||||
struct rt_list_node *node;
|
||||
|
||||
rt_kprintf("memheap pool size available size\n");
|
||||
rt_kprintf("-------- --------- --------------\n");
|
||||
for (node = list->next; node != list; node = node->next)
|
||||
{
|
||||
mh = (struct rt_memheap *)rt_list_entry(node, struct rt_object, list);
|
||||
|
||||
rt_kprintf("%-8.*s %04d %04d\n", RT_NAME_MAX, mh->parent.name,
|
||||
mh->pool_size, mh->available_size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long list_memheap(void)
|
||||
{
|
||||
return _list_memheap(&rt_object_container[RT_Object_Class_MemHeap].object_list);
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(list_memheap, list memory heap in system)
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_MEMPOOL
|
||||
static long _list_mempool(struct rt_list_node *list)
|
||||
{
|
||||
|
@ -327,8 +354,10 @@ static long _list_timer(struct rt_list_node *list)
|
|||
{
|
||||
timer = (struct rt_timer *)(rt_list_entry(node, struct rt_object, list));
|
||||
rt_kprintf("%-8.*s 0x%08x 0x%08x ", RT_NAME_MAX, timer->parent.name, timer->init_tick, timer->timeout_tick);
|
||||
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) rt_kprintf("activated\n");
|
||||
else rt_kprintf("deactivated\n");
|
||||
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
|
||||
rt_kprintf("activated\n");
|
||||
else
|
||||
rt_kprintf("deactivated\n");
|
||||
}
|
||||
|
||||
rt_kprintf("current tick:0x%08x\n", rt_tick_get());
|
||||
|
@ -476,6 +505,11 @@ int list_mod_detail(const char* name)
|
|||
tlist = &module->module_object[RT_Object_Class_MessageQueue].object_list;
|
||||
if (!rt_list_isempty(tlist)) _list_msgqueue(tlist);
|
||||
#endif
|
||||
#ifdef RT_USING_MEMHEAP
|
||||
/* list memory heap in module */
|
||||
tlist = &module->module_object[RT_Object_Class_MemHeap].object_list;
|
||||
if (!rt_list_isempty(tlist)) _list_memheap(tlist);
|
||||
#endif
|
||||
#ifdef RT_USING_MEMPOOL
|
||||
/* list memory pool in module */
|
||||
tlist = &module->module_object[RT_Object_Class_MemPool].object_list;
|
||||
|
@ -564,7 +598,9 @@ static int str_is_prefix(const char* prefix, const char* str)
|
|||
str ++;
|
||||
}
|
||||
|
||||
if (*prefix == 0) return 0;
|
||||
if (*prefix == 0)
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -572,7 +608,7 @@ static int str_common(const char * str1, const char * str2)
|
|||
{
|
||||
const char *str = str1;
|
||||
|
||||
while( *str !=0 && *str2 !=0 && (*str == *str2))
|
||||
while ((*str != 0) && (*str2 != 0) && (*str == *str2))
|
||||
{
|
||||
str ++;
|
||||
str2 ++;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* Date Author Notes
|
||||
* 2012-04-10 Bernard first implementation
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef RT_USING_MEMHEAP
|
||||
|
@ -118,7 +119,8 @@ void* rt_memheap_alloc(struct rt_memheap *pool_ptr, rt_uint32_t size)
|
|||
|
||||
/* align allocated size */
|
||||
size = RT_ALIGN(size, RT_ALIGN_SIZE);
|
||||
if (size < RT_MEMHEAP_MINIALLOC) size = RT_MEMHEAP_MINIALLOC;
|
||||
if (size < RT_MEMHEAP_MINIALLOC)
|
||||
size = RT_MEMHEAP_MINIALLOC;
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("allocate %d", size));
|
||||
|
||||
|
@ -207,6 +209,7 @@ void* rt_memheap_alloc(struct rt_memheap *pool_ptr, rt_uint32_t size)
|
|||
/* Return a memory address to the caller. */
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("am: m[0x%08x], h[0x%08x], size: %d",
|
||||
(void *)((rt_uint8_t *)header_ptr + RT_MEMHEAP_SIZE), header_ptr, size);
|
||||
|
||||
return (void *)((rt_uint8_t *)header_ptr + RT_MEMHEAP_SIZE));
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +227,8 @@ void rt_memheap_free(void* ptr)
|
|||
rt_uint32_t insert_header;
|
||||
|
||||
/* set initial status as OK */
|
||||
insert_header = 1; new_ptr = RT_NULL;
|
||||
insert_header = 1;
|
||||
new_ptr = RT_NULL;
|
||||
header_ptr = (struct rt_memheap_item *)((rt_uint8_t *)ptr - RT_MEMHEAP_SIZE);
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("free memory: m[0x%08x], h[0x%08x]", ptr, header_ptr));
|
||||
|
@ -257,7 +261,8 @@ void rt_memheap_free(void* ptr)
|
|||
|
||||
/* move header pointer to previous. */
|
||||
header_ptr = header_ptr->prev;
|
||||
insert_header = 0; /* don't insert header to free list */
|
||||
/* don't insert header to free list */
|
||||
insert_header = 0;
|
||||
}
|
||||
|
||||
/* determine if the block can be merged with the next neighbor. */
|
||||
|
|
Loading…
Reference in New Issue