]>
Commit | Line | Data |
---|---|---|
35edb766 L |
1 | /* |
2 | * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> | |
3 | * | |
4 | * SPDX-License-Identifier: GPL-2.0+ | |
5 | */ | |
6 | ||
e39cd2a2 | 7 | #include "common.h" |
8f23e84c | 8 | #include <stdio.h> |
e39cd2a2 L |
9 | #include <ctype.h> |
10 | #include "con-utils.h" | |
8f23e84c L |
11 | #include "print-utils.h" |
12 | ||
13 | void print_blanks(uint_fast8_t count) | |
14 | { | |
15 | while(count--) | |
16 | putchar(' '); | |
17 | } | |
18 | ||
19 | ||
fc454c83 L |
20 | void eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count) |
21 | { | |
22 | eeprom_read_block((void *) buf, (const void *) (size_t) addr, count); | |
23 | } | |
24 | ||
25 | void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count) | |
26 | { | |
27 | while (count--) | |
28 | *buf++ = *(uint8_t *) (size_t) addr++; | |
29 | } | |
30 | ||
31 | int dump_mem(uint32_t address, uint32_t offset, uint32_t len, | |
e39cd2a2 L |
32 | void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title) |
33 | { | |
34 | uint8_t buf[16]; | |
35 | char *indent = NULL; | |
36 | uint8_t llen = 16; | |
fc454c83 L |
37 | uint8_t pre = offset % 16; |
38 | offset = offset & ~0x0f; | |
e39cd2a2 L |
39 | len += pre; |
40 | uint8_t i; | |
41 | ||
42 | if (title && *title) { | |
43 | printf_P(PSTR("%s\n"),title); | |
44 | indent = " "; | |
45 | } | |
46 | ||
47 | while (len) { | |
48 | if (len < 16) | |
49 | llen = len; | |
fc454c83 | 50 | readfkt(buf, address, llen - pre); |
e39cd2a2 | 51 | |
fc454c83 | 52 | printf_P(PSTR("%s%.5lx:"),indent, offset); |
e39cd2a2 L |
53 | for (i = 0; i < llen; i++) { |
54 | if ((i % 8) == 0) | |
55 | putchar(' '); | |
56 | if (i < pre) | |
57 | printf_P(PSTR(".. ")); | |
58 | else | |
59 | printf_P(PSTR("%.2x "), buf[i-pre]); | |
60 | } | |
61 | /* fill line with whitespace for nice ASCII print */ | |
62 | print_blanks(3 * (16u - i) + (16u-i)/8 + 1 + pre); | |
63 | /* Print data in ASCII characters */ | |
64 | for (i = pre; i < llen; i++) | |
65 | printf_P(PSTR("%c"), isprint(buf[i-pre]) ? buf[i-pre] : '.'); | |
66 | putchar('\n'); | |
67 | ||
fc454c83 L |
68 | address += llen - pre; |
69 | offset += 16; | |
e39cd2a2 | 70 | pre = 0; |
e39cd2a2 L |
71 | len -= llen; |
72 | ||
73 | if (ctrlc()) | |
74 | return -1; | |
75 | } | |
76 | return 0; | |
77 | } | |
fc454c83 L |
78 | |
79 | void dump_eep(uint32_t addr, unsigned int len, char *title) | |
80 | { | |
81 | dump_mem(addr, addr, len, eeprom_read_buf, title); | |
82 | } | |
83 | ||
cca42593 | 84 | void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title) |
fc454c83 | 85 | { |
cca42593 | 86 | dump_mem((uint32_t) (size_t) addr, offset, len, ram_read_buf, title); |
fc454c83 | 87 | } |