X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/0f3b947bda5f34662a611272b9f12199e0da9aca..aea51b6c4c93c56715f50e64d424e1181c6d0242:/avr/print-utils.c diff --git a/avr/print-utils.c b/avr/print-utils.c index 83f86a9..15f69f8 100644 --- a/avr/print-utils.c +++ b/avr/print-utils.c @@ -1,7 +1,7 @@ /* - * (C) Copyright 2014 Leo C. + * (C) Copyright 2014,2018 Leo C. * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ #include "common.h" @@ -18,31 +18,30 @@ 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]; - char *indent = NULL; uint8_t llen = 16; uint8_t pre = offset % 16; offset = offset & ~0x0f; @@ -51,16 +50,18 @@ int dump_mem(uint32_t address, uint32_t offset, uint32_t len, if (title && *title) { printf_P(PSTR("%s\n"),title); - indent = " "; } while (len) { if (len < 16) llen = len; - if (readfkt(buf, address, llen - pre) != 0) - return -2; /* TODO: Error codes */ + ERRNUM err = readfkt(buf, address, llen - pre); + if (err != ESUCCESS) + return err; - printf_P(PSTR("%s%.5lx:"),indent, offset); + if (title) + print_blanks(4); + printf_P(PSTR("%.5lx:"),offset); for (i = 0; i < llen; i++) { if ((i % 8) == 0) putchar(' '); @@ -82,9 +83,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)