]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - include/common.h
DEBUG: Fix debug macros
[karo-tx-uboot.git] / include / common.h
index fb41d7ae5fa3f37792f15bf216fc7ad56f6c003e..5ca8820898b2939b0f5edea8dbe80043b5cdccd1 100644 (file)
@@ -116,20 +116,26 @@ typedef volatile unsigned char    vu_char;
 #include <flash.h>
 #include <image.h>
 
-#ifdef DEBUG
-#define debug(fmt,args...)     printf (fmt ,##args)
-#define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args);
-#else
-#define debug(fmt,args...)
-#define debugX(level,fmt,args...)
-#endif /* DEBUG */
-
 #ifdef DEBUG
-# define _DEBUG 1
+#define _DEBUG 1
 #else
-# define _DEBUG 0
+#define _DEBUG 0
 #endif
 
+/*
+ * Output a debug text when condition "cond" is met. The "cond" should be
+ * computed by a preprocessor in the best case, allowing for the best
+ * optimization.
+ */
+#define debug_cond(cond, fmt, args...)         \
+       do {                                    \
+               if (cond)                       \
+                       printf(fmt, ##args);    \
+       } while (0)
+
+#define debug(fmt, args...)                    \
+       debug_cond(_DEBUG, fmt, ##args)
+
 /*
  * An assertion is run-time check done in debug mode only. If DEBUG is not
  * defined then it is skipped. If DEBUG is defined and the assertion fails,