Debug library

Dependents:   NetworkingCoreLib LwIPNetworking yeswecancoap lwip

Revision:
1:bd1844de60f1
Parent:
0:3ac250c92185
Child:
3:53f6e0430d8e
--- 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();
+  }
+}