]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/debug.c
process_macros: reduce heap usage and fragmentation
[z180-stamp.git] / avr / debug.c
index 74d8ab2ad35fcc1cd9388cdae411355f6c7a742f..47b11b097cc5b51130f460eb760e5d4fd6564231 100644 (file)
@@ -12,8 +12,6 @@
  */
 #ifdef DEBUG
 
-//uint8_t eeprom_read_byte (const uint8_t *__p)
-
 static void print_blanks(uint_fast8_t count)
 {
        while(count--)
@@ -25,19 +23,22 @@ static uint8_t ram_read_byte(const uint8_t *p)
        return *p;
 }
 
-void dump_mem(const uint8_t *startaddr, int len, 
+void dump_mem(const uint8_t *startaddr, int len,
                uint8_t (*readfkt)(const uint8_t *), char *title)
 {
        uint8_t buf[16];
+       char *indent = NULL;
        uint8_t llen = 16;
        uint8_t pre = (size_t) startaddr % 16;
        const uint8_t *addr = (uint8_t *) ((size_t) startaddr & ~0x0f);
        len += pre;
        uint8_t i;
-       
-       if (title && *title)
+
+       if (title && *title) {
                printf_P(PSTR("%s\n"),title);
-               
+               indent = "    ";
+       }
+
        while (len) {
                if (len < 16)
                        llen = len;
@@ -45,7 +46,7 @@ void dump_mem(const uint8_t *startaddr, int len,
                for (i = pre; i < llen; i++)
                        buf[i] = readfkt(addr + i);
 
-               printf_P(PSTR("%04x:"), addr);
+               printf_P(PSTR("%s%04x:"),indent, addr);
                for (i = 0; i < llen; i++) {
                        if ((i % 8) == 0)
                                putchar(' ');
@@ -67,37 +68,17 @@ void dump_mem(const uint8_t *startaddr, int len,
        }
 }
 
-#if 0
-void dump_ram(const uint8_t *startaddr, int len, char *title)
+void dump_eep(const uint8_t *addr, unsigned int len, char *title)
 {
-       uint8_t llen = 16;
-       uint8_t pre = (size_t) startaddr % 16;
-       const uint8_t *addr = (uint8_t *) ((size_t) startaddr & ~0x0f);
-       len += pre;
-       uint8_t i;
-
-       if (title && *title)
-               printf_P(PSTR("%s\n"),title);
+       dump_mem(addr, len, eeprom_read_byte, title);
+}
 
-       while (len) {
-               if (len < 16)
-                       llen = len;
+void dump_ram(const uint8_t *addr, unsigned int len, char *title)
+{
+       dump_mem(addr, len, ram_read_byte, title);
+}
 
-               printf_P(PSTR("    %.4x:"), (size_t) addr);
-               print_blanks(3 * pre);
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR(" %.2x"), addr[i]);
-               print_blanks(3 * (16 - i + 1) + pre);
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR("%c"), isprint(addr[i]) ? addr[i] : '.');
-               putchar('\n');
 
-               pre = 0;
-               addr += 16;
-               len -= llen;
-       }
-}
-#endif
 #if 0
 void dump_heap(void)
 {
@@ -109,35 +90,9 @@ void dump_heap(void)
 }
 #endif
 
-#if 0
-/* TODO: combine with dump_ram() */
-void dump_eep(const uint8_t *addr, unsigned int len, 
-                       uint8_t (*readfkt)(const uint8_t *))
-{
-       uint_fast8_t i;
-       uint8_t buf[16];
-
-       printf_P(PSTR("eeprom dump:"));
-       while (len) {
-               printf_P(PSTR("\n    0x%.4x:"), (unsigned int) addr);
-               for (i = 0; i<16; i++)
-                       buf[i] = readfkt(addr + i);
-               for (i = 0; i<16; i++)
-                       printf_P(PSTR(" %.2x"), buf[i]);
-               printf_P(PSTR("   "));
-               for (i = 0; i<16; i++)
-                       printf_P(PSTR("%c"), isprint(buf[i]) ? buf[i] : '.');
-
-               addr += 16;
-               len -= len > 16 ? 16 : len;
-       }
-       putchar('\n');
-}
-#endif
-
 
 /*
- * EEPROM Display
+ * Memory Display
  *     md addr {len}
  */
 command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -145,7 +100,7 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
 //     static const uint8_t *addr;
 //     static uint16_t length = 128;
        uint8_t (*readhow)(const uint8_t *);
-               
+
        (void) cmdtp; (void) flag;
 
        if (argc < 2)
@@ -153,7 +108,7 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
 
        const uint8_t *addr;
        uint16_t length = 128;
-       
+
        if (strchr(argv[0],'r') != NULL)
                readhow = ram_read_byte;
        else if (strchr(argv[0],'e') != NULL)
@@ -227,6 +182,8 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
 /*------------------------------------------------------------------------------*/
 
 
+#if 1
+
 struct __freelist {
        size_t sz;
        struct __freelist *nx;
@@ -244,6 +201,8 @@ printfreelist(const char * title)
        int i;
        unsigned int freesum = 0;
 
+/* TODO: printf_P */
+
        if (!__flp) {
                printf("%s no free list\n", title ? title : "");
        } else {
@@ -258,13 +217,14 @@ printfreelist(const char * title)
                        freesum += fp1->sz;
                }
        }
-       
+
        freesum +=  (size_t) STACK_POINTER() - __malloc_margin - (size_t) __brkval;
 
        printf("SP: %04x, __brkval: %04x, Total free: %04u\n",
                (size_t) STACK_POINTER(), (size_t) __brkval, freesum);
 }
 
+#endif
 
 #endif /* DEBUG */