]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_mem.c
Support for Peter Danneggers fboot.
[z180-stamp.git] / avr / cmd_mem.c
index 6341e0b77682c5057fb27c964436654c176b3e24..20a4412a0b2e770e8b8cc232c628057771b73bff 100644 (file)
@@ -1,4 +1,6 @@
 /*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
  * (C) Copyright 2000
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
 #include <stdlib.h>
 #include <ctype.h>
 
-#include "config.h"
-#include "debug.h"
 #include "command.h"
 #include "cli_readline.h"
+#include "print-utils.h"
 #include "con-utils.h"
 #include "z80-if.h"
+//#include "debug.h"
 
-/* 
- * TODO: printf() --> printf_P() 
- */
 
 #ifndef CONFIG_SYS_MEMTEST_SCRATCH
 #define CONFIG_SYS_MEMTEST_SCRATCH 0
@@ -41,72 +40,15 @@ static      uint32_t        base_address = 0;
 
 /*--------------------------------------------------------------------------*/
 
-static void print_blanks(uint_fast8_t count)
-{
-       while(count--)
-               putchar(' ');
-}
 
-int z180_dump_mem(uint32_t startaddr, uint32_t len, const char *title)
+void z180_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
-       uint8_t buf[16];
-       uint8_t llen = 16;
-       uint8_t pre = startaddr % 16;
-       uint32_t addr = startaddr & ~0x0f;
-       len += pre;
-       uint8_t i;
-       
-       if (title && *title)
-               printf_P(PSTR("%s\n"),title);
-               
-       while (len) {
-               if (len < 16)
-                       llen = len;
-
-               z80_bus_cmd(Request);
-               for (i = pre; i < llen; i++)
-                       buf[i] = z80_read(addr + i);
-               z80_bus_cmd(Release);
-
-               printf_P(PSTR("%.5lx:"), addr);
-#if 0
-               print_blanks(3 * pre);
-
-               /* Print hex values */
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR(" %.2x"), buf[i]);
-#else
-               for (i = 0; i < llen; i++) {
-                       if ((i % 8) == 0)
-                               putchar(' ');
-                       if (i < pre)
-                               printf_P(PSTR(".. "));
-                       else
-                               printf_P(PSTR("%.2x "), buf[i]);
+               if (z80_bus_cmd(Request) & ZST_ACQUIRED) {
+                       z80_read_block (buf, addr, count);
+                       z80_bus_cmd(Release);
                }
-#endif
-               /* fill line with whitespace for nice ASCII print */
-#if 1
-               print_blanks(3 * (16u - i) + (16u-i)/8 + 1 + pre);
-#else
-
-#endif
-               /* Print data in ASCII characters */
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR("%c"), isprint(buf[i]) ? buf[i] : '.');
-               putchar('\n');
-
-               pre = 0;
-               addr += 16;
-               len -= llen;
-
-               if (ctrlc())
-                       return -1;
-       }
-       return 0;
 }
 
-
 /*--------------------------------------------------------------------------*/
 
 /* Memory Display
@@ -117,10 +59,10 @@ int z180_dump_mem(uint32_t startaddr, uint32_t len, const char *title)
 command_ret_t do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        uint32_t addr, length;
-       
+
        (void) cmdtp;
 
-#if 0  
+#if 0
        printf_P(PSTR("flag: %d, argc: %d"), flag, argc);
        for (int i = 0; i < argc; i++) {
                printf_P(PSTR(", argv[%d]: %s"), i, argv[i] ? argv[i] : "<NULL>");
@@ -148,7 +90,7 @@ command_ret_t do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        }
 
        /* Print the lines. */
-       z180_dump_mem(addr, length, NULL);
+       dump_mem(addr, addr, length, z180_read_buf, NULL);
 
        dp_last_addr = addr + length;
        dp_last_length = length;
