]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/print-utils.c
Add makefiles (replace Tup)
[z180-stamp.git] / avr / print-utils.c
index 4205a90332fd7ff3a59f2f2489d5a51ec6a357fe..15f69f8c475c6b5b7bc92f6301124d316cb41d88 100644 (file)
@@ -1,4 +1,11 @@
+/*
+ * (C) Copyright 2014,2018 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
+
 #include "common.h"
+#include <stdint.h>
 #include <stdio.h>
 #include <ctype.h>
 #include "con-utils.h"
@@ -11,22 +18,30 @@ void print_blanks(uint_fast8_t count)
 }
 
 
-void 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 ESUCCESS;
+}
+
+ERRNUM ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+{
+       while (count--)
+               *buf++ = *(uint8_t *) (size_t) addr++;
+       return ESUCCESS;
 }
 
-void 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)
 {
-               while (count--)
-                       *buf++ = *(uint8_t *) (size_t) addr++;
+       while (count--)
+               *buf++ = *(const __memx uint8_t *) (__uint24) addr++;
+       return ESUCCESS;
 }
 
-int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
-               void (*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;
@@ -35,15 +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;
-               readfkt(buf, address, llen - pre);
+               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(' ');
@@ -65,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)