]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Debugging code moved to debug.c
authorLeo C <erbl259-lmu@yahoo.de>
Sat, 16 Aug 2014 12:46:12 +0000 (14:46 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Sat, 16 Aug 2014 12:46:12 +0000 (14:46 +0200)
avr/Tupfile
avr/debug.c [new file with mode: 0644]
avr/env.c

index b7da73be6ec02e6d601ca43e7b662d6b45e1afa1..199b86c3a5a0a8a4aba577fb8004ea31ccd931b7 100644 (file)
@@ -35,6 +35,7 @@ GDB   = $(TOOLCHAIN)-gdb
 ###############################################################################
 
 ifdef DEBUG
+SRC    += debug.c
 DEFS   += -DDEBUG=2
 endif
 
diff --git a/avr/debug.c b/avr/debug.c
new file mode 100644 (file)
index 0000000..620eb4d
--- /dev/null
@@ -0,0 +1,170 @@
+#include "common.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include <avr/eeprom.h>
+
+#include "command.h"
+#include "debug.h"
+
+/*
+ * Debugging
+ */
+#ifdef DEBUG
+
+
+static void print_blanks(uint_fast8_t count)
+{
+       while(count--)
+               putchar(' ');
+}
+
+
+void dump_ram(const uint8_t *startaddr, int len, char *title)
+{
+       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;
+
+               printf_P(PSTR("    %.4x:"), (size_t) addr);
+               print_blanks(3 * pre);
+               for (i = pre; i < llen; i++)
+                       printf_P(PSTR(" %.2x"), addr[i]);
+               print_blanks(3 * (16 - i + 1) + pre);
+               for (i = pre; i < llen; i++)
+                       printf_P(PSTR("%c"), isprint(addr[i]) ? addr[i] : '.');
+               putchar('\n');
+
+               pre = 0;
+               addr += 16;
+               len -= llen;
+       }
+}
+
+void dump_heap(void)
+{
+       extern unsigned int __brkval;
+
+       dump_ram((uint8_t *) __malloc_heap_start,
+               __brkval - (unsigned int) __malloc_heap_start,
+               "=== Heap:");
+}
+
+/* TODO: combine with dump_ram() */
+void dump_eep(const uint8_t *addr, unsigned int len)
+{
+       uint_fast8_t i;
+       uint8_t buf[16];
+
+       printf_P(PSTR("eeprom dump:"));
+       while (len) {
+               printf_P(PSTR("\n    0x%.4x:"), (unsigned int) addr);
+               for (i = 0; i<16; i++)
+                       buf[i] = eeprom_read_byte(addr + i);
+               for (i = 0; i<16; i++)
+                       printf_P(PSTR(" %.2x"), buf[i]);
+               printf_P(PSTR("   "));
+               for (i = 0; i<16; i++)
+                       printf_P(PSTR("%c"), isprint(buf[i]) ? buf[i] : '.');
+
+               addr += 16;
+               len -= len > 16 ? 16 : len;
+       }
+       putchar('\n');
+}
+
+/*
+ * EEPROM Display
+ *     md addr {len}
+ */
+int do_dump_eep(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;
+
+       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);
+
+               /* 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);
+
+       return 0;
+}
+
+int do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       uint16_t src, dest, count;
+       int_fast8_t step;
+
+       (void) cmdtp;
+       (void) flag;
+
+       if (argc != 4)
+               return CMD_RET_USAGE;
+
+       src = (size_t) strtoul(argv[1], NULL, 16);
+       dest = (size_t) strtoul(argv[2], NULL, 16);
+       count = (size_t) strtoul(argv[3], NULL, 16);
+
+       if (src > E2END) {
+               debug("src > EEPROM size: 0x%04x\n", src);
+               return 1;
+       }
+       if (dest > E2END) {
+               debug("dest > EEPROM size: 0x%04x\n", dest);
+               return 1;
+       }
+       if (count > E2END+1) {
+               debug("count > EEPROM size: 0x%04x\n", count);
+               return 1;
+       }
+       if (count == 0) {
+               debug("Zero length ???\n");
+               return 1;
+       }
+
+       if (dest > src) {
+               src += count - 1;
+               dest += count - 1;
+               step = -1;
+       } else
+               step = 1;
+
+       while (count-- > 0) {
+               uint8_t data;
+               data = eeprom_read_byte((uint8_t *) src);
+               eeprom_write_byte((uint8_t *) dest, data);
+               src += step;
+               dest += step;
+
+       }
+       return 0;
+}
+#endif /* DEBUG */
+
index 9063a17f8a259a0de93a6b3838a2db6bb5186bfb..e16dc8452746f00565c30c2c0e13baa22e8b970a 100644 (file)
--- a/avr/env.c
+++ b/avr/env.c
@@ -36,170 +36,6 @@ const FLASH char default_env[] = {
 };
 
 
