]>
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 command_ret_t
do_dump_mem(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
31 int (*readwhat
)(uint8_t *buf
, uint32_t addr
, uint8_t count
);
33 (void) cmdtp
; (void) flag
;
39 uint32_t length
= 128;
43 readwhat
= ram_read_buf
;
46 readwhat
= eeprom_read_buf
;
49 readwhat
= flash_read_buf
;
55 /* Address is specified since argc > 1 */
56 addr
= eval_arg(argv
[1], NULL
);
58 /* If another parameter, it is the length to display. */
60 length
= (uint16_t) eval_arg(argv
[2], NULL
);
62 /* Print the lines. */
63 dump_mem(addr
, addr
, length
, readwhat
, NULL
);
65 return CMD_RET_SUCCESS
;
68 command_ret_t
do_eep_cp(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
70 uint16_t src
, dest
, count
;
79 src
= (size_t) eval_arg(argv
[1], NULL
);
80 dest
= (size_t) eval_arg(argv
[2], NULL
);
81 count
= (size_t) eval_arg(argv
[3], NULL
);
84 debug("src > EEPROM size: 0x%04x\n", src
);
85 return CMD_RET_FAILURE
;
88 debug("dest > EEPROM size: 0x%04x\n", dest
);
89 return CMD_RET_FAILURE
;
91 if (count
> E2END
+1) {
92 debug("count > EEPROM size: 0x%04x\n", count
);
93 return CMD_RET_FAILURE
;
96 debug("Zero length?\n");
97 return CMD_RET_FAILURE
;
107 while (count
-- > 0) {
109 data
= eeprom_read_byte((uint8_t *) src
);
110 eeprom_write_byte((uint8_t *) dest
, data
);
115 return CMD_RET_SUCCESS
;
126 static uint8_t *mm_last_addr
;
129 mod_mem_avr(cmd_tbl_t
*cmdtp
, int incrflag
, uint_fast8_t flag
, int argc
, char * const argv
[])
137 return CMD_RET_USAGE
;
139 /* We use the last specified parameters, unless new ones are
144 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
145 /* New command specified.
148 /* Address is specified since argc > 1
150 addr
= (uint8_t *) (size_t) eval_arg(argv
[1], NULL
);
153 /* Print the address, followed by value. Then accept input for
154 * the next value. A non-converted value exits.
157 uint8_t data
= *addr
;
158 printf_P(PSTR("%04x: %02x"), addr
, data
);
160 nbytes
= cli_readline(PSTR(" ? "), 0);
161 if (nbytes
== 0 || (nbytes
== 1 && console_buffer
[0] == '-')) {
162 /* <CR> pressed as only input, don't modify current
163 * location and move to next. "-" pressed will go back.
166 addr
+= nbytes
? -1 : 1;
171 data
= eval_arg(console_buffer
, &endp
);
172 nbytes
= endp
- console_buffer
;
179 } while (nbytes
> 0);
182 return CMD_RET_SUCCESS
;
186 command_ret_t
do_mem_mm_avr(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
188 return mod_mem_avr (cmdtp
, 1, flag
, argc
, argv
);
190 command_ret_t
do_mem_nm_avr(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
192 return mod_mem_avr (cmdtp
, 0, flag
, argc
, argv
);
195 /*------------------------------------------------------------------------------*/
199 struct __freelist
*nx
;
202 extern char *__brkval
; /* first location not yet allocated */
203 extern struct __freelist
*__flp
; /* freelist pointer (head of freelist) */
205 #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
207 size_t get_freemem(void)
209 return (size_t) STACK_POINTER() - __malloc_margin
- (size_t) __brkval
;
213 printfreelist(const char * title
)
215 struct __freelist
*fp1
;
217 unsigned int freesum
= 0;
222 printf("%s no free list\n", title
? title
: "");
224 printf("Free list: %s\n", title
? title
: "");
225 for (i
= 0, fp1
= __flp
; fp1
; i
++, fp1
= fp1
->nx
) {
226 printf(" entry %d @ %04x: size %4u, next ",
227 i
, (size_t)fp1
, fp1
->sz
);
229 printf("%04x\n", (size_t)fp1
->nx
);
236 freesum
+= get_freemem();
238 printf("SP: %04x, __brkval: %04x, Total free: %04u\n",
239 (size_t) STACK_POINTER(), (size_t) __brkval
, freesum
);
242 command_ret_t
do_pr_free_avr(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag UNUSED
, int argc UNUSED
, char * const argv
[] UNUSED
)
246 return CMD_RET_SUCCESS
;
251 //extern unsigned int __brkval;
253 dump_ram((uint8_t *)__malloc_heap_start
, (size_t) __malloc_heap_start
, __brkval
- __malloc_heap_start
,
257 command_ret_t
do_pr_heap_avr(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag UNUSED
, int argc UNUSED
, char * const argv
[] UNUSED
)
261 return CMD_RET_SUCCESS
;