From dd70231bed3a1139386cbe503dae9dd62c1d5a94 Mon Sep 17 00:00:00 2001
From: Kaspar Schleiser <kaspar@schleiser.de>
Date: Wed, 7 Dec 2016 20:33:23 +0100
Subject: [PATCH] sys: uart_stdio: make use of isrpipe

---
 Makefile.dep                |  2 +-
 sys/uart_stdio/uart_stdio.c | 33 ++++++---------------------------
 2 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/Makefile.dep b/Makefile.dep
index 5ae32e1a37..0b4d6df2bd 100644
--- a/Makefile.dep
+++ b/Makefile.dep
@@ -373,7 +373,7 @@ ifneq (,$(filter rtt_stdio,$(USEMODULE)))
 endif
 
 ifneq (,$(filter uart_stdio,$(USEMODULE)))
-  USEMODULE += tsrb
+  USEMODULE += isrpipe
 endif
 
 ifneq (,$(filter isrpipe,$(USEMODULE)))
diff --git a/sys/uart_stdio/uart_stdio.c b/sys/uart_stdio/uart_stdio.c
index 14dace5e5c..4dcc2dac67 100644
--- a/sys/uart_stdio/uart_stdio.c
+++ b/sys/uart_stdio/uart_stdio.c
@@ -24,15 +24,12 @@
  */
 
 #include <stdio.h>
-#include "uart_stdio.h"
 
-#include "tsrb.h"
-#include "thread.h"
-#include "mutex.h"
-#include "irq.h"
+#include "uart_stdio.h"
 
 #include "board.h"
 #include "periph/uart.h"
+#include "isrpipe.h"
 
 #ifdef USE_ETHOS_FOR_STDIO
 #include "ethos.h"
@@ -42,39 +39,21 @@ extern ethos_t ethos;
 #define ENABLE_DEBUG 0
 #include "debug.h"
 
-/**
- * @brief use mutex for waiting on incoming UART chars
- */
-static mutex_t _rx_mutex = MUTEX_INIT;
 static char _rx_buf_mem[UART_STDIO_RX_BUFSIZE];
-static tsrb_t _rx_buf = TSRB_INIT(_rx_buf_mem);
-
-/**
- * @brief Receive a new character from the UART and put it into the receive buffer
- */
-void uart_stdio_rx_cb(void *arg, uint8_t data)
-{
-    (void)arg;
-    tsrb_add_one(&_rx_buf, (uint8_t)data);
-    mutex_unlock(&_rx_mutex);
-}
+static isrpipe_t _isrpipe = ISRPIPE_INIT(_rx_buf_mem);
 
 void uart_stdio_init(void)
 {
 #ifndef USE_ETHOS_FOR_STDIO
-    uart_init(UART_STDIO_DEV, UART_STDIO_BAUDRATE, uart_stdio_rx_cb, NULL);
+    uart_init(UART_STDIO_DEV, UART_STDIO_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &_isrpipe);
 #else
-    uart_init(ETHOS_UART, ETHOS_BAUDRATE, uart_stdio_rx_cb, NULL);
+    uart_init(ETHOS_UART, ETHOS_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &_isrpipe);
 #endif
 }
 
 int uart_stdio_read(char* buffer, int count)
 {
-    int res;
-    while (!(res = tsrb_get(&_rx_buf, buffer, count))) {
-        mutex_lock(&_rx_mutex);
-    }
-    return res;
+    return isrpipe_read(&_isrpipe, buffer, count);
 }
 
 int uart_stdio_write(const char* buffer, int len)
-- 
GitLab