]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> | |
3 | * | |
4 | * SPDX-License-Identifier: GPL-2.0+ | |
5 | */ | |
6 | ||
7 | #include "common.h" | |
8 | #include <stdint.h> | |
9 | #include <stdio.h> | |
10 | #include <ctype.h> | |
11 | #include "con-utils.h" | |
12 | #include "print-utils.h" | |
13 | ||
14 | void print_blanks(uint_fast8_t count) | |
15 | { | |
16 | while(count--) | |
17 | putchar(' '); | |
18 | } | |
19 | ||
20 | ||
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 | ||
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 | ||
38 | int dump_mem(uint32_t address, uint32_t offset, uint32_t len, | |
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; | |
44 | uint8_t pre = offset % 16; | |
45 | offset = offset & ~0x0f; | |
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; | |
57 | readfkt(buf, address, llen - pre); | |
58 | ||
59 | printf_P(PSTR("%s%.5lx:"),indent, offset); | |
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 | ||
75 | address += llen - pre; | |
76 | offset += 16; | |
77 | pre = 0; | |
78 | len -= llen; | |
79 | ||
80 | if (ctrlc()) | |
81 | return -1; | |
82 | } | |
83 | return 0; | |
84 | } | |
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 | ||
91 | void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title) | |
92 | { | |
93 | dump_mem((uint32_t) (size_t) addr, offset, len, ram_read_buf, title); | |
94 | } |