]>
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 UNUSED
, uint_fast8_t flag UNUSED
, int argc
, char * const argv
[])
31 ERRNUM (*readwhat
)(uint8_t *buf
, uint32_t addr
, uint8_t count
);
37 uint32_t length
= 128;
41 readwhat
= ram_read_buf
;
44 readwhat
= eeprom_read_buf
;
47 readwhat
= flash_read_buf
;
53 /* Address is specified since argc > 1 */
54 addr
= eval_arg(argv
[1], NULL
);
56 /* If another parameter, it is the length to display. */
58 length
= (uint16_t) eval_arg(argv
[2], NULL
);
60 /* Print the lines. */
61 dump_mem(addr
, addr
, length
, readwhat
, NULL
);
63 return CMD_RET_SUCCESS
;
66 command_ret_t
do_eep_cp(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
68 uint16_t src
, dest
, count
;
77 src
= (size_t) eval_arg(argv
[1], NULL
);
78 dest
= (size_t) eval_arg(argv
[2], NULL
);
79 count
= (size_t) eval_arg(argv
[3], NULL
);
82 debug("src > EEPROM size: 0x%04x\n", src
);
83 return CMD_RET_FAILURE
;
86 debug("dest > EEPROM size: 0x%04x\n", dest
);
87 return CMD_RET_FAILURE
;
89 if (count
> E2END
+1) {
90 debug("count > EEPROM size: 0x%04x\n", count
);
91 return CMD_RET_FAILURE
;
94 debug("Zero length?\n");
95 return CMD_RET_FAILURE
;
105 while (count
-- > 0) {
107 data
= eeprom_read_byte((uint8_t *) src
);
108 eeprom_write_byte((uint8_t *) dest
, data
);
113 return CMD_RET_SUCCESS
;
124 static uint8_t *mm_last_addr
;
127 mod_mem_avr(cmd_tbl_t
*cmdtp
, int incrflag
, uint_fast8_t flag
, int argc
, char * const argv
[])
135 return CMD_RET_USAGE
;
137 /* We use the last specified parameters, unless new ones are
142 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
143 /* New command specified.
146 /* Address is specified since argc > 1
148 addr
= (uint8_t *) (size_t) eval_arg(argv
[1], NULL
);
151 /* Print the address, followed by value. Then accept input for
152 * the next value. A non-converted value exits.
155 uint8_t data
= *addr
;
156 printf_P(PSTR("%04x: %02x"), addr
, data
);
158 nbytes
= cli_readline(PSTR(" ? "), 0);
159 if (nbytes
== 0 || (nbytes
== 1 && console_buffer
[0] == '-')) {
160 /* <CR> pressed as only input, don't modify current
161 * location and move to next. "-" pressed will go back.
164 addr
+= nbytes
? -1 : 1;
169 data
= eval_arg(console_buffer
, &endp
);
170 nbytes
= endp
- console_buffer
;
177 } while (nbytes
> 0);
180 return CMD_RET_SUCCESS
;
184 command_ret_t
do_mem_mm_avr(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
186 return mod_mem_avr (cmdtp
, 1, flag
, argc
, argv
);
188 command_ret_t
do_mem_nm_avr(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
190 return mod_mem_avr (cmdtp
, 0, flag
, argc
, argv
);
193 /*------------------------------------------------------------------------------*/
197 struct __freelist
*nx
;
200 extern char *__brkval
; /* first location not yet allocated */
201 extern struct __freelist
*__flp
; /* freelist pointer (head of freelist) */
203 #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
205 size_t get_freemem(void)
207 return (size_t) STACK_POINTER() - __malloc_margin
- (size_t) __brkval
;
211 printfreelist(const char * title
)
213 struct __freelist
*fp1
;
215 unsigned int freesum
= 0;
218 printf_P(PSTR("%s no free list\n"), title
? title
: "");
220 printf_P(PSTR("Free list: %s\n"), title
? title
: "");
221 for (i
= 0, fp1
= __flp
; fp1
; i
++, fp1
= fp1
->nx
) {
222 printf_P(PSTR(" entry %d @ %04x: size %4u, next "),
223 i
, (size_t)fp1
, fp1
->sz
);
225 printf_P(PSTR("%04x\n"), (size_t)fp1
->nx
);
227 printf_P(PSTR("NULL\n"));
232 freesum
+= get_freemem();
234 printf_P(PSTR("SP: %04x, __brkval: %04x, Total free: %04u\n"),
235 (size_t) STACK_POINTER(), (size_t) __brkval
, freesum
);
238 command_ret_t
do_pr_free_avr(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag UNUSED
, int argc UNUSED
, char * const argv
[] UNUSED
)
242 return CMD_RET_SUCCESS
;
247 //extern unsigned int __brkval;
249 dump_ram((uint8_t *)__malloc_heap_start
, (size_t) __malloc_heap_start
, __brkval
- __malloc_heap_start
,
253 command_ret_t
do_pr_heap_avr(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag UNUSED
, int argc UNUSED
, char * const argv
[] UNUSED
)
257 return CMD_RET_SUCCESS
;