-#ifdef DEBUG
-
-/*
- * Debugging
- *
- * TODO: move elsewhere
- */
-#include <ctype.h>
-
-static void print_blanks(uint_fast8_t count)
-{
-       while(count--)
-               putchar(' ');
-}
-
-
-void dump_ram(const uint8_t *startaddr, int len, char *title)
-{
-       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;
-                       
-               printf_P(PSTR("    %.4x:"), (size_t) addr);
-               print_blanks(3 * pre);
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR(" %.2x"), addr[i]);
-               print_blanks(3 * (16 - i + 1) + pre);
-               for (i = pre; i < llen; i++)
-                       printf_P(PSTR("%c"), isprint(addr[i]) ? addr[i] : '.');
-               putchar('\n');
-
-               pre = 0;
-               addr += 16;
-               len -= llen;
-       }
-}
-
-void dump_heap(void)
-{
-       extern unsigned int __brkval;
-
-       dump_ram((uint8_t *) __malloc_heap_start, 
-               __brkval - (unsigned int) __malloc_heap_start,
-               "=== Heap:");
-}
-
-/* TODO: combine with dump_ram() */
-void dump_eep(const uint8_t *addr, unsigned int len)
-{
-       uint_fast8_t i;
-       uint8_t buf[16];
-       
-       printf_P(PSTR("eeprom dump:"));
-       while (len) {
-               printf_P(PSTR("\n    0x%.4x:"), (unsigned int) addr);
-               for (i = 0; i<16; i++)
-                       buf[i] = eeprom_read_byte(addr + i);
-               for (i = 0; i<16; i++)
-                       printf_P(PSTR(" %.2x"), buf[i]);
-               printf_P(PSTR("   "));
-               for (i = 0; i<16; i++) 
-                       printf_P(PSTR("%c"), isprint(buf[i]) ? buf[i] : '.');
-                       
-               addr += 16;
-               len -= len > 16 ? 16 : len;
-       }
-       putchar('\n');
-}
-
-/* 
- * EEPROM Display
- *     md addr {len}
- */
-int do_dump_eep(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;
-
-       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);
-
-               /* 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);
-
-       return 0;
-}
-
-int do_eep_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       uint16_t src, dest, count;
-       int_fast8_t step;
-       
-       (void) cmdtp;
-       (void) flag;
-
-       if (argc != 4)
-               return CMD_RET_USAGE;
-
-       src = (size_t) strtoul(argv[1], NULL, 16);
-       dest = (size_t) strtoul(argv[2], NULL, 16);
-       count = (size_t) strtoul(argv[3], NULL, 16);
-
-       if (src > E2END) {
-               debug("src > EEPROM size: 0x%04x\n", src);
-               return 1;
-       }
-       if (dest > E2END) {
-               debug("dest > EEPROM size: 0x%04x\n", dest);
-               return 1;
-       }
-       if (count > E2END+1) {
-               debug("count > EEPROM size: 0x%04x\n", count);
-               return 1;
-       }
-       if (count == 0) {
-               debug("Zero length ???\n");
-               return 1;
-       }
-       
-       if (dest > src) {
-               src += count - 1;
-               dest += count - 1;
-               step = -1;
-       } else
-               step = 1;
-
-       while (count-- > 0) {
-               uint8_t data;
-               data = eeprom_read_byte((uint8_t *) src);
-               eeprom_write_byte((uint8_t *) dest, data);
-               src += step;
-               dest += step;
-
-       }
-       return 0;
-}
-#endif /* DEBUG */
 
 
 typedef struct environment_s {