]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/debug.c
5 #include <avr/eeprom.h>
15 //uint8_t eeprom_read_byte (const uint8_t *__p)
17 static void print_blanks(uint_fast8_t count
)
23 static uint8_t ram_read_byte(const uint8_t *p
)
28 void dump_mem(const uint8_t *startaddr
, int len
,
29 uint8_t (*readfkt
)(const uint8_t *), char *title
)
33 uint8_t pre
= (size_t) startaddr
% 16;
34 const uint8_t *addr
= (uint8_t *) ((size_t) startaddr
& ~0x0f);
39 printf_P(PSTR("%s\n"),title
);
45 for (i
= pre
; i
< llen
; i
++)
46 buf
[i
] = readfkt(addr
+ i
);
48 printf_P(PSTR("%04x:"), addr
);
49 for (i
= 0; i
< llen
; i
++) {
53 printf_P(PSTR(".. "));
55 printf_P(PSTR("%.2x "), buf
[i
]);
57 /* fill line with whitespace for nice ASCII print */
58 print_blanks(3 * (16u - i
) + (16u-i
)/8 + 1 + pre
);
59 /* Print data in ASCII characters */
60 for (i
= pre
; i
< llen
; i
++)
61 printf_P(PSTR("%c"), isprint(buf
[i
]) ? buf
[i
] : '.');
71 void dump_ram(const uint8_t *startaddr
, int len
, char *title
)
74 uint8_t pre
= (size_t) startaddr
% 16;
75 const uint8_t *addr
= (uint8_t *) ((size_t) startaddr
& ~0x0f);
80 printf_P(PSTR("%s\n"),title
);
86 printf_P(PSTR(" %.4x:"), (size_t) addr
);
87 print_blanks(3 * pre
);
88 for (i
= pre
; i
< llen
; i
++)
89 printf_P(PSTR(" %.2x"), addr
[i
]);
90 print_blanks(3 * (16 - i
+ 1) + pre
);
91 for (i
= pre
; i
< llen
; i
++)
92 printf_P(PSTR("%c"), isprint(addr
[i
]) ? addr
[i
] : '.');
104 extern unsigned int __brkval
;
106 dump_ram((uint8_t *) __malloc_heap_start
,
107 __brkval
- (unsigned int) __malloc_heap_start
,
113 /* TODO: combine with dump_ram() */
114 void dump_eep(const uint8_t *addr
, unsigned int len
,
115 uint8_t (*readfkt
)(const uint8_t *))
120 printf_P(PSTR("eeprom dump:"));
122 printf_P(PSTR("\n 0x%.4x:"), (unsigned int) addr
);
123 for (i
= 0; i
<16; i
++)
124 buf
[i
] = readfkt(addr
+ i
);
125 for (i
= 0; i
<16; i
++)
126 printf_P(PSTR(" %.2x"), buf
[i
]);
128 for (i
= 0; i
<16; i
++)
129 printf_P(PSTR("%c"), isprint(buf
[i
]) ? buf
[i
] : '.');
132 len
-= len
> 16 ? 16 : len
;
143 command_ret_t
do_dump_mem(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
145 // static const uint8_t *addr;
146 // static uint16_t length = 128;
147 uint8_t (*readhow
)(const uint8_t *);
149 (void) cmdtp
; (void) flag
;
152 return CMD_RET_USAGE
;
155 uint16_t length
= 128;
157 if (strchr(argv
[0],'r') != NULL
)
158 readhow
= ram_read_byte
;
159 else if (strchr(argv
[0],'e') != NULL
)
160 readhow
= eeprom_read_byte
;
162 return CMD_RET_USAGE
;
164 /* Address is specified since argc > 1 */
165 addr
= (const uint8_t *) (size_t) strtoul(argv
[1], NULL
, 16);
167 /* If another parameter, it is the length to display. */
169 length
= (uint16_t) strtoul(argv
[2], NULL
, 16);
171 /* Print the lines. */
172 dump_mem(addr
, length
, readhow
, NULL
);
174 return CMD_RET_SUCCESS
;
177 command_ret_t
do_eep_cp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
179 uint16_t src
, dest
, count
;
186 return CMD_RET_USAGE
;
188 src
= (size_t) strtoul(argv
[1], NULL
, 16);
189 dest
= (size_t) strtoul(argv
[2], NULL
, 16);
190 count
= (size_t) strtoul(argv
[3], NULL
, 16);
193 debug("src > EEPROM size: 0x%04x\n", src
);
194 return CMD_RET_FAILURE
;
197 debug("dest > EEPROM size: 0x%04x\n", dest
);
198 return CMD_RET_FAILURE
;
200 if (count
> E2END
+1) {
201 debug("count > EEPROM size: 0x%04x\n", count
);
202 return CMD_RET_FAILURE
;
205 debug("Zero length ???\n");
206 return CMD_RET_FAILURE
;
216 while (count
-- > 0) {
218 data
= eeprom_read_byte((uint8_t *) src
);
219 eeprom_write_byte((uint8_t *) dest
, data
);
224 return CMD_RET_SUCCESS
;