]> cloudbase.mooo.com Git - z180-stamp.git/blob - avr/debug.c
Remove obsolete debug code
[z180-stamp.git] / avr / debug.c
1 /*
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7 #include "common.h"
8 #include <stdlib.h>
9 #include <string.h>
10 #include <ctype.h>
11 #include <avr/eeprom.h>
12
13 #include "command.h"
14 #include "print-utils.h"
15 #include "debug.h"
16
17 /*
18 * Debugging
19 */
20
21 #ifdef DEBUG
22
23
24 #if 0
25 void dump_heap(void)
26 {
27 extern unsigned int __brkval;
28
29 dump_ram(__malloc_heap_start,
30 __brkval - (unsigned int) __malloc_heap_start,
31 "=== Heap:");
32 }
33 #endif
34
35
36 /*
37 * Memory Display
38 * md addr {len}
39 */
40 command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
41 {
42 void (*readhow)(uint8_t *buf, uint32_t addr, uint8_t count);
43
44 (void) cmdtp; (void) flag;
45
46 if (argc < 2)
47 return CMD_RET_USAGE;
48
49 uint32_t addr;
50 uint32_t length = 128;
51
52 if (strchr(argv[0],'r') != NULL)
53 readhow = ram_read_buf;
54 else if (strchr(argv[0],'e') != NULL)
55 readhow = eeprom_read_buf;
56 else
57 return CMD_RET_USAGE;
58
59 /* Address is specified since argc > 1 */
60 addr = strtoul(argv[1], NULL, 16);
61
62 /* If another parameter, it is the length to display. */
63 if (argc > 2)
64 length = (uint16_t) strtoul(argv[2], NULL, 16);
65
66 /* Print the lines. */
67 dump_mem(addr, addr, length, readhow, NULL);
68
69 return CMD_RET_SUCCESS;
70 }
71
72 command_ret_t do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
73 {
74 uint16_t src, dest, count;
75 int_fast8_t step;
76
77 (void) cmdtp;
78 (void) flag;
79
80 if (argc != 4)
81 return CMD_RET_USAGE;
82
83 src = (size_t) strtoul(argv[1], NULL, 16);
84 dest = (size_t) strtoul(argv[2], NULL, 16);
85 count = (size_t) strtoul(argv[3], NULL, 16);
86
87 if (src > E2END) {
88 debug("src > EEPROM size: 0x%04x\n", src);
89 return CMD_RET_FAILURE;
90 }
91 if (dest > E2END) {
92 debug("dest > EEPROM size: 0x%04x\n", dest);
93 return CMD_RET_FAILURE;
94 }
95 if (count > E2END+1) {
96 debug("count > EEPROM size: 0x%04x\n", count);
97 return CMD_RET_FAILURE;
98 }
99 if (count == 0) {
100 debug("Zero length?\n");
101 return CMD_RET_FAILURE;
102 }
103
104 if (dest > src) {
105 src += count - 1;
106 dest += count - 1;
107 step = -1;
108 } else
109 step = 1;
110
111 while (count-- > 0) {
112 uint8_t data;
113 data = eeprom_read_byte((uint8_t *) src);
114 eeprom_write_byte((uint8_t *) dest, data);
115 src += step;
116 dest += step;
117
118 }
119 return CMD_RET_SUCCESS;
120 }
121
122
123 /*------------------------------------------------------------------------------*/
124
125 #if 1
126
127 struct __freelist {
128 size_t sz;
129 struct __freelist *nx;
130 };
131
132 extern char *__brkval; /* first location not yet allocated */
133 extern struct __freelist *__flp; /* freelist pointer (head of freelist) */
134
135 #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
136
137 void
138 printfreelist(const char * title)
139 {
140 struct __freelist *fp1;
141 int i;
142 unsigned int freesum = 0;
143
144 /* TODO: printf_P */
145
146 if (!__flp) {
147 printf("%s no free list\n", title ? title : "");
148 } else {
149 printf("Free list: %s\n", title ? title : "");
150 for (i = 0, fp1 = __flp; fp1; i++, fp1 = fp1->nx) {
151 printf(" entry %d @ %04x: size %4u, next ",
152 i, (size_t)fp1, fp1->sz);
153 if (fp1->nx)
154 printf("%04x\n", (size_t)fp1->nx);
155 else
156 printf("NULL\n");
157 freesum += fp1->sz;
158 }
159 }
160
161 freesum += (size_t) STACK_POINTER() - __malloc_margin - (size_t) __brkval;
162
163 printf("SP: %04x, __brkval: %04x, Total free: %04u\n",
164 (size_t) STACK_POINTER(), (size_t) __brkval, freesum);
165 }
166
167 #endif
168
169 #endif /* DEBUG */