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