X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/35edb766593d019b89a3f40b6d6cdd2b50f18032..fcf1d5b30bd3b341fb7596aef395f347c6dc97b4:/avr/debug.c diff --git a/avr/debug.c b/avr/debug.c index 5096d59..21dd242 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -1,18 +1,20 @@ /* - * (C) Copyright 2014 Leo C. + * (C) Copyright 2014,2016 Leo C. * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ +#include "debug.h" #include "common.h" -#include +#include /* __malloc_margin */ #include #include #include #include "command.h" +#include "cli_readline.h" +#include "eval_arg.h" #include "print-utils.h" -#include "debug.h" /* * Debugging @@ -37,9 +39,9 @@ void dump_heap(void) * Memory Display * md addr {len} */ -command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) { - void (*readhow)(uint8_t *buf, uint32_t addr, uint8_t count); + int (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count); (void) cmdtp; (void) flag; @@ -49,27 +51,34 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg uint32_t addr; uint32_t length = 128; - if (strchr(argv[0],'r') != NULL) - readhow = ram_read_buf; - else if (strchr(argv[0],'e') != NULL) - readhow = eeprom_read_buf; - else + switch (argv[0][3]) { + case 'r': + readwhat = ram_read_buf; + break; + case 'e': + readwhat = eeprom_read_buf; + break; + case 'f': + readwhat = flash_read_buf; + break; + default: return CMD_RET_USAGE; + } /* 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, readhow, NULL); + dump_mem(addr, addr, length, readwhat, NULL); return CMD_RET_SUCCESS; } -command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) { uint16_t src, dest, count; int_fast8_t step; @@ -80,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); @@ -120,20 +129,83 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ } -/*------------------------------------------------------------------------------*/ +/* Modify memory. + * + * Syntax: + * !mm {addr} + * !nm {addr} + */ + + static uint8_t *mm_last_addr; -command_ret_t do_testarg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static command_ret_t +mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, uint_fast8_t flag, int argc, char * const argv[]) { - my_puts_P(cmdtp->name); - printf_P(PSTR("\n%s\n"), argv[0]); + uint8_t *addr; + int nbytes; + + (void) cmdtp; + + if (argc != 2) + return CMD_RET_USAGE; + + /* We use the last specified parameters, unless new ones are + * entered. + */ + addr = mm_last_addr; + + if ((flag & CMD_FLAG_REPEAT) == 0) { + /* New command specified. + */ + + /* Address is specified since argc > 1 + */ + 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 { + uint8_t data = *addr; + printf_P(PSTR("%04x: %02x"), addr, data); + + nbytes = cli_readline(PSTR(" ? "), 0); + if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { + /* pressed as only input, don't modify current + * location and move to next. "-" pressed will go back. + */ + if (incrflag) + addr += nbytes ? -1 : 1; + nbytes = 1; + + } else { + char *endp; + data = eval_arg(console_buffer, &endp); + nbytes = endp - console_buffer; + if (nbytes) { + *addr = data; + if (incrflag) + addr++; + } + } + } while (nbytes > 0); + mm_last_addr = addr; return CMD_RET_SUCCESS; } -/*------------------------------------------------------------------------------*/ +command_ret_t do_mem_mm_avr(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) +{ + return mod_mem_avr (cmdtp, 1, flag, argc, argv); +} +command_ret_t do_mem_nm_avr(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) +{ + return mod_mem_avr (cmdtp, 0, flag, argc, argv); +} -#if 1 +/*------------------------------------------------------------------------------*/ struct __freelist { size_t sz; @@ -175,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 UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED) +{ + printfreelist(NULL); + + return CMD_RET_SUCCESS; +} #endif /* DEBUG */