]>
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 <avr/eeprom.h>
12 #include "cli_readline.h"
14 #include "print-utils.h"
26 command_ret_t
do_dump_mem(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag UNUSED
, int argc
, char * const argv
[])
28 ERRNUM (*readwhat
)(uint8_t *buf
, uint32_t addr
, uint8_t count
);
34 uint32_t length
= 128;
38 readwhat
= ram_read_buf
;
41 readwhat
= eeprom_read_buf
;
44 readwhat
= flash_read_buf
;
50 /* Address is specified since argc > 1 */
51 addr
= eval_arg(argv
[1], NULL
);
53 /* If another parameter, it is the length to display. */
55 length
= (uint16_t) eval_arg(argv
[2], NULL
);
57 /* Print the lines. */
58 dump_mem(addr
, addr
, length
, readwhat
, NULL
);
60 return CMD_RET_SUCCESS
;
63 command_ret_t
do_eep_cp(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
65 uint16_t src
, dest
, count
;
74 src
= (size_t) eval_arg(argv
[1], NULL
);
75 dest
= (size_t) eval_arg(argv
[2], NULL
);
76 count
= (size_t) eval_arg(argv
[3], NULL
);
79 debug("src > EEPROM size: 0x%04x\n", src
);
80 return CMD_RET_FAILURE
;
83 debug("dest > EEPROM size: 0x%04x\n", dest
);
84 return CMD_RET_FAILURE
;
86 if (count
> E2END
+1) {
87 debug("count > EEPROM size: 0x%04x\n", count
);
88 return CMD_RET_FAILURE
;
91 debug("Zero length?\n");
92 return CMD_RET_FAILURE
;
102 while (count
-- > 0) {
104 data
= eeprom_read_byte((uint8_t *) src
);
105 eeprom_write_byte((uint8_t *) dest
, data
);
110 return CMD_RET_SUCCESS
;
121 static uint8_t *mm_last_addr
;
124 mod_mem_avr(cmd_tbl_t
*cmdtp
, int incrflag
, uint_fast8_t flag
, int argc
, char * const argv
[])
132 return CMD_RET_USAGE
;
134 /* We use the last specified parameters, unless new ones are
139 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
140 /* New command specified.
143 /* Address is specified since argc > 1
145 addr
= (uint8_t *) (size_t) eval_arg(argv
[1], NULL
);
148 /* Print the address, followed by value. Then accept input for
149 * the next value. A non-converted value exits.
152 uint8_t data
= *addr
;
153 printf_P(PSTR("%04x: %02x"), addr
, data
);
155 nbytes
= cli_readline(PSTR(" ? "), 0);
156 if (nbytes
== 0 || (nbytes
== 1 && console_buffer
[0] == '-')) {
157 /* <CR> pressed as only input, don't modify current
158 * location and move to next. "-" pressed will go back.
161 addr
+= nbytes
? -1 : 1;
166 data
= eval_arg(console_buffer
, &endp
);
167 nbytes
= endp
- console_buffer
;
174 } while (nbytes
> 0);
177 return CMD_RET_SUCCESS
;
181 command_ret_t
do_mem_mm_avr(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
183 return mod_mem_avr (cmdtp
, 1, flag
, argc
, argv
);
185 command_ret_t
do_mem_nm_avr(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
187 return mod_mem_avr (cmdtp
, 0, flag
, argc
, argv
);
190 /*------------------------------------------------------------------------------*/
194 struct __freelist
*nx
;
197 extern char *__brkval
; /* first location not yet allocated */
198 extern struct __freelist
*__flp
; /* freelist pointer (head of freelist) */
200 #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
202 size_t get_freemem(void)
204 return (size_t) STACK_POINTER() - __malloc_margin
- (size_t) __brkval
;
208 printfreelist(const char * title
)
210 struct __freelist
*fp1
;
212 unsigned int freesum
= 0;
215 printf_P(PSTR("%s no free list\n"), title
? title
: "");
217 printf_P(PSTR("Free list: %s\n"), title
? title
: "");
218 for (i
= 0, fp1
= __flp
; fp1
; i
++, fp1
= fp1
->nx
) {
219 printf_P(PSTR(" entry %d @ %04x: size %4u, next "),
220 i
, (size_t)fp1
, fp1
->sz
);
222 printf_P(PSTR("%04x\n"), (size_t)fp1
->nx
);
224 printf_P(PSTR("NULL\n"));
229 freesum
+= get_freemem();
231 printf_P(PSTR("SP: %04x, __brkval: %04x, Total free: %04u\n"),
232 (size_t) STACK_POINTER(), (size_t) __brkval
, freesum
);
235 command_ret_t
do_pr_free_avr(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag UNUSED
, int argc UNUSED
, char * const argv
[] UNUSED
)
239 return CMD_RET_SUCCESS
;
244 //extern unsigned int __brkval;
246 dump_ram((uint8_t *)__malloc_heap_start
, (size_t) __malloc_heap_start
, __brkval
- __malloc_heap_start
,
250 command_ret_t
do_pr_heap_avr(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag UNUSED
, int argc UNUSED
, char * const argv
[] UNUSED
)
254 return CMD_RET_SUCCESS
;