src: use new libosmogsm and include/osmocom/[gsm|core] path to headers
[osmocom-bb.git] / src / target / firmware / comm / sercomm_cons.c
index fa08b50..987c992 100644 (file)
 #include <errno.h>
 #include <string.h>
 
+#include <asm/system.h>
+
 #include <calypso/uart.h>
 
 #include <console.h>
-#include <comm/msgb.h>
+#include <osmocom/core/msgb.h>
 #include <comm/sercomm.h>
 #include <comm/sercomm_cons.h>
 
@@ -50,7 +52,8 @@ static void raw_puts(const char *s)
 
 int sercomm_puts(const char *s)
 {
-       const int len = strlen(s) + 1;
+       unsigned long flags;
+       const int len = strlen(s);
        unsigned int bytes_left = len;
 
        if (!sercomm_initialized()) {
@@ -59,6 +62,12 @@ int sercomm_puts(const char *s)
                return len - 1;
        }
 
+       /* This function is called from any context: Supervisor, IRQ, FIQ, ...
+        * as such, we need to ensure re-entrant calls are either supported or
+        * avoided. */
+       local_irq_save(flags);
+       local_fiq_disable();
+
        while (bytes_left > 0) {
                unsigned int write_num, space_left, flush;
                uint8_t *data;
@@ -91,8 +100,11 @@ int sercomm_puts(const char *s)
                {
                        unsigned int i;
                        for (i = 0; i < write_num; i++) {
-                               /* flush buffer at end of line */
-                               if (*s == '\n')
+                               /* flush buffer at end of line, but skip
+                                * flushing if we have a backlog in order to
+                                * increase efficiency of msgb filling */
+                               if (*s == '\n' &&
+                                   sercomm_tx_queue_depth(SC_DLCI_CONSOLE) < 4)
                                        flush = 1;
                                *data++ = *s++;
                        }
@@ -107,6 +119,8 @@ int sercomm_puts(const char *s)
                }
        }
 
+       local_irq_restore(flags);
+
        return len - 1;
 }