1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 10:12:45 +01:00

sys: uart_stdio: make use of isrpipe

This commit is contained in:
Kaspar Schleiser 2016-12-07 20:33:23 +01:00
parent b89d81fdba
commit dd70231bed
2 changed files with 7 additions and 28 deletions

View File

@ -373,7 +373,7 @@ ifneq (,$(filter rtt_stdio,$(USEMODULE)))
endif
ifneq (,$(filter uart_stdio,$(USEMODULE)))
USEMODULE += tsrb
USEMODULE += isrpipe
endif
ifneq (,$(filter isrpipe,$(USEMODULE)))

View File

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