]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
mcd_mem.c: use cmd_error(), z80_bus_request_or_exit()
authorLeo C <erbl259-lmu@yahoo.de>
Wed, 5 Sep 2018 10:20:59 +0000 (12:20 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Wed, 5 Sep 2018 10:20:59 +0000 (12:20 +0200)
avr/cmd_mem.c
avr/debug.c
avr/print-utils.c
avr/strerror.c
avr/z80-if.c
include/errnum.h
include/print-utils.h
include/z80-if.h

index 763b857b860bf20de2ca586f833f58f716d1766f..7a8781cc7b7432d036bfc9c11cf2db5940eb686e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014,2018 Leo C. <erbl259-lmu@yahoo.de>
  *
  * (C) Copyright 2000
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
@@ -43,14 +43,14 @@ static      uint32_t        base_address = 0;
 
 /*--------------------------------------------------------------------------*/
 
-int z180_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+static ERRNUM z180_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
        if (!(z80_bus_cmd(Request) & ZST_ACQUIRED))
-               return -1;
+               return EBUSTO;
 
        z80_read_block (buf, addr, count);
        z80_bus_cmd(Release);
-       return 0;
+       return ESUCCESS;
 }
 
 /*--------------------------------------------------------------------------*/
@@ -94,13 +94,11 @@ command_ret_t do_mem_md(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * co
        }
 
        /* Print the lines. */
-       int ret = dump_mem(addr, addr, length, z180_read_buf, NULL);
-       if (ret == -2)  { /* TODO: Error codes */
-               my_puts_P(PSTR("Bus timeout\n"));
-               return  CMD_RET_FAILURE;
-       }
+       ERRNUM ret = dump_mem(addr, addr, length, z180_read_buf, NULL);
+       if (ret == EBUSTO)
+               cmd_error(CMD_RET_FAILURE, ret, NULL);
 
-       if (ret >= 0) {
+       if (ret == ESUCCESS) {
                dp_last_addr = addr + length;
                dp_last_length = length;
        }
@@ -144,10 +142,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, uint_fast8_t flag, int argc, char * cons
         * 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;
-               }
+               z80_bus_request_or_exit();
                data = z80_read(addr);
                z80_bus_cmd(Release);
                printf_P(PSTR("%05lx: %02x"), addr, data);
@@ -166,10 +161,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, uint_fast8_t flag, int argc, char * cons
                        data = eval_arg(console_buffer, &endp);
                        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_bus_request_or_exit();
                                z80_write(addr, data);
                                z80_bus_cmd(Release);
                                if (incrflag)
@@ -235,11 +227,7 @@ command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * co
        if (argc == 3)
                count = eval_arg(argv[optind], NULL);
 
-       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-               my_puts_P(PSTR("Bus timeout\n"));
-               return  CMD_RET_FAILURE;
-       }
-
+       z80_bus_request_or_exit();
        if (width == 1)
                z80_memset(addr, writeval, count);
        else {
@@ -380,10 +368,7 @@ command_ret_t do_mem_cp(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * co
 
        while (count-- > 0) {
                uint8_t data;
-               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-                       my_puts_P(PSTR("Bus timeout\n"));
-                       return  CMD_RET_FAILURE;
-               }
+               z80_bus_request_or_exit();
                data = z80_read(src);
                z80_write(dest, data);
                z80_bus_cmd(Release);
@@ -436,19 +421,13 @@ command_ret_t do_mem_loop(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc,
         * If we have only one object, just run infinite loops.
         */
        if (length == 1) {
-               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-                       my_puts_P(PSTR("Bus timeout\n"));
-                       return  CMD_RET_FAILURE;
-               }
+               z80_bus_request_or_exit();
                cli();
                for (;;)
                        z80_read(addr);
        }
 
-       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-               my_puts_P(PSTR("Bus timeout\n"));
-               return  CMD_RET_FAILURE;
-       }
+       z80_bus_request_or_exit();
        cli();
        for (;;) {
                uint32_t i = length;
@@ -484,19 +463,13 @@ command_ret_t do_mem_loopw (cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char
         * If we have only one object, just run infinite loops.
         */
        if (length == 1) {
-               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-                       my_puts_P(PSTR("Bus timeout\n"));
-                       return  CMD_RET_FAILURE;
-               }
+               z80_bus_request_or_exit();
                cli();
                for (;;)
                        z80_write(addr, data);
        }
 
-       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-               my_puts_P(PSTR("Bus timeout\n"));
-               return  CMD_RET_FAILURE;
-       }
+       z80_bus_request_or_exit();
        cli();
        for (;;) {
                uint32_t i = length;
@@ -770,10 +743,7 @@ command_ret_t do_mem_mtest(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc,
                printf_P(PSTR("Iteration: %6d\r"), iteration + 1);
 //             debug("\n");
 
-               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-                       my_puts_P(PSTR("Bus timeout\n"));
-                       return  CMD_RET_FAILURE;
-               }
+               z80_bus_request_or_exit();
                errs += mem_test_alt(start, end);
                z80_bus_cmd(Release);
 
index ea4aa21a9f0dce93b8eb7db501c20e02c54cc811..89ef4b131a0757e5dedf45f6773abe733c581bcd 100644 (file)
  * Memory Display
  *     md addr {len}
  */
-command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
+command_ret_t do_dump_mem(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
 {
-       int (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count);
-
-       (void) cmdtp; (void) flag;
+       ERRNUM (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count);
 
        if (argc < 2)
                return CMD_RET_USAGE;
index b8100a0411b870bb2d2280acc479f25d60012dc9..69f45536924241e82717e25c2f95df079e351725 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014,2018 Leo C. <erbl259-lmu@yahoo.de>
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 #include "common.h"
@@ -18,28 +18,28 @@ void print_blanks(uint_fast8_t count)
 }
 
 
-int eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+ERRNUM eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
        eeprom_read_block((void *) buf, (const void *) (size_t) addr, count);
-       return 0;
+       return ESUCCESS;
 }
 
-int ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+ERRNUM ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
        while (count--)
                *buf++ = *(uint8_t *) (size_t) addr++;
-       return 0;
+       return ESUCCESS;
 }
 
-int flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+ERRNUM flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
        while (count--)
                *buf++ = *(const __memx uint8_t *) (__uint24) addr++;
-       return 0;
+       return ESUCCESS;
 }
 