@@ -192,10 +134,13 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
         * the next value.  A non-converted value exits.
         */
        do {
-               z80_bus_cmd(Request);
+               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+                       my_puts_P(PSTR("Bus timeout\n"));
+                       return  CMD_RET_FAILURE;
+               }
                data = z80_read(addr);
-               printf("%05lx: %02x", addr, data);
                z80_bus_cmd(Release);
+               printf_P(PSTR("%05lx: %02x"), addr, data);
 
                nbytes = cli_readline(PSTR(" ? "));
                if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
@@ -211,7 +156,10 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
                        data = strtoul(console_buffer, &endp, 16);
                        nbytes = endp - console_buffer;
                        if (nbytes) {
-                               z80_bus_cmd(Request);
+                               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+                                       my_puts_P(PSTR("Bus timeout\n"));
+                                       return  CMD_RET_FAILURE;
+                               }
                                z80_write(addr, data);
                                z80_bus_cmd(Release);
                                if (incrflag)
@@ -261,11 +209,11 @@ command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
                count = 1;
        }
 
-       z80_bus_cmd(Request);
-       while (count-- > 0) {
-               z80_write(addr, writeval);
-               ++addr; 
+       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+               my_puts_P(PSTR("Bus timeout\n"));
+               return  CMD_RET_FAILURE;
        }
+       z80_memset(addr, writeval, count);
        z80_bus_cmd(Release);
 
        return CMD_RET_SUCCESS;
@@ -292,7 +240,7 @@ command_ret_t do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const ar
 
                /* check for ctrl-c to abort... */
                if (ctrlc()) {
-                       my_puts("Abort\n");
+                       my_puts_P(PSTR("Abort\n"));
                        return CMD_RET_SUCCESS;
                }
        }
@@ -320,7 +268,7 @@ command_ret_t do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const ar
 
                /* check for ctrl-c to abort... */
                if (ctrlc()) {
-                       my_puts("Abort\n");
+                       my_puts_P(PSTR("Abort\n"));
                        return CMD_RET_SUCCESS;
                }
        }
@@ -349,13 +297,17 @@ command_ret_t do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
        count = strtoul(argv[3], NULL, 16);
 
        for (ngood = 0; ngood < count; ++ngood) {
-               z80_bus_cmd(Request);
+               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+                       my_puts_P(PSTR("Bus timeout\n"));
+                       rcode =  CMD_RET_FAILURE;
+                       break;
+               }
                byte1 = z80_read(addr1);
                byte2 = z80_read(addr2);
                z80_bus_cmd(Release);
                if (byte1 != byte2) {
-                       printf"byte at 0x%05lx (%#02x) != "
-                               "byte at 0x%05lx (%#02x)\n",
+                       printf_P(PSTR("byte at 0x%05lx (%#02x) != "
+                               "byte at 0x%05lx (%#02x)\n"),
                                addr1, byte1, addr2, byte2);
                        rcode = CMD_RET_FAILURE;
                        break;
@@ -365,12 +317,12 @@ command_ret_t do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
 
                /* check for ctrl-c to abort... */
                if (ctrlc()) {
-                       my_puts("Abort\n");
+                       my_puts_P(PSTR("Abort\n"));
                        return CMD_RET_SUCCESS;
                }
        }
 
-       printf("Total of %ld byte(s) (0x%lx) were the same\n", ngood, ngood);
+       printf_P(PSTR("Total of %ld byte(s) (0x%lx) were the same\n"), ngood, ngood);
        return rcode;
 }
 
@@ -392,10 +344,10 @@ command_ret_t do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        count = strtoul(argv[3], NULL, 16);
 
        if (count == 0) {
-               my_puts ("Zero length ???\n");
+               my_puts_P(PSTR("Zero length?\n"));
                return CMD_RET_FAILURE;
        }
