From d9414fdab434454b73eea05eaeabec655125b251 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 22 Sep 2015 04:39:39 +0200 Subject: [PATCH] cpu: msp430fxyz: switch back to uart_stdio --- boards/msb-430-common/board_init.c | 4 +- boards/telosb/board.c | 4 +- boards/wsn430-common/board_init.c | 4 +- boards/z1/board.c | 4 +- cpu/msp430fxyz/Makefile.include | 2 +- cpu/msp430fxyz/include/msp430_stdio.h | 37 ------------------ cpu/msp430fxyz/msp430_stdio.c | 56 +++------------------------ 7 files changed, 15 insertions(+), 96 deletions(-) delete mode 100644 cpu/msp430fxyz/include/msp430_stdio.h diff --git a/boards/msb-430-common/board_init.c b/boards/msb-430-common/board_init.c index f4eb550591e1..21ff475d89b0 100644 --- a/boards/msb-430-common/board_init.c +++ b/boards/msb-430-common/board_init.c @@ -23,7 +23,7 @@ #include "cpu.h" #include "irq.h" #include "board.h" -#include "msp430_stdio.h" +#include "uart_stdio.h" #include "periph_conf.h" #include "kernel_internal.h" #include "msp430.h" @@ -205,5 +205,5 @@ void board_init(void) msp430_set_cpu_speed(CLOCK_CORECLOCK); /* finally initialize the STDIO */ - msp430_stdio_init(); + uart_stdio_init(); } diff --git a/boards/telosb/board.c b/boards/telosb/board.c index ebb505d82a71..1b5a285d9ff3 100644 --- a/boards/telosb/board.c +++ b/boards/telosb/board.c @@ -9,7 +9,7 @@ #include "cpu.h" #include "board.h" -#include "msp430_stdio.h" +#include "uart_stdio.h" void uart_init(void); @@ -123,7 +123,7 @@ void board_init(void) msp430_init_dco(); /* initialize the STDIO */ - msp430_stdio_init(); + uart_stdio_init(); /* enable interrupts */ __bis_SR_register(GIE); diff --git a/boards/wsn430-common/board_init.c b/boards/wsn430-common/board_init.c index a50ca620ce50..738230b51aa1 100644 --- a/boards/wsn430-common/board_init.c +++ b/boards/wsn430-common/board_init.c @@ -13,7 +13,7 @@ #include "kernel_internal.h" #include "msp430.h" #include "debug.h" -#include "msp430_stdio.h" +#include "uart_stdio.h" volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; @@ -113,5 +113,5 @@ void board_init(void) msp430_set_cpu_speed(MCLK_8MHZ_SCLK_8MHZ); /* initialize the STDIO */ - msp430_stdio_init(); + uart_stdio_init(); } diff --git a/boards/z1/board.c b/boards/z1/board.c index 2b8c6a71ae21..99d23dfb61e6 100644 --- a/boards/z1/board.c +++ b/boards/z1/board.c @@ -24,7 +24,7 @@ #include "cpu.h" #include "board.h" -#include "msp430_stdio.h" +#include "uart_stdio.h" static void z1_ports_init(void) { @@ -216,7 +216,7 @@ void board_init(void) msp430_init_dco(); /* initialize STDIO */ - msp430_stdio_init(); + uart_stdio_init(); /* enable interrupts */ __bis_SR_register(GIE); diff --git a/cpu/msp430fxyz/Makefile.include b/cpu/msp430fxyz/Makefile.include index 7f579d26e633..fd4c822745e3 100644 --- a/cpu/msp430fxyz/Makefile.include +++ b/cpu/msp430fxyz/Makefile.include @@ -2,4 +2,4 @@ INCLUDES += -I$(RIOTCPU)/msp430fxyz/include/ include $(RIOTCPU)/msp430-common/Makefile.include -export USEMODULE += periph periph_common +export USEMODULE += periph periph_common uart_stdio diff --git a/cpu/msp430fxyz/include/msp430_stdio.h b/cpu/msp430fxyz/include/msp430_stdio.h deleted file mode 100644 index c8b1e6deeb5e..000000000000 --- a/cpu/msp430fxyz/include/msp430_stdio.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2015 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup cpu_msp430fxyz - * - * @{ - * @file - * @brief STDIO over UART for MSP430 platforms - * - * @author Hauke Petersen - */ - -#ifndef MSP430_STDIO_H -#define MSP430_STDIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Initialize the STDIO data structured and the underlying UART driver - * as define in board.h - */ -void msp430_stdio_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* MSP430_STDIO_H */ -/** @} */ diff --git a/cpu/msp430fxyz/msp430_stdio.c b/cpu/msp430fxyz/msp430_stdio.c index 23e3fd62e204..17619dd1d5d3 100644 --- a/cpu/msp430fxyz/msp430_stdio.c +++ b/cpu/msp430fxyz/msp430_stdio.c @@ -18,61 +18,16 @@ * @} */ -#include "irq.h" -#include "mutex.h" -#include "board.h" -#include "ringbuffer.h" -#include "periph/uart.h" - -#include - -static mutex_t rx_lock = MUTEX_INIT; -static ringbuffer_t rx_buf; -static char rx_buf_mem[STDIO_RX_BUFSIZE]; - -static inline int safe_read(void) -{ - int res; - unsigned state = disableIRQ(); - res = ringbuffer_get_one(&rx_buf); - restoreIRQ(state); - return res; -} - -static void rx_cb(void *arg, char data) -{ - (void)arg; - - ringbuffer_add_one(&rx_buf, data); - /* this is a little dirty hack: it seems the MSP430 boards are too slow for - * processing data @ 115200 baud and calling mutex_unock() for each byte. By - * asserting, that the STDIO is used for the shell and we are only - * interested in completed lines anyway, we can reduce the overhead here by - * only waking the shell on newline chars */ - if (data == '\n') { - mutex_unlock(&rx_lock); - } -} - -void msp430_stdio_init(void) -{ - mutex_lock(&rx_lock); - ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_RX_BUFSIZE); - uart_init(STDIO, STDIO_BAUDRATE, rx_cb, NULL, 0); -} +#include "uart_stdio.h" /** * @brief Get one character from STDIO - used by the libc */ int getchar(void) { - int res = safe_read(); - - while (res == -1) { - mutex_lock(&rx_lock); - res = safe_read(); - } - return res; + char c; + uart_stdio_read(&c, 1); + return c; } /** @@ -81,6 +36,7 @@ int getchar(void) */ int putchar(int c) { - uart_write_blocking(STDIO, (char)c); + char _c = c; + uart_stdio_write(&_c, 1); return 1; }