-int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
-               int (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
+ERRNUM dump_mem(uint32_t address, uint32_t offset, uint32_t len,
+               ERRNUM (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
 {
        uint8_t buf[16];
        uint8_t llen = 16;
@@ -56,7 +56,7 @@ int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
                if (len < 16)
                        llen = len;
                if (readfkt(buf, address, llen - pre) != 0)
-                       return -2; /* TODO: Error codes */
+                       return -EBUSTO;
 
                if (title)
                        print_blanks(4);
@@ -82,9 +82,9 @@ int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
                len -= llen;
 
                if (ctrlc())
-                       return -1;
+                       return EINTR;
        }
-       return 0;
+       return ESUCCESS;
 }
 
 void dump_eep(uint32_t addr, unsigned int len, char *title)
index 4fdc63de6783942557f06602194dd128fed03370..a4d2a67340c76c35dc022ba14d3a6452413635fc 100644 (file)
@@ -11,6 +11,7 @@
 static const FLASH char * const FLASH error_strings[] = {
        FSTR("Unknown error"),
        FSTR("Not enough memory"),
+       FSTR("Interrupt"),
        FSTR("Bus timeout"),
        FSTR("Unexpected argument"),
        FSTR("Invalid disk number"),
index e36b3696a5b9a43e3a6e057f637142f803ba975c..618384950874db2abd9ae8e70ac33ee7dbcfac84 100644 (file)
 #define MASK(n)        ((1<<(n))-1)
 #define SMASK(w,s) (MASK(w) << (s))
 
+void z80_bus_request_or_exit(void)
+{
+       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED))
+               cmd_error(CMD_RET_FAILURE, EBUSTO, NULL);
+}
 
 static zstate_t zstate;
 static volatile uint8_t timer;         /* used for bus timeout */
index adb8a8040cb010ea3bc7442afac327889db41883..628c4323af2a8f9b3dd997ec5e794b6aeca5d66e 100644 (file)
 typedef enum {
        ESUCCESS        = 0,
        ENOMEM          = 101,
+       EINTR,
        EBUSTO,
        EUNEXPARG,
-    EATRANGE,
-    EATALRDY,
-    EATNOT,
-    EATOPEN,
-    EATOTHER,
-    ERUNNING,
-    EINVAL,
-    EEOF,
+       EATRANGE,
+       EATALRDY,
+       EATNOT,
+       EATOPEN,
+       EATOTHER,
+       ERUNNING,
+       EINVAL,
+       EEOF,
 
 } ERRNUM;
 
index ffff039944b6c294557cb82f27ed67f8b6385bbe..38de11165cb5d69c12f0b41ce1549c2cd58bd52b 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014, 2018 Leo C. <erbl259-lmu@yahoo.de>
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 #ifndef PRINT_UTILS_H
 #include <avr/eeprom.h>
 
 void print_blanks(uint_fast8_t count);
-int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
-               int (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title);
+ERRNUM dump_mem(uint32_t address, uint32_t offset, uint32_t len,
+               ERRNUM (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title);
 
 void dump_eep(uint32_t addr, unsigned int len, char *title);
 void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title);
 
-int eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
-int ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
-int flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
+ERRNUM eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
+ERRNUM ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
+ERRNUM flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
 
 #endif /* PRINT_UTILS_H */
index ef87e5ae0435194f0264f0ab86b539925b4387b3..d5a5f568476b4e4484de380ab4ca1fa01f45a9fd 100644 (file)
@@ -26,6 +26,9 @@ typedef enum {
 
 typedef enum {LOW, HIGH} level_t;
 
+
+void z80_bus_request_or_exit(void);
+
 zstate_t z80_bus_state(void);
 zstate_t z80_bus_cmd(bus_cmd_t cmd);
 void z80_setup_bus(void);