]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/debug.c
2 * (C) Copyright 2014,2016 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0
9 #include <stdlib.h> /* __malloc_margin */
12 #include <avr/eeprom.h>
15 #include "cli_readline.h"
17 #include "print-utils.h"
29 extern unsigned int __brkval
;
31 dump_ram(__malloc_heap_start
,
32 __brkval
- (unsigned int) __malloc_heap_start
,
42 command_ret_t
do_dump_mem(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
44 int (*readwhat
)(uint8_t *buf
, uint32_t addr
, uint8_t count
);
46 (void) cmdtp
; (void) flag
;
52 uint32_t length
= 128;
56 readwhat
= ram_read_buf
;
59 readwhat
= eeprom_read_buf
;
62 readwhat
= flash_read_buf
;
68 /* Address is specified since argc > 1 */
69 addr
= eval_arg(argv
[1], NULL
);
71 /* If another parameter, it is the length to display. */
73 length
= (uint16_t) eval_arg(argv
[2], NULL
);
75 /* Print the lines. */
76 dump_mem(addr
, addr
, length
, readwhat
, NULL
);
78 return CMD_RET_SUCCESS
;
81 command_ret_t
do_eep_cp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
83 uint16_t src
, dest
, count
;
92 src
= (size_t) eval_arg(argv
[1], NULL
);
93 dest
= (size_t) eval_arg(argv
[2], NULL
);
94 count
= (size_t) eval_arg(argv
[3], NULL
);
97 debug("src > EEPROM size: 0x%04x\n", src
);
98 return CMD_RET_FAILURE
;
101 debug("dest > EEPROM size: 0x%04x\n", dest
);
102 return CMD_RET_FAILURE
;
104 if (count
> E2END
+1) {
105 debug("count > EEPROM size: 0x%04x\n", count
);
106 return CMD_RET_FAILURE
;
109 debug("Zero length?\n");
110 return CMD_RET_FAILURE
;
120 while (count
-- > 0) {
122 data
= eeprom_read_byte((uint8_t *) src
);
123 eeprom_write_byte((uint8_t *) dest
, data
);
128 return CMD_RET_SUCCESS
;
139 static uint8_t *mm_last_addr
;
142 mod_mem_avr(cmd_tbl_t
*cmdtp
, int incrflag
, int flag
, int argc
, char * const argv
[])
151 return CMD_RET_USAGE
;
153 /* We use the last specified parameters, unless new ones are
158 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
159 /* New command specified.
162 /* Address is specified since argc > 1
164 addr
= (uint8_t *) (size_t) eval_arg(argv
[1], NULL
);
167 /* Print the address, followed by value. Then accept input for
168 * the next value. A non-converted value exits.
172 printf_P(PSTR("%04x: %02x"), addr
, data
);
174 nbytes
= cli_readline(PSTR(" ? "), 0);
175 if (nbytes
== 0 || (nbytes
== 1 && console_buffer
[0] == '-')) {
176 /* <CR> pressed as only input, don't modify current
177 * location and move to next. "-" pressed will go back.
180 addr
+= nbytes
? -1 : 1;
185 data
= eval_arg(console_buffer
, &endp
);
186 nbytes
= endp
- console_buffer
;
193 } while (nbytes
> 0);
196 return CMD_RET_SUCCESS
;
200 command_ret_t
do_mem_mm_avr(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
202 return mod_mem_avr (cmdtp
, 1, flag
, argc
, argv
);
204 command_ret_t
do_mem_nm_avr(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
206 return mod_mem_avr (cmdtp
, 0, flag
, argc
, argv
);
209 /*------------------------------------------------------------------------------*/
215 struct __freelist
*nx
;
218 extern char *__brkval
; /* first location not yet allocated */
219 extern struct __freelist
*__flp
; /* freelist pointer (head of freelist) */
221 #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
224 printfreelist(const char * title
)
226 struct __freelist
*fp1
;
228 unsigned int freesum
= 0;
233 printf("%s no free list\n", title
? title
: "");
235 printf("Free list: %s\n", title
? title
: "");
236 for (i
= 0, fp1
= __flp
; fp1
; i
++, fp1
= fp1
->nx
) {
237 printf(" entry %d @ %04x: size %4u, next ",
238 i
, (size_t)fp1
, fp1
->sz
);
240 printf("%04x\n", (size_t)fp1
->nx
);
247 freesum
+= (size_t) STACK_POINTER() - __malloc_margin
- (size_t) __brkval
;
249 printf("SP: %04x, __brkval: %04x, Total free: %04u\n",
250 (size_t) STACK_POINTER(), (size_t) __brkval
, freesum
);