+/*
+ * (C) Copyright 2014,2018 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
#include "common.h"
-#include <stdio.h>
-#include <ctype.h>
+#include <stdint.h>
#include "con-utils.h"
#include "print-utils.h"
}
-int dump_mem(uint32_t startaddr, uint32_t len,
- void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
+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;
+}
+
+ERRNUM flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+{
+ while (count--)
+ *buf++ = *(const __memx uint8_t *) (__uint24) addr++;
+ return ESUCCESS;
+}
+
+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 = startaddr % 16;
- uint32_t addr = startaddr & ~0x0f;
+ uint8_t pre = offset % 16;
+ offset = offset & ~0x0f;
len += pre;
uint8_t i;
if (title && *title) {
printf_P(PSTR("%s\n"),title);
- indent = " ";
}
while (len) {
if (len < 16)
llen = len;
- readfkt(buf, addr + pre, llen - pre);
+ ERRNUM err = readfkt(buf, address, llen - pre);
+ if (err != ESUCCESS)
+ return err;
- printf_P(PSTR("%s%.5lx:"),indent, addr);
+ if (title)
+ print_blanks(4);
+ printf_P(PSTR("%.5lx:"),offset);
for (i = 0; i < llen; i++) {
if ((i % 8) == 0)
putchar(' ');
printf_P(PSTR("%c"), isprint(buf[i-pre]) ? buf[i-pre] : '.');
putchar('\n');
+ address += llen - pre;
+ offset += 16;
pre = 0;
- addr += 16;
len -= llen;
if (ctrlc())
- return -1;
+ return EINTR;
}
- return 0;
+ return ESUCCESS;
+}
+
+void dump_eep(uint32_t addr, unsigned int len, char *title)
+{
+ dump_mem(addr, addr, len, eeprom_read_buf, title);
+}
+
+void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title)
+{
+ dump_mem((uint32_t) (size_t) addr, offset, len, ram_read_buf, title);
}