/*
+ * (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
#endif
-static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
-
/* Display values from last command.
* Memory modify remembered values are different from display memory.
*/
/*--------------------------------------------------------------------------*/
-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;
-
- zstate_t state = z80_request_bus_save();
- for (i = pre; i < llen; i++)
- buf[i] = z80_read(addr + i);
- z80_release_bus_save(state);
-
- 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
* Syntax:
* md {addr} {len}
*/
-int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+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>");
}
/* 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;
- return 0;
+ return CMD_RET_SUCCESS;
}
-int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+/* Modify memory.
+ *
+ * Syntax:
+ * mm {addr}
+ * nm {addr}
+ */
+static command_ret_t
+mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
+{
+ uint32_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 = strtoul(argv[1], NULL, 16);
+ addr += base_address;
+ }
+
+ /* Print the address, followed by value. Then accept input for
+ * the next value. A non-converted value exits.
+ */
+ do {
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ my_puts_P(PSTR("Bus timeout\n"));
+ return CMD_RET_FAILURE;
+ }
+ data = z80_read(addr);
+ z80_bus_cmd(Release);
+ printf_P(PSTR("%05lx: %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) {
+ 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)
+ addr++;
+ }
+ }
+ } while (nbytes);
+
+ mm_last_addr = addr;
+ return CMD_RET_SUCCESS;
+}
+
+
+command_ret_t do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
return mod_mem (cmdtp, 1, flag, argc, argv);
}
-int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
return mod_mem (cmdtp, 0, flag, argc, argv);
}
-int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
uint8_t writeval;
uint32_t addr, count;
count = 1;
}
- zstate_t state = z80_request_bus_save();
- 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_release_bus_save(state);
+ z80_memset(addr, writeval, count);
+ z80_bus_cmd(Release);
- return 0;
+ return CMD_RET_SUCCESS;
}
#ifdef CONFIG_MX_CYCLIC
-int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int i;
uint32_t count;
/* check for ctrl-c to abort... */
if (ctrlc()) {
- my_puts("Abort\n");
- return 0;
+ my_puts_P(PSTR("Abort\n"));
+ return CMD_RET_SUCCESS;
}
}
- return 0;
+ return CMD_RET_SUCCESS;
}
-int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int i;
uint32_t count;
/* check for ctrl-c to abort... */
if (ctrlc()) {
- my_puts("Abort\n");
- return 0;
+ my_puts_P(PSTR("Abort\n"));
+ return CMD_RET_SUCCESS;
}
}
- return 0;
+ return CMD_RET_SUCCESS;
}
#endif /* CONFIG_MX_CYCLIC */
-int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
uint32_t addr1, addr2, count, ngood;
- int rcode = 0;
+ command_ret_t rcode = CMD_RET_SUCCESS;
uint8_t byte1, byte2;
(void) cmdtp;
count = strtoul(argv[3], NULL, 16);
for (ngood = 0; ngood < count; ++ngood) {
- zstate_t state = z80_request_bus_save();
+ 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_release_bus_save(state);
+ 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 = 1;
+ rcode = CMD_RET_FAILURE;
break;
}
addr1++;
/* check for ctrl-c to abort... */
if (ctrlc()) {
- my_puts("Abort\n");
- return 0;
+ 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;
}
-int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
uint32_t src, dest, count;
int_fast8_t step;
count = strtoul(argv[3], NULL, 16);
if (count == 0) {
- my_puts ("Zero length ???\n");
- return 1;
+ my_puts_P(PSTR("Zero length?\n"));
+ return CMD_RET_FAILURE;
}
-
+
if (dest > src) {
src += count - 1;
dest += count - 1;
while (count-- > 0) {
uint8_t data;
- zstate_t state = z80_request_bus_save();
+ 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_release_bus_save(state);
+ z80_bus_cmd(Release);
src += step;
dest += step;
/* check for ctrl-c to abort... */
if (ctrlc()) {
- my_puts("Abort\n");
- return 0;
+ my_puts_P(PSTR("Abort\n"));
+ return CMD_RET_SUCCESS;
}
}
- return 0;
+ return CMD_RET_SUCCESS;
}
-int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
+command_ret_t do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
(void) cmdtp;
base_address = strtoul(argv[1], NULL, 16);
}
/* Print the current base address. */
- printf("Base Address: 0x%05lx\n", base_address);
- return 0;
+ printf_P(PSTR("Base Address: 0x%05lx\n"), base_address);
+ return CMD_RET_SUCCESS;
}
-int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
+command_ret_t do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
uint32_t addr, length;
* If we have only one object, just run infinite loops.
*/
if (length == 1) {
- zstate_t state = z80_request_bus_save();
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
+ my_puts_P(PSTR("Bus timeout\n"));
+ return CMD_RET_FAILURE;
+ }
for (;;)
z80_read(addr);
- z80_release_bus_save(state);
+ z80_bus_cmd(Release);
}
- zstate_t state = z80_request_bus_save();
+ 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;
while (i-- > 0)
z80_read(p++);
}
- z80_release_bus_save(state);
+ z80_bus_cmd(Release);
- return 0;
+ return CMD_RET_SUCCESS;
}
#ifdef CONFIG_LOOPW
-int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
uint32_t addr, length;
uint8_t data;
* If we have only one object, just run infinite loops.
*/
if (length == 1) {
- zstate_t state = z80_request_bus_save();
+ 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;
*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())
*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())
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++;
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++;
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++;
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++;
}
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++) {
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++;
* configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
* interrupted by ctrl-c or by a failure of one of the sub-tests.
*/
-int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
+command_ret_t do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
uint32_t start, end;
vu_long *buf, *dummy;
int iteration_limit;
+/* TODO: command_ret_t */
int ret;
uint32_t errs = 0; /* number of errors, or -1 if interrupted */
uint32_t pattern;
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);
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);
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;
}
return ret; /* not reached */
}
#endif /* CONFIG_CMD_MEMTEST */
-
-/* Modify memory.
- *
- * Syntax:
- * mm {addr}
- * nm {addr}
- */
-static int
-mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
-{
- uint32_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 = strtoul(argv[1], NULL, 16);
- addr += base_address;
- }
-
- /* Print the address, followed by value. Then accept input for
- * the next value. A non-converted value exits.
- */
- do {
- zstate_t state = z80_request_bus_save();
- data = z80_read(addr);
- printf("%05lx: %02x", addr, data);
- z80_release_bus_save(state);
-
- 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) {
- zstate_t state = z80_request_bus_save();
- z80_write(addr, data);
- z80_release_bus_save(state);
- if (incrflag)
- addr++;
- }
- }
- } while (nbytes);
-
- mm_last_addr = addr;
- return 0;
-}
-