]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/debug.c
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0
12 #include <avr/eeprom.h>
15 #include "cli_readline.h"
16 #include "print-utils.h"
28 extern unsigned int __brkval
;
30 dump_ram(__malloc_heap_start
,
31 __brkval
- (unsigned int) __malloc_heap_start
,
41 command_ret_t
do_dump_mem(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
43 int (*readwhat
)(uint8_t *buf
, uint32_t addr
, uint8_t count
);
45 (void) cmdtp
; (void) flag
;
51 uint32_t length
= 128;
55 readwhat
= ram_read_buf
;
58 readwhat
= eeprom_read_buf
;
61 readwhat
= flash_read_buf
;
67 /* Address is specified since argc > 1 */
68 addr
= strtoul(argv
[1], NULL
, 16);
70 /* If another parameter, it is the length to display. */
72 length
= (uint16_t) strtoul(argv
[2], NULL
, 16);
74 /* Print the lines. */
75 dump_mem(addr
, addr
, length
, readwhat
, NULL
);
77 return CMD_RET_SUCCESS
;
80 command_ret_t
do_eep_cp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
82 uint16_t src
, dest
, count
;
91 src
= (size_t) strtoul(argv
[1], NULL
, 16);
92 dest
= (size_t) strtoul(argv
[2], NULL
, 16);
93 count
= (size_t) strtoul(argv
[3], NULL
, 16);
96 debug("src > EEPROM size: 0x%04x\n", src
);
97 return CMD_RET_FAILURE
;
100 debug("dest > EEPROM size: 0x%04x\n", dest
);
101 return CMD_RET_FAILURE
;
103 if (count
> E2END
+1) {
104 debug("count > EEPROM size: 0x%04x\n", count
);
105 return CMD_RET_FAILURE
;
108 debug("Zero length?\n");
109 return CMD_RET_FAILURE
;
119 while (count
-- > 0) {
121 data
= eeprom_read_byte((uint8_t *) src
);
122 eeprom_write_byte((uint8_t *) dest
, data
);
127 return CMD_RET_SUCCESS
;
138 static uint8_t *mm_last_addr
;
141 mod_mem_avr(cmd_tbl_t
*cmdtp
, int incrflag
, int flag
, int argc
, char * const argv
[])
150 return CMD_RET_USAGE
;
152 /* We use the last specified parameters, unless new ones are
157 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
158 /* New command specified.
161 /* Address is specified since argc > 1
163 addr
= (uint8_t *) (size_t) strtoul(argv
[1], NULL
, 16);
166 /* Print the address, followed by value. Then accept input for
167 * the next value. A non-converted value exits.
171 printf_P(PSTR("%04x: %02x"), addr
, data
);
173 nbytes
= cli_readline(PSTR(" ? "), 0);
174 if (nbytes
== 0 || (nbytes
== 1 && console_buffer
[0] == '-')) {
175 /* <CR> pressed as only input, don't modify current
176 * location and move to next. "-" pressed will go back.
179 addr
+= nbytes
? -1 : 1;
184 data
= strtoul(console_buffer
, &endp
, 16);
185 nbytes
= endp
- console_buffer
;
195 return CMD_RET_SUCCESS
;
199 command_ret_t
do_mem_mm_avr(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
201 return mod_mem_avr (cmdtp
, 1, flag
, argc
, argv
);
203 command_ret_t
do_mem_nm_avr(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
205 return mod_mem_avr (cmdtp
, 0, flag
, argc
, argv
);
208 /*------------------------------------------------------------------------------*/
214 struct __freelist
*nx
;
217 extern char *__brkval
; /* first location not yet allocated */
218 extern struct __freelist
*__flp
; /* freelist pointer (head of freelist) */
220 #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
223 printfreelist(const char * title
)
225 struct __freelist
*fp1
;
227 unsigned int freesum
= 0;
232 printf("%s no free list\n", title
? title
: "");
234 printf("Free list: %s\n", title
? title
: "");
235 for (i
= 0, fp1
= __flp
; fp1
; i
++, fp1
= fp1
->nx
) {
236 printf(" entry %d @ %04x: size %4u, next ",
237 i
, (size_t)fp1
, fp1
->sz
);
239 printf("%04x\n", (size_t)fp1
->nx
);
246 freesum
+= (size_t) STACK_POINTER() - __malloc_margin
- (size_t) __brkval
;
248 printf("SP: %04x, __brkval: %04x, Total free: %04u\n",
249 (size_t) STACK_POINTER(), (size_t) __brkval
, freesum
);