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