--- /dev/null
+/* 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
--- /dev/null
+/* 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();
+}
--- /dev/null
+/* 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
+}
--- /dev/null
+/* 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");
+ }
+ }
+}
--- /dev/null
+/* 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)
--- /dev/null
+/* 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) {}
+}
%T/chips/cp210x
%T/chips/stm25p
%T/lib/adc
+ %T/lib/debug
%T/lib/misc
%T/lib/power
%T/lib/serial