]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/debug.c
Set __malloc_margin, Print free heap command
[z180-stamp.git] / avr / debug.c
index e38ccb2f27d86d063d2efdfa5e6de7bf30d299b5..46e2ef668a0970ffe90882c9eb40e647826d125b 100644 (file)
@@ -1,18 +1,19 @@
 /*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014,2016 Leo C. <erbl259-lmu@yahoo.de>
  *
  * SPDX-License-Identifier:    GPL-2.0
  */
 
 #include "debug.h"
 #include "common.h"
-#include <stdlib.h>
+#include <stdlib.h>                    /* __malloc_margin */
 #include <string.h>
 #include <ctype.h>
 #include <avr/eeprom.h>
 
 #include "command.h"
 #include "cli_readline.h"
+#include "eval_arg.h"
 #include "print-utils.h"
 
 /*
@@ -65,11 +66,11 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
        }
 
        /* Address is specified since argc > 1 */
-       addr =  strtoul(argv[1], NULL, 16);
+       addr =  eval_arg(argv[1], NULL);
 
        /* If another parameter, it is the length to display. */
        if (argc > 2)
-               length = (uint16_t) strtoul(argv[2], NULL, 16);
+               length = (uint16_t) eval_arg(argv[2], NULL);
 
        /* Print the lines. */
        dump_mem(addr, addr, length, readwhat, NULL);
@@ -88,9 +89,9 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        if (argc != 4)
                return CMD_RET_USAGE;
 
-       src = (size_t) strtoul(argv[1], NULL, 16);
-       dest = (size_t) strtoul(argv[2], NULL, 16);
-       count = (size_t) strtoul(argv[3], NULL, 16);
+       src   = (size_t) eval_arg(argv[1], NULL);
+       dest  = (size_t) eval_arg(argv[2], NULL);
+       count = (size_t) eval_arg(argv[3], NULL);
 
        if (src > E2END) {
                debug("src > EEPROM size: 0x%04x\n", src);
@@ -141,7 +142,6 @@ static command_ret_t
 mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
 {
        uint8_t *addr;
-       uint8_t data;
        int nbytes;
 
        (void) cmdtp;
@@ -160,14 +160,14 @@ mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg
 
                /* Address is specified since argc > 1
                */
-               addr = (uint8_t *) (size_t) strtoul(argv[1], NULL, 16);
+               addr = (uint8_t *) (size_t) eval_arg(argv[1], NULL);
        }
 
        /* Print the address, followed by value.  Then accept input for
         * the next value.  A non-converted value exits.
         */
        do {
-               data = *addr;
+               uint8_t data = *addr;
                printf_P(PSTR("%04x: %02x"), addr, data);
 
                nbytes = cli_readline(PSTR(" ? "), 0);
@@ -181,7 +181,7 @@ mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg
 
                } else {
                        char *endp;
-                       data = strtoul(console_buffer, &endp, 16);
+                       data = eval_arg(console_buffer, &endp);
                        nbytes = endp - console_buffer;
                        if (nbytes) {
                                *addr = data;
@@ -207,8 +207,6 @@ command_ret_t do_mem_nm_avr(cmd_tbl_t *cmdtp, int flag, int argc, char * const a
 
 /*------------------------------------------------------------------------------*/
 
-#if 1
-
 struct __freelist {
        size_t sz;
        struct __freelist *nx;
@@ -249,6 +247,11 @@ printfreelist(const char * title)
                (size_t) STACK_POINTER(), (size_t) __brkval, freesum);
 }
 
-#endif
+command_ret_t do_pr_free_avr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       printfreelist(NULL);
+
+       return CMD_RET_SUCCESS;
+}
 
 #endif /* DEBUG */