]>
Commit | Line | Data |
---|---|---|
92b46605 L |
1 | #include "common.h" |
2 | #include <stdlib.h> | |
f338df2a | 3 | #include <string.h> |
92b46605 L |
4 | #include <ctype.h> |
5 | #include <avr/eeprom.h> | |
6 | ||
7 | #include "command.h" | |
e39cd2a2 | 8 | #include "print-utils.h" |
92b46605 | 9 | #include "debug.h" |
92b46605 L |
10 | /* |
11 | * Debugging | |
12 | */ | |
e39cd2a2 | 13 | |
92b46605 L |
14 | #ifdef DEBUG |
15 | ||
92b46605 | 16 | |
f338df2a | 17 | #if 0 |
92b46605 L |
18 | void dump_heap(void) |
19 | { | |
20 | extern unsigned int __brkval; | |
21 | ||
e39cd2a2 | 22 | dump_ram(__malloc_heap_start, |
92b46605 L |
23 | __brkval - (unsigned int) __malloc_heap_start, |
24 | "=== Heap:"); | |
25 | } | |
f338df2a | 26 | #endif |
92b46605 | 27 | |
92b46605 L |
28 | |
29 | /* | |
61b0cfe9 | 30 | * Memory Display |
92b46605 L |
31 | * md addr {len} |
32 | */ | |
d0581f88 | 33 | command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
92b46605 | 34 | { |
e39cd2a2 | 35 | void (*readhow)(uint8_t *buf, uint32_t addr, uint8_t count); |
507d25e2 | 36 | |
f338df2a | 37 | (void) cmdtp; (void) flag; |
92b46605 L |
38 | |
39 | if (argc < 2) | |
40 | return CMD_RET_USAGE; | |
41 | ||
e39cd2a2 L |
42 | uint32_t addr; |
43 | uint32_t length = 128; | |
507d25e2 | 44 | |
f338df2a | 45 | if (strchr(argv[0],'r') != NULL) |
e39cd2a2 | 46 | readhow = ram_read_buf; |
f338df2a | 47 | else if (strchr(argv[0],'e') != NULL) |
e39cd2a2 | 48 | readhow = eeprom_read_buf; |
f338df2a L |
49 | else |
50 | return CMD_RET_USAGE; | |
92b46605 | 51 | |
f338df2a | 52 | /* Address is specified since argc > 1 */ |
e39cd2a2 | 53 | addr = strtoul(argv[1], NULL, 16); |
f338df2a L |
54 | |
55 | /* If another parameter, it is the length to display. */ | |
56 | if (argc > 2) | |
57 | length = (uint16_t) strtoul(argv[2], NULL, 16); | |
92b46605 L |
58 | |
59 | /* Print the lines. */ | |
fc454c83 | 60 | dump_mem(addr, addr, length, readhow, NULL); |
92b46605 | 61 | |
d0581f88 | 62 | return CMD_RET_SUCCESS; |
92b46605 L |
63 | } |
64 | ||
d0581f88 | 65 | command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
92b46605 L |
66 | { |
67 | uint16_t src, dest, count; | |
68 | int_fast8_t step; | |
69 | ||
70 | (void) cmdtp; | |
71 | (void) flag; | |
72 | ||
73 | if (argc != 4) | |
74 | return CMD_RET_USAGE; | |
75 | ||
76 | src = (size_t) strtoul(argv[1], NULL, 16); | |
77 | dest = (size_t) strtoul(argv[2], NULL, 16); | |
78 | count = (size_t) strtoul(argv[3], NULL, 16); | |
79 | ||
80 | if (src > E2END) { | |
81 | debug("src > EEPROM size: 0x%04x\n", src); | |
d0581f88 | 82 | return CMD_RET_FAILURE; |
92b46605 L |
83 | } |
84 | if (dest > E2END) { | |
85 | debug("dest > EEPROM size: 0x%04x\n", dest); | |
d0581f88 | 86 | return CMD_RET_FAILURE; |
92b46605 L |
87 | } |
88 | if (count > E2END+1) { | |
89 | debug("count > EEPROM size: 0x%04x\n", count); | |
d0581f88 | 90 | return CMD_RET_FAILURE; |
92b46605 L |
91 | } |
92 | if (count == 0) { | |
69988dc1 | 93 | debug("Zero length?\n"); |
d0581f88 | 94 | return CMD_RET_FAILURE; |
92b46605 L |
95 | } |
96 | ||
97 | if (dest > src) { | |
98 | src += count - 1; | |
99 | dest += count - 1; | |
100 | step = -1; | |
101 | } else | |
102 | step = 1; | |
103 | ||
104 | while (count-- > 0) { | |
105 | uint8_t data; | |
106 | data = eeprom_read_byte((uint8_t *) src); | |
107 | eeprom_write_byte((uint8_t *) dest, data); | |
108 | src += step; | |
109 | dest += step; | |
110 | ||
111 | } | |
d0581f88 | 112 | return CMD_RET_SUCCESS; |
92b46605 | 113 | } |
69988dc1 L |
114 | |
115 | /*------------------------------------------------------------------------------*/ | |
116 | ||
117 | ||
507d25e2 | 118 | #if 1 |
dea9a315 | 119 | |
69988dc1 L |
120 | struct __freelist { |
121 | size_t sz; | |
122 | struct __freelist *nx; | |
123 | }; | |
124 | ||
125 | extern char *__brkval; /* first location not yet allocated */ | |
126 | extern struct __freelist *__flp; /* freelist pointer (head of freelist) */ | |
127 | ||
128 | #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG) | |
129 | ||
130 | void | |
131 | printfreelist(const char * title) | |
132 | { | |
133 | struct __freelist *fp1; | |
134 | int i; | |
135 | unsigned int freesum = 0; | |
136 | ||
507d25e2 L |
137 | /* TODO: printf_P */ |
138 | ||
69988dc1 L |
139 | if (!__flp) { |
140 | printf("%s no free list\n", title ? title : ""); | |
141 | } else { | |
142 | printf("Free list: %s\n", title ? title : ""); | |
143 | for (i = 0, fp1 = __flp; fp1; i++, fp1 = fp1->nx) { | |
144 | printf(" entry %d @ %04x: size %4u, next ", | |
145 | i, (size_t)fp1, fp1->sz); | |
146 | if (fp1->nx) | |
147 | printf("%04x\n", (size_t)fp1->nx); | |
148 | else | |
149 | printf("NULL\n"); | |
150 | freesum += fp1->sz; | |
151 | } | |
152 | } | |
507d25e2 | 153 | |
69988dc1 L |
154 | freesum += (size_t) STACK_POINTER() - __malloc_margin - (size_t) __brkval; |
155 | ||
156 | printf("SP: %04x, __brkval: %04x, Total free: %04u\n", | |
157 | (size_t) STACK_POINTER(), (size_t) __brkval, freesum); | |
158 | } | |
159 | ||
dea9a315 | 160 | #endif |
69988dc1 | 161 | |
92b46605 | 162 | #endif /* DEBUG */ |