summaryrefslogtreecommitdiff
path: root/avr/debug.c
diff options
context:
space:
mode:
authorLeo C2014-08-18 23:40:36 +0200
committerLeo C2014-08-18 23:40:36 +0200
commitf338df2abc35f85961aa6266458f94ea2a102b81 (patch)
tree2f608280c2368cda835b6de19fa0ff8f6c85dfd7 /avr/debug.c
parent1da3acc4b7215e76d459905c3e74675ffa679ce0 (diff)
downloadz180-stamp-f338df2abc35f85961aa6266458f94ea2a102b81.zip
Command 'go <startaddr>' works now
Add debug command to display AVR RAM
Diffstat (limited to 'avr/debug.c')
-rw-r--r--avr/debug.c103
1 files changed, 80 insertions, 23 deletions
diff --git a/avr/debug.c b/avr/debug.c
index 620eb4d..e62869b 100644
--- a/avr/debug.c
+++ b/avr/debug.c
@@ -1,5 +1,6 @@
#include "common.h"
#include <stdlib.h>
+#include <string.h>
#include <ctype.h>
#include <avr/eeprom.h>
@@ -11,6 +12,7 @@
*/
#ifdef DEBUG
+//uint8_t eeprom_read_byte (const uint8_t *__p)
static void print_blanks(uint_fast8_t count)
{
@@ -18,7 +20,54 @@ static void print_blanks(uint_fast8_t count)
putchar(' ');
}
+static uint8_t ram_read_byte(const uint8_t *p)
+{
+ return *p;
+}
+void dump_mem(const uint8_t *startaddr, int len,
+ uint8_t (*readfkt)(const uint8_t *), char *title)
+{
+ uint8_t buf[16];
+ uint8_t llen = 16;
+ uint8_t pre = (size_t) startaddr % 16;
+ const uint8_t *addr = (uint8_t *) ((size_t) startaddr & ~0x0f);
+ len += pre;
+ uint8_t i;
+
+ if (title && *title)
+ printf_P(PSTR("%s\n"),title);
+
+ while (len) {
+ if (len < 16)
+ llen = len;
+
+ for (i = pre; i < llen; i++)
+ buf[i] = readfkt(addr + i);
+
+ printf_P(PSTR("%04x:"), addr);
+ for (i = 0; i < llen; i++) {
+ if ((i % 8) == 0)
+ putchar(' ');
+ if (i < pre)
+ printf_P(PSTR(".. "));
+ else
+ printf_P(PSTR("%.2x "), buf[i]);
+ }
+ /* fill line with whitespace for nice ASCII print */
+ print_blanks(3 * (16u - i) + (16u-i)/8 + 1 + pre);
+ /* Print data in ASCII characters */
+ for (i = pre; i < llen; i++)
+ printf_P(PSTR("%c"), isprint(buf[i]) ? buf[i] : '.');
+ putchar('\n');
+
+ pre = 0;
+ addr += 16;
+ len -= llen;
+ }
+}
+
+#if 0
void dump_ram(const uint8_t *startaddr, int len, char *title)
{
uint8_t llen = 16;
@@ -48,7 +97,8 @@ void dump_ram(const uint8_t *startaddr, int len, char *title)
len -= llen;
}
}
-
+#endif
+#if 0
void dump_heap(void)
{
extern unsigned int __brkval;
@@ -57,9 +107,12 @@ void dump_heap(void)
__brkval - (unsigned int) __malloc_heap_start,
"=== Heap:");
}
+#endif
+#if 0
/* TODO: combine with dump_ram() */
-void dump_eep(const uint8_t *addr, unsigned int len)
+void dump_eep(const uint8_t *addr, unsigned int len,
+ uint8_t (*readfkt)(const uint8_t *))
{
uint_fast8_t i;
uint8_t buf[16];
@@ -68,7 +121,7 @@ void dump_eep(const uint8_t *addr, unsigned int len)
while (len) {
printf_P(PSTR("\n 0x%.4x:"), (unsigned int) addr);
for (i = 0; i<16; i++)
- buf[i] = eeprom_read_byte(addr + i);
+ buf[i] = readfkt(addr + i);
for (i = 0; i<16; i++)
printf_P(PSTR(" %.2x"), buf[i]);
printf_P(PSTR(" "));
@@ -80,39 +133,43 @@ void dump_eep(const uint8_t *addr, unsigned int len)
}
putchar('\n');
}
+#endif
+
/*
* EEPROM Display
* md addr {len}
*/
-int do_dump_eep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- const uint8_t *addr;
- uint16_t length;
-
- (void) cmdtp;
-
-
- /* We use the last specified parameters, unless new ones are
- * entered.
- */
- addr = 0;
- length = 128;
+// static const uint8_t *addr;
+// static uint16_t length = 128;
+ uint8_t (*readhow)(const uint8_t *);
+
+ (void) cmdtp; (void) flag;
if (argc < 2)
return CMD_RET_USAGE;
- if ((flag & CMD_FLAG_REPEAT) == 0) {
- /* Address is specified since argc > 1 */
- addr = (const uint8_t *) (size_t) strtoul(argv[1], NULL, 16);
+ const uint8_t *addr;
+ uint16_t length = 128;
+
+ if (strchr(argv[0],'r') != NULL)
+ readhow = ram_read_byte;
+ else if (strchr(argv[0],'e') != NULL)
+ readhow = eeprom_read_byte;
+ else
+ return CMD_RET_USAGE;
- /* If another parameter, it is the length to display. */
- if (argc > 2)
- length = (uint16_t) strtoul(argv[2], NULL, 16);
- }
+ /* Address is specified since argc > 1 */
+ addr = (const uint8_t *) (size_t) strtoul(argv[1], NULL, 16);
+
+ /* If another parameter, it is the length to display. */
+ if (argc > 2)
+ length = (uint16_t) strtoul(argv[2], NULL, 16);
/* Print the lines. */
- dump_eep(addr, length);
+ dump_mem(addr, length, readhow, NULL);
return 0;
}