summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2018-09-05 12:20:59 +0200
committerLeo C2018-09-05 12:20:59 +0200
commitb35fcb2f65a9c2dd17faae5b513eecca8032461b (patch)
tree09ef88059fb6eba7785a79e23b60194bddaf1952
parent1633073f77aa4f9c90a8f1d7f317e4c4d7187921 (diff)
downloadz180-stamp-b35fcb2f65a9c2dd17faae5b513eecca8032461b.zip
mcd_mem.c: use cmd_error(), z80_bus_request_or_exit()
-rw-r--r--avr/cmd_mem.c64
-rw-r--r--avr/debug.c6
-rw-r--r--avr/print-utils.c26
-rw-r--r--avr/strerror.c1
-rw-r--r--avr/z80-if.c5
-rw-r--r--include/errnum.h17
-rw-r--r--include/print-utils.h14
-rw-r--r--include/z80-if.h3
8 files changed, 57 insertions, 79 deletions
diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c
index 763b857..7a8781c 100644
--- a/avr/cmd_mem.c
+++ b/avr/cmd_mem.c
@@ -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);
diff --git a/avr/debug.c b/avr/debug.c
index ea4aa21..89ef4b1 100644
--- a/avr/debug.c
+++ b/avr/debug.c
@@ -26,11 +26,9 @@
* 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;
diff --git a/avr/print-utils.c b/avr/print-utils.c
index b8100a0..69f4553 100644
--- a/avr/print-utils.c
+++ b/avr/print-utils.c
@@ -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)
diff --git a/avr/strerror.c b/avr/strerror.c
index 4fdc63d..a4d2a67 100644
--- a/avr/strerror.c
+++ b/avr/strerror.c
@@ -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"),
diff --git a/avr/z80-if.c b/avr/z80-if.c
index e36b369..6183849 100644
--- a/avr/z80-if.c
+++ b/avr/z80-if.c
@@ -136,6 +136,11 @@
#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 */
diff --git a/include/errnum.h b/include/errnum.h
index adb8a80..628c432 100644
--- a/include/errnum.h
+++ b/include/errnum.h
@@ -12,16 +12,17 @@
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;
diff --git a/include/print-utils.h b/include/print-utils.h
index ffff039..38de111 100644
--- a/include/print-utils.h
+++ b/include/print-utils.h
@@ -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
@@ -11,14 +11,14 @@
#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 */
diff --git a/include/z80-if.h b/include/z80-if.h
index ef87e5a..d5a5f56 100644
--- a/include/z80-if.h
+++ b/include/z80-if.h
@@ -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);