X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/93ea25f2ec6e99ef5ba3068112eafab265087089..2d23b44169ebf0e91e2262bc33a6ed62e62ae137:/avr/debug.c diff --git a/avr/debug.c b/avr/debug.c index 21dd242..ea4aa21 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -22,19 +22,6 @@ #ifdef DEBUG - -#if 0 -void dump_heap(void) -{ - extern unsigned int __brkval; - - dump_ram(__malloc_heap_start, - __brkval - (unsigned int) __malloc_heap_start, - "=== Heap:"); -} -#endif - - /* * Memory Display * md addr {len} @@ -212,11 +199,16 @@ struct __freelist { struct __freelist *nx; }; -extern char *__brkval; /* first location not yet allocated */ -extern struct __freelist *__flp; /* freelist pointer (head of freelist) */ +extern char *__brkval; /* first location not yet allocated */ +extern struct __freelist *__flp; /* freelist pointer (head of freelist) */ #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG) +size_t get_freemem(void) +{ + return (size_t) STACK_POINTER() - __malloc_margin - (size_t) __brkval; +} + void printfreelist(const char * title) { @@ -224,26 +216,24 @@ printfreelist(const char * title) int i; unsigned int freesum = 0; -/* TODO: printf_P */ - if (!__flp) { - printf("%s no free list\n", title ? title : ""); + printf_P(PSTR("%s no free list\n"), title ? title : ""); } else { - printf("Free list: %s\n", title ? title : ""); + printf_P(PSTR("Free list: %s\n"), title ? title : ""); for (i = 0, fp1 = __flp; fp1; i++, fp1 = fp1->nx) { - printf(" entry %d @ %04x: size %4u, next ", + printf_P(PSTR(" entry %d @ %04x: size %4u, next "), i, (size_t)fp1, fp1->sz); if (fp1->nx) - printf("%04x\n", (size_t)fp1->nx); + printf_P(PSTR("%04x\n"), (size_t)fp1->nx); else - printf("NULL\n"); + printf_P(PSTR("NULL\n")); freesum += fp1->sz; } } - freesum += (size_t) STACK_POINTER() - __malloc_margin - (size_t) __brkval; + freesum += get_freemem(); - printf("SP: %04x, __brkval: %04x, Total free: %04u\n", + printf_P(PSTR("SP: %04x, __brkval: %04x, Total free: %04u\n"), (size_t) STACK_POINTER(), (size_t) __brkval, freesum); } @@ -254,4 +244,19 @@ command_ret_t do_pr_free_avr(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, return CMD_RET_SUCCESS; } +void dump_heap(void) +{ + //extern unsigned int __brkval; + + dump_ram((uint8_t *)__malloc_heap_start, (size_t) __malloc_heap_start, __brkval - __malloc_heap_start, + "=== Heap:"); +} + +command_ret_t do_pr_heap_avr(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED) +{ + dump_heap(); + + return CMD_RET_SUCCESS; +} + #endif /* DEBUG */