Browse Source

sys: uart_stdio: make use of isrpipe

pr/spi.typo
Kaspar Schleiser 6 years ago
parent
commit
dd70231bed
  1. 2
      Makefile.dep
  2. 33
      sys/uart_stdio/uart_stdio.c

2
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)))

33
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)

Loading…
Cancel
Save