Debug library

Dependents:   NetworkingCoreLib LwIPNetworking yeswecancoap lwip

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Thu May 31 15:09:00 2012 +0000
Parent:
0:3ac250c92185
Child:
3:53f6e0430d8e
Commit message:
Newline characters can be setup

Changed in this revision

dbg.cpp Show annotated file Show diff for this revision Revisions of this file
dbg.h Show annotated file Show diff for this revision Revisions of this file
--- a/dbg.cpp	Thu May 24 15:33:14 2012 +0000
+++ b/dbg.cpp	Thu May 31 15:09:00 2012 +0000
@@ -35,14 +35,23 @@
 
 Mutex* debug_printf_mutex; //Singleton runtime initialisation to avoid static initialisation chaos problems
 
+static char debug_newline[3];
+
 void debug_init()
 {
+  debug_set_newline("\n");
   debug_pc.baud(115200);
   debug_printf_mutex = new Mutex();
   printf("[START]\n");
   fflush(stdout);
 }
 
+void debug_set_newline(const char* newline)
+{
+  strncpy( debug_newline, newline, 2 );
+  debug_newline[2] = '\0';
+}
+
 void debug(int level, const char* module, int line, const char* fmt, ...)
 {
   osStatus ret = debug_printf_mutex->lock();
@@ -79,7 +88,7 @@
   vprintf(fmt, argp);
   va_end(argp);
 
-  printf("\n");
+  printf(debug_newline);
 
   fflush(stdout);
 
@@ -98,4 +107,26 @@
   debug_printf_mutex->unlock();
 }
 
+void debug_exact(const char* fmt, ...)
+{
+  osStatus ret = debug_printf_mutex->lock();
+  if(ret != osOK)
+  {
+    /*
+    printf("[FATAL] DBG Mutex failed!! (ret code = %02x - Mutex is @ %p)\n", ret, &debug_printf_mutex);
+    error("");
+    while(1); //FATAL
+    */
+  }
+  
+  va_list argp;
 
+  va_start(argp, fmt);
+  vprintf(fmt, argp);
+  va_end(argp);
+  
+  if(ret == osOK)
+  {
+    debug_printf_mutex->unlock();
+  }
+}
--- a/dbg.h	Thu May 24 15:33:14 2012 +0000
+++ b/dbg.h	Thu May 31 15:09:00 2012 +0000
@@ -31,15 +31,14 @@
 
 void debug_init(void);
 void debug(int level, const char* module, int line, const char* fmt, ...);
+void debug_set_newline(const char* newline);
 void debug_error(const char* module, int line, int ret);
-
-#if __DEBUG__
-//#undef __DEBUG__
-#endif
-//#define __DEBUG__ 0
+void debug_exact(const char* fmt, ...);
 
 #define DBG_INIT() do{ debug_init(); }while(0)
 
+#define DBG_SET_NEWLINE( x ) do{ debug_set_newline(x); }while(0)
+
 #if __DEBUG__ > 0
 #ifndef __MODULE__
 #error "__MODULE__ must be defined"
@@ -68,8 +67,10 @@
 
 #if __DEBUG__ >= 4
 #define DBG(...) do{ debug(4, __MODULE__, __LINE__, __VA_ARGS__); }while(0)
+#define DBGX(...) do{ debug_exact(__VA_ARGS__); }while(0)
 #else
 #define DBG(...) do{ }while(0)
+#define DBGX(...) do{ }while(0)
 #endif
 
 #ifdef __cplusplus