Basic debug library

Dependents:   modem_ref_helper_for_v5_3_217 modem_ref_helper

Files at this revision

API Documentation at this revision

Comitter:
Jeej
Date:
Thu Aug 01 08:32:35 2019 +0000
Parent:
8:87a867b8a129
Child:
10:0e6e54fb08c0
Commit message:
Updated for mbed-os 5.13

Changed in this revision

WizziDebug.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 87a867b8a129 -r 87d9cc850af1 WizziDebug.cpp
--- a/WizziDebug.cpp	Wed Jul 31 16:49:03 2019 +0000
+++ b/WizziDebug.cpp	Thu Aug 01 08:32:35 2019 +0000
@@ -10,7 +10,7 @@
 
 static CBuffer<uint8_t, 2048>   g_dbg_buf;
 static char                     g_dbg_msg[DBG_MAX_STRING_SIZE];
-static Thread                   g_dbg_thread(osPriorityIdle, 512, NULL);
+static Thread                   g_dbg_thread(osPriorityLow, 512);
 static RawSerial*               g_dbg_serial;
 static Mutex                    g_dbg_ressource;
 static Semaphore                g_dbg_print(0);
@@ -159,9 +159,6 @@
 // Prints a message to the debug port.
 void dbg_print(const char* format, ...)
 {
-    // Critical section
-    g_dbg_ressource.lock();
-
     int size;
 
     va_list args;
@@ -170,9 +167,6 @@
     va_end(args);
     
     dbg_add_to_buf(g_dbg_msg, size);
-    
-    // End of critical section
-    g_dbg_ressource.unlock();
 }
 
 // Flush the pending debug messages.
@@ -217,9 +211,6 @@
 
 void dbg_print_data(const char* before, const char* format, uint8_t* data, uint8_t length, const char* after)
 {
-    // Critical section
-    g_dbg_ressource.lock();
-    
     uint32_t total_len = 0;
     
     total_len += sprintf(g_dbg_msg, before);
@@ -233,9 +224,6 @@
     total_len += sprintf(&g_dbg_msg[total_len], after);
     
     dbg_add_to_buf(g_dbg_msg, total_len);
-    
-    // End of critical section
-    g_dbg_ressource.unlock();
 }
 
 
@@ -246,7 +234,7 @@
     
     while (true)
     {
-        g_dbg_print.try_acquire();
+        g_dbg_print.acquire();
         
         if (g_dbg_missing)
         {
@@ -264,7 +252,7 @@
             do {
                 byte = g_dbg_buf.pop();
                 g_dbg_serial->putc(byte);
-            } while (byte != '\n');
+            } while (byte != '\n' && !g_dbg_buf.empty());
 #else
             // Flush characters one by one
             g_dbg_serial->putc(g_dbg_buf.pop());
@@ -273,7 +261,6 @@
             g_dbg_ressource.unlock();
             ThisThread::yield();
         }
-
     }
 }