-       
+
        if (dest > src) {
                src += count - 1;
                dest += count - 1;
@@ -405,7 +357,10 @@ command_ret_t do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
 
        while (count-- > 0) {
                uint8_t data;
-               z80_bus_cmd(Request);
+               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+                       my_puts_P(PSTR("Bus timeout\n"));
+                       return  CMD_RET_FAILURE;
+               }
                data = z80_read(src);
                z80_write(dest, data);
                z80_bus_cmd(Release);
@@ -414,7 +369,7 @@ command_ret_t do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
 
                /* check for ctrl-c to abort... */
                if (ctrlc()) {
-                       my_puts("Abort\n");
+                       my_puts_P(PSTR("Abort\n"));
                        return CMD_RET_SUCCESS;
                }
        }
@@ -432,7 +387,7 @@ command_ret_t do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
                base_address = strtoul(argv[1], NULL, 16);
        }
        /* Print the current base address. */
-       printf("Base Address: 0x%05lx\n", base_address);
+       printf_P(PSTR("Base Address: 0x%05lx\n"), base_address);
        return CMD_RET_SUCCESS;
 }
 
@@ -458,13 +413,19 @@ command_ret_t do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
         * If we have only one object, just run infinite loops.
         */
        if (length == 1) {
-               z80_bus_cmd(Request);
+               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+                       my_puts_P(PSTR("Bus timeout\n"));
+                       return  CMD_RET_FAILURE;
+               }
                for (;;)
                        z80_read(addr);
                z80_bus_cmd(Release);
        }
 
-       z80_bus_cmd(Request);
+       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+               my_puts_P(PSTR("Bus timeout\n"));
+               return  CMD_RET_FAILURE;
+       }
        for (;;) {
                uint32_t i = length;
                uint32_t p = addr;
@@ -500,11 +461,18 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const a
         * If we have only one object, just run infinite loops.
         */
        if (length == 1) {
-               z80_bus_cmd(Request);
+               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+                       my_puts_P(PSTR("Bus timeout\n"));
+                       return  CMD_RET_FAILURE;
+               }
                for (;;)
                        z80_write(addr, data);
        }
 
