/*
- * (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.
/*--------------------------------------------------------------------------*/
-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;
}
/*--------------------------------------------------------------------------*/
}
/* 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;
}
* 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);
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)
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 {
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);
* 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;
* 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;
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);
* 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;
/*
- * (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"
}
-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;
if (len < 16)
llen = len;
if (readfkt(buf, address, llen - pre) != 0)
- return -2; /* TODO: Error codes */
+ return -EBUSTO;
if (title)
print_blanks(4);
len -= llen;
if (ctrlc())
- return -1;
+ return EINTR;
}
- return 0;
+ return ESUCCESS;
}
void dump_eep(uint32_t addr, unsigned int len, char *title)
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"),
#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 */
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;
/*
- * (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 */
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);