diff --git a/bsp/board/bl808dk/board.c b/bsp/board/bl808dk/board.c index 08d30205..1fd7b80c 100644 --- a/bsp/board/bl808dk/board.c +++ b/bsp/board/bl808dk/board.c @@ -267,8 +267,13 @@ void board_init(void) bl_show_log(); bl_show_flashinfo(); - +#ifdef CONFIG_TLSF + bflb_tlsf_size_container_t *tlsf_size = bflb_tlsf_stats(); + printf("TLSF Dynamic Memory Init Success: Heap Size = %d Kbyte, Used Size = %d Kbyte, Free Size = %d Kbyte\r\n", + tlsf_size->free + tlsf_size->used / 1024, tlsf_size->used / 1024, tlsf_size->free / 1024); +#else printf("dynamic memory init success,heap size = %d Kbyte \r\n", system_mmheap[0].mem_size / 1024); +#endif printf("sig1:%08x\r\n", BL_RD_REG(GLB_BASE, GLB_UART_CFG1)); printf("sig2:%08x\r\n", BL_RD_REG(GLB_BASE, GLB_UART_CFG2)); diff --git a/components/tlsf/bflb_tlsf.c b/components/tlsf/bflb_tlsf.c index c9bcbae7..e656bb6c 100644 --- a/components/tlsf/bflb_tlsf.c +++ b/components/tlsf/bflb_tlsf.c @@ -56,4 +56,22 @@ void *bflb_malloc_align(size_t align, size_t size) ptr = tlsf_memalign(tlsf_ptr, align, size); return ptr; +} + +void tlsf_size_walker(void* ptr, size_t size, int used, void* user) +{ + if (used) { + ((bflb_tlsf_size_container_t *)user)->used += (unsigned int)size; + } + else { + ((bflb_tlsf_size_container_t *)user)->free += (unsigned int)size; + } +} + +bflb_tlsf_size_container_t *bflb_tlsf_stats() { + static bflb_tlsf_size_container_t sizes; + sizes.free = 0; + sizes.used = 0; + tlsf_walk_pool(tlsf_get_pool(tlsf_ptr), tlsf_size_walker, &sizes); + return &sizes; } \ No newline at end of file diff --git a/components/tlsf/bflb_tlsf.h b/components/tlsf/bflb_tlsf.h index c71b0e9d..6b3bad5f 100644 --- a/components/tlsf/bflb_tlsf.h +++ b/components/tlsf/bflb_tlsf.h @@ -4,11 +4,17 @@ #include #include +typedef struct { + unsigned free; /**< total free size */ + unsigned used; /**< total used size */ +} bflb_tlsf_size_container_t; + int bflb_mmheap_init(void *begin_addr, uint32_t size); void *bflb_malloc(size_t nbytes); void bflb_free(void *ptr); void *bflb_realloc(void *ptr, size_t nbytes); void *bflb_calloc(size_t count, size_t size); void *bflb_malloc_align(size_t align, size_t size); +bflb_tlsf_size_container_t *bflb_tlsf_stats(); #endif \ No newline at end of file diff --git a/components/tlsf/tlsf.c b/components/tlsf/tlsf.c index 08d2a15f..dfc0b851 100644 --- a/components/tlsf/tlsf.c +++ b/components/tlsf/tlsf.c @@ -7,6 +7,8 @@ #include "tlsf.h" +#pragma GCC diagnostic ignored "-Wunused-value" + #if defined(__cplusplus) #define tlsf_decl inline #else @@ -1066,7 +1068,7 @@ void tlsf_remove_pool(tlsf_t tlsf, pool_t pool) ** TLSF main interface. */ -#if _DEBUG +#ifdef _DEBUG int test_ffs_fls() { /* Verify ffs/fls work properly. */ @@ -1096,7 +1098,7 @@ int test_ffs_fls() tlsf_t tlsf_create(void *mem) { -#if _DEBUG +#ifdef _DEBUG if (test_ffs_fls()) { return 0;