]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/debug.c
switch fifos conin,conout
[z180-stamp.git] / avr / debug.c
index 1940eb003d240db4fe3d6936d7ec83fe1a8191cc..f3632c288018c14ca31476ae4263f5393f5e8d75 100644 (file)
@@ -1,3 +1,9 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
 #include "common.h"
 #include <stdlib.h>
 #include <string.h>
@@ -5,8 +11,10 @@
 #include <avr/eeprom.h>
 
 #include "command.h"
+#include "cli_readline.h"
 #include "print-utils.h"
 #include "debug.h"
+
 /*
  * Debugging
  */
 #ifdef DEBUG
 
 
-void eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
-{
-       eeprom_read_block((void *) buf, (const void *) (size_t) addr, count);
-}
-
-void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
-{
-               while (count--)
-                       *buf++ = *(uint8_t *) (size_t) addr++;
-}
-
-
-void dump_eep(uint32_t addr, unsigned int len, char *title)
-{
-       dump_mem(addr, len, eeprom_read_buf, title);
-}
-
-void dump_ram(uint32_t addr, unsigned int len, char *title)
-{
-       dump_mem(addr, len, ram_read_buf, title);
-}
-
-
 #if 0
 void dump_heap(void)
 {
@@ -55,7 +40,7 @@ void dump_heap(void)
  */
 command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       void (*readhow)(uint8_t *buf, uint32_t addr, uint8_t count);
+       void (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count);
 
        (void) cmdtp; (void) flag;
 
@@ -65,12 +50,19 @@ 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);
@@ -80,7 +72,7 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
                length = (uint16_t) strtoul(argv[2], NULL, 16);
 
        /* Print the lines. */
-       dump_mem(addr, length, readhow, NULL);
+       dump_mem(addr, addr, length, readwhat, NULL);
 
        return CMD_RET_SUCCESS;
 }
@@ -135,8 +127,85 @@ command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        return CMD_RET_SUCCESS;
 }
 
-/*------------------------------------------------------------------------------*/
 
+/* Modify memory.
+ *
+ * Syntax:
+ *     !mm {addr}
+ *     !nm {addr}
+ */
+
+ static uint8_t        *mm_last_addr;
+
+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;
+
+       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) strtoul(argv[1], NULL, 16);
+       }
+
+       /* Print the address, followed by value.  Then accept input for
+        * the next value.  A non-converted value exits.
+        */
+       do {
+               data = *addr;
+               printf_P(PSTR("%04x: %02x"), addr, data);
+
+               nbytes = cli_readline(PSTR(" ? "));
+               if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
+                       /* <CR> 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 = strtoul(console_buffer, &endp, 16);
+                       nbytes = endp - console_buffer;
+                       if (nbytes) {
+                               *addr = data;
+                               if (incrflag)
+                                       addr++;
+                       }
+               }
+       } while (nbytes);
+
+       mm_last_addr = addr;
+       return CMD_RET_SUCCESS;
+}
+
+
+command_ret_t do_mem_mm_avr(cmd_tbl_t *cmdtp, int 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, int flag, int argc, char * const argv[])
+{
+       return mod_mem_avr (cmdtp, 0, flag, argc, argv);
+}
+
+/*------------------------------------------------------------------------------*/
 
 #if 1