+       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+               my_puts_P(PSTR("Bus timeout\n"));
+               return  CMD_RET_FAILURE;
+       }
        for (;;) {
                uint32_t i = length;
                uint32_t p = addr;
@@ -566,8 +534,8 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
                        *dummy  = ~val; /* clear the test data off the bus */
                        readback = *addr;
                        if (readback != val) {
-                               printf("FAILURE (data line): "
-                                       "expected %05lx, actual %05lx\n",
+                               printf_P(PSTR("FAILURE (data line): "
+                                       "expected %05lx, actual %05lx\n"),
                                                val, readback);
                                errs++;
                                if (ctrlc())
@@ -577,8 +545,8 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
                        *dummy  = val;
                        readback = *addr;
                        if (readback != ~val) {
-                               printf("FAILURE (data line): "
-                                       "Is %05lx, should be %05lx\n",
+                               printf_P(PSTR("FAILURE (data line): "
+                                       "Is %05lx, should be %05lx\n"),
                                                readback, ~val);
                                errs++;
                                if (ctrlc())
@@ -641,8 +609,8 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
        for (offset = 1; offset < num_words; offset <<= 1) {
                temp = addr[offset];
                if (temp != pattern) {
-                       printf("\nFAILURE: Address bit stuck high @ 0x%.5lx:"
-                               " expected 0x%.5lx, actual 0x%.5lx\n",
+                       printf_P(PSTR("\nFAILURE: Address bit stuck high @ 0x%.5lx:"
+                               " expected 0x%.5lx, actual 0x%.5lx\n"),
                                start_addr + offset*sizeof(vu_long),
                                pattern, temp);
                        errs++;
@@ -661,9 +629,9 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
                for (offset = 1; offset < num_words; offset <<= 1) {
                        temp = addr[offset];
                        if ((temp != pattern) && (offset != test_offset)) {
-                               printf("\nFAILURE: Address bit stuck low or"
+                               printf_P(PSTR("\nFAILURE: Address bit stuck low or"
                                        " shorted @ 0x%.5lx: expected 0x%.5lx,"
-                                       " actual 0x%.5lx\n",
+                                       " actual 0x%.5lx\n"),
                                        start_addr + offset*sizeof(vu_long),
                                        pattern, temp);
                                errs++;
@@ -701,8 +669,8 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
        for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
                temp = addr[offset];
                if (temp != pattern) {
-                       printf("\nFAILURE (read/write) @ 0x%.5lx:"
-                               " expected 0x%.5lx, actual 0x%.5lx)\n",
+                       printf_P(PSTR("\nFAILURE (read/write) @ 0x%.5lx:"
+                               " expected 0x%.5lx, actual 0x%.5lx)\n"),
                                start_addr + offset*sizeof(vu_long),
                                pattern, temp);
                        errs++;
@@ -722,8 +690,8 @@ static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_add
                anti_pattern = ~pattern;
                temp = addr[offset];
                if (temp != anti_pattern) {
-                       printf("\nFAILURE (read/write): @ 0x%.5lx:"
-                               " expected 0x%.5lx, actual 0x%.5lx)\n",
+                       printf_P(PSTR("\nFAILURE (read/write): @ 0x%.5lx:"
+                               " expected 0x%.5lx, actual 0x%.5lx)\n"),
                                start_addr + offset*sizeof(vu_long),
                                anti_pattern, temp);
                        errs++;
@@ -762,9 +730,9 @@ static uint32_t mem_test_quick(vu_long *buf, uint32_t start_addr, uint32_t end_a
        }
        length = (end_addr - start_addr) / sizeof(uint32_t);
        end = buf + length;
-       printf("\rPattern %08lX  Writing..."
+       printf_P(PSTR("\rPattern %08lX  Writing..."
                "%12s"
-               "\b\b\b\b\b\b\b\b\b\b",
+               "\b\b\b\b\b\b\b\b\b\b"),
                pattern, "");
 
        for (addr = buf, val = pattern; addr < end; addr++) {
@@ -772,15 +740,15 @@ static uint32_t mem_test_quick(vu_long *buf, uint32_t start_addr, uint32_t end_a
                val += incr;
        }
 
-       my_puts("Reading...");
+       my_puts_P(PSTR("Reading..."));
 
        for (addr = buf, val = pattern; addr < end; addr++) {
                readback = *addr;
                if (readback != val) {
                        uint32_t offset = addr - buf;
 
-                       printf("\nMem error @ 0x%08X: "
-                               "found %08lX, expected %08lX\n",
+                       printf_P(PSTR("\nMem error @ 0x%08X: "
+                               "found %08lX, expected %08lX\n"),
                                (unsigned int)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
                                readback, val);
                        errs++;
@@ -835,7 +803,7 @@ command_ret_t do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
        else
                iteration_limit = 0;
 
-       printf("Testing %08x ... %08x:\n", (unsigned int)start, (unsigned int)end);
+       printf_P(PSTR("Testing %08x ... %08x:\n"), (unsigned int)start, (unsigned int)end);
        debug("%s:%d: start %#05lx end %#05lx\n", __func__, __LINE__,
              start, end);
 
@@ -850,7 +818,7 @@ command_ret_t do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
                        break;
                }
 
-               printf("Iteration: %6d\r", iteration + 1);
+               printf_P(PSTR("Iteration: %6d\r"), iteration + 1);
                debug("\n");
                if (alt_test) {
                        errs = mem_test_alt(buf, start, end, dummy);
@@ -867,7 +835,7 @@ command_ret_t do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
                putc('\n');
                ret = 1;
        } else {
-               printf("Tested %d iteration(s) with %lu errors.\n",
+               printf_P(PSTR("Tested %d iteration(s) with %lu errors.\n"),
                        iteration, errs);
                ret = errs != 0;
        }
@@ -875,4 +843,3 @@ command_ret_t do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
        return ret;     /* not reached */
 }
 #endif /* CONFIG_CMD_MEMTEST */
-