]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Add debug library; use with tmimsp platforms
authorR. Steve McKown <rsmckown@gmail.com>
Mon, 15 Oct 2012 00:59:23 +0000 (18:59 -0600)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 23 Oct 2012 23:10:41 +0000 (17:10 -0600)
tos/lib/debug/Debug.h [new file with mode: 0644]
tos/lib/debug/Debug.nc [new file with mode: 0644]
tos/lib/debug/DebugC.nc [new file with mode: 0644]
tos/lib/debug/DebugP.nc [new file with mode: 0644]
tos/lib/debug/Debug_undef.h [new file with mode: 0644]
tos/lib/debug/NoDebugP.nc [new file with mode: 0644]
tos/platforms/tmimsp/.family

diff --git a/tos/lib/debug/Debug.h b/tos/lib/debug/Debug.h
new file mode 100644 (file)
index 0000000..e9be7cf
--- /dev/null
@@ -0,0 +1,67 @@
+/* Copyright (c) 2006-2009 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/**
+ * TinyOS debug layer offering printf-style functionality.
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ *
+ * For a module to use the debug functions it must:
+ *
+ * 1. use the Debug interface, which is then wired to DebugC.
+ * 2. include "Debug.h" to set the macros appropriately.
+ *
+ * Optionally, a module may implement module specific debug, where a different
+ * global define can be used to individually select debug on or off for each
+ * module.  This feature requires the following lines of code in the module,
+ * after Debug.h has been included.  MODULENAME_DEBUG should be changed to a
+ * more meaningful, and module-unique, name, such as MYMODULE_DEBUG.
+ *
+ *    #ifndef SERIAL_DEBUG
+ *    #  undef MODULENAME_DEBUG
+ *    #else
+ *    #  ifndef MODULENAME_DEBUG
+ *    #    include "Debug_undef.h"
+ *    #  endif
+ *    #endif
+ *
+ * To activate debug for a program, add this line to the Makefile:
+ *    CFLAGS += -DSERIAL_DEBUG
+ *
+ * To activate debug for a module with selectable debug, one must additionally
+ * define the modules debug identifier in the Makefile, such as:
+ *    CFLAGS += -DMODULENAME_DEBUG
+ *
+ * Undefining SERIAL_DEBUG deactivates all program debug regardless of the state
+ * of any module-specific debug identifiers.
+ *
+ * Debug.h must no include the traditional multiple-inclusion guard so that each
+ * module including Debug.h has the opportunity to either set or clear (i.e.
+ * make a noop) the debug macros, according to the operating state defined for
+ * that module.
+ */
+
+#undef dbg_printf
+#undef dbg_assert
+
+#ifdef SERIAL_DEBUG
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#define dbg_printf(args...) uprintf(call Debug.uptr(), args)
+#define dbg_assert(condition, args...) \
+    do { if (condition) uprintf(call Debug.uptr(), args); } while(0)
+
+#else
+
+#define dbg_printf(args...) ((void)0)
+#define dbg_assert(condition, args...) ((void)0)
+
+#endif
diff --git a/tos/lib/debug/Debug.nc b/tos/lib/debug/Debug.nc
new file mode 100644 (file)
index 0000000..3fc6880
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (c) 2006-2009 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/* A simple debug component.
+ */
+
+#include <stdarg.h>
+#include "Uprint.h"
+
+interface Debug {
+  async command void raw(const void* ptr, uint16_t len);
+  async command void byteAsBits(uint8_t byte);
+  async command void hexdump(const void* ptr, uint16_t len);
+
+  /* Used for dbgprintf; see Debug.h */
+  async command uprint_ptr_t uptr();
+}
diff --git a/tos/lib/debug/DebugC.nc b/tos/lib/debug/DebugC.nc
new file mode 100644 (file)
index 0000000..4e83774
--- /dev/null
@@ -0,0 +1,37 @@
+/* Copyright (c) 2006-2009 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/* A simple debug component.  The best use would be to have a PlatformDebugC
+ * component that either wires to this component or one called NoDebugC
+ * depending upon compilation options.
+ */
+
+configuration DebugC {
+  provides interface Debug;
+}
+implementation
+{
+#ifdef SERIAL_DEBUG
+#warning "SERIAL DEBUG ON"
+
+  components DebugP;
+  Debug = DebugP;
+
+  components MainC;
+  MainC.SoftwareInit -> DebugP;
+
+  components DebugUartC;
+  DebugP.UartResource -> DebugUartC;
+  DebugP.UartByte -> DebugUartC;
+#else
+
+  components NoDebugP;
+  Debug = NoDebugP;
+#endif
+}
diff --git a/tos/lib/debug/DebugP.nc b/tos/lib/debug/DebugP.nc
new file mode 100644 (file)
index 0000000..d420f9d
--- /dev/null
@@ -0,0 +1,109 @@
+/* Copyright (c) 2006-2007 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/* A simple debug component.
+ */
+
+#include <ctype.h>
+#include <stdarg.h>
+#include "Uprint.h"
+
+module DebugP {
+  provides {
+    interface Init;
+    interface Debug;
+  }
+  uses {
+    interface Resource as UartResource;
+    interface UartByte;
+  }
+}
+implementation {
+  enum { COLUMNS = 16 };
+
+  bool m_on;
+
+  int debug_putc(int c)
+  {
+    call UartByte.send((uint8_t)c);
+    return c;
+  }
+
+  void uartWrite(const char* buf)
+  {
+    if (buf) {
+      uprintf(debug_putc, buf);
+    }
+  }
+
+  command error_t Init.init()
+  {
+    if (call UartResource.immediateRequest() != SUCCESS)
+      call UartResource.request();
+    return SUCCESS;
+  }
+
+  event void UartResource.granted() {}
+
+  async command uprint_ptr_t Debug.uptr()
+  {
+    return debug_putc;
+  }
+
+  async command void Debug.raw(const void* string, uint16_t len)
+  {
+    uint8_t* buf = (uint8_t*)string;
+    atomic {
+      if (buf) {
+        atomic {
+          while (len--) {
+            char c = *buf;
+
+            if (isprint(c))
+              debug_putc(c);
+            else
+              uprintf(debug_putc, "{%02x}", c);
+            buf++;
+          }
+        }
+      }
+    }
+  }
+
+  async command void Debug.byteAsBits(uint8_t byte)
+  {
+    atomic {
+      unsigned mask = 1 << 7;
+      uprintf(debug_putc, "0b");
+      while (mask) {
+        debug_putc((byte & mask) ? '1' : '0');
+        mask >>= 1;
+      }
+    }
+  }
+
+  async command void Debug.hexdump(const void* addr, uint16_t len)
+  {
+    atomic {
+      uint8_t* ptr = (void*)addr;
+      uint16_t i = 0;
+
+      /* FIXME: ptr as 16 bit value is platform specific */
+      uprintf(debug_putc, "Hexdump for location 0x%04x", (uint16_t)ptr);
+      while (i < len) {
+        char* prefix = (i % COLUMNS) ? "  " : "\r\n";
+
+       uprintf(debug_putc, "%s%02x", prefix, *ptr++);
+       i++;
+      }
+      if (i % COLUMNS)
+       uprintf(debug_putc, "\r\n");
+    }
+  }
+}
diff --git a/tos/lib/debug/Debug_undef.h b/tos/lib/debug/Debug_undef.h
new file mode 100644 (file)
index 0000000..3d6b373
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (c) 2006-2009 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/**
+ * TinyOS debug layer offering printf-style functionality.
+ *
+ * This module sets the debug function macros to no-op.  See Debug.h for more
+ * information.
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#undef dbg_printf
+#undef dbg_assert
+
+#define dbg_printf(args...) ((void)0)
+#define dbg_assert(condition, args...) ((void)0)
diff --git a/tos/lib/debug/NoDebugP.nc b/tos/lib/debug/NoDebugP.nc
new file mode 100644 (file)
index 0000000..e85fe17
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (c) 2006-2007 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/* A simple debug component.
+ */
+
+#include <stdarg.h>
+
+module NoDebugP {
+  provides interface Debug;
+}
+implementation {
+  async command uprint_ptr_t Debug.uptr() { return NULL; }
+  async command void Debug.raw(const void* string, uint16_t len) {}
+  async command void Debug.byteAsBits(uint8_t byte) {}
+  async command void Debug.hexdump(const void* addr, uint16_t len) {}
+}
index 71576bc33f9a45bb51d3d8d6b2dce2b1172df7b3..313b32dc524ee55f37161dd3c1fa0fbf316517c1 100644 (file)
@@ -23,6 +23,7 @@ push( @includes, qw(
   %T/chips/cp210x
   %T/chips/stm25p
   %T/lib/adc
+  %T/lib/debug
   %T/lib/misc
   %T/lib/power
   %T/lib/serial