X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=blobdiff_plain;f=tos%2Flib%2Fdebug%2FDebug.h;fp=tos%2Flib%2Fdebug%2FDebug.h;h=e9be7cf0bebec18e99c36b701d4c3cc0490526bd;hp=0000000000000000000000000000000000000000;hb=c40d959ed0b5880f73809836eadddd72a7c277d6;hpb=eb7d4fbd7e465dd1a4a8450111ec93af2dce936b diff --git a/tos/lib/debug/Debug.h b/tos/lib/debug/Debug.h new file mode 100644 index 00000000..e9be7cf0 --- /dev/null +++ b/tos/lib/debug/Debug.h @@ -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 + * + * 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 +#include + +#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