1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #3924 from kaspar030/msp430fxyz_use_uart_stdio

cpu: make msp430fxyz use uart stdio
This commit is contained in:
Thomas Eichinger 2015-09-25 14:37:21 +02:00
commit 7b3d1a728e
7 changed files with 15 additions and 96 deletions

View File

@ -23,7 +23,7 @@
#include "cpu.h" #include "cpu.h"
#include "irq.h" #include "irq.h"
#include "board.h" #include "board.h"
#include "msp430_stdio.h" #include "uart_stdio.h"
#include "periph_conf.h" #include "periph_conf.h"
#include "kernel_internal.h" #include "kernel_internal.h"
#include "msp430.h" #include "msp430.h"
@ -205,5 +205,5 @@ void board_init(void)
msp430_set_cpu_speed(CLOCK_CORECLOCK); msp430_set_cpu_speed(CLOCK_CORECLOCK);
/* finally initialize the STDIO */ /* finally initialize the STDIO */
msp430_stdio_init(); uart_stdio_init();
} }

View File

@ -9,7 +9,7 @@
#include "cpu.h" #include "cpu.h"
#include "board.h" #include "board.h"
#include "msp430_stdio.h" #include "uart_stdio.h"
void uart_init(void); void uart_init(void);
@ -123,7 +123,7 @@ void board_init(void)
msp430_init_dco(); msp430_init_dco();
/* initialize the STDIO */ /* initialize the STDIO */
msp430_stdio_init(); uart_stdio_init();
/* enable interrupts */ /* enable interrupts */
__bis_SR_register(GIE); __bis_SR_register(GIE);

View File

@ -13,7 +13,7 @@
#include "kernel_internal.h" #include "kernel_internal.h"
#include "msp430.h" #include "msp430.h"
#include "debug.h" #include "debug.h"
#include "msp430_stdio.h" #include "uart_stdio.h"
volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; 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); msp430_set_cpu_speed(MCLK_8MHZ_SCLK_8MHZ);
/* initialize the STDIO */ /* initialize the STDIO */
msp430_stdio_init(); uart_stdio_init();
} }

View File

@ -24,7 +24,7 @@
#include "cpu.h" #include "cpu.h"
#include "board.h" #include "board.h"
#include "msp430_stdio.h" #include "uart_stdio.h"
static void z1_ports_init(void) static void z1_ports_init(void)
{ {
@ -216,7 +216,7 @@ void board_init(void)
msp430_init_dco(); msp430_init_dco();
/* initialize STDIO */ /* initialize STDIO */
msp430_stdio_init(); uart_stdio_init();
/* enable interrupts */ /* enable interrupts */
__bis_SR_register(GIE); __bis_SR_register(GIE);

View File

@ -2,4 +2,4 @@ INCLUDES += -I$(RIOTCPU)/msp430fxyz/include/
include $(RIOTCPU)/msp430-common/Makefile.include include $(RIOTCPU)/msp430-common/Makefile.include
export USEMODULE += periph periph_common export USEMODULE += periph periph_common uart_stdio

View File

@ -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 <hauke.petersen@fu-berlin.de>
*/
#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 */
/** @} */

View File

@ -18,61 +18,16 @@
* @} * @}
*/ */
#include "irq.h" #include "uart_stdio.h"
#include "mutex.h"
#include "board.h"
#include "ringbuffer.h"
#include "periph/uart.h"
#include <stdio.h>
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);
}
/** /**
* @brief Get one character from STDIO - used by the libc * @brief Get one character from STDIO - used by the libc
*/ */
int getchar(void) int getchar(void)
{ {
int res = safe_read(); char c;
uart_stdio_read(&c, 1);
while (res == -1) { return c;
mutex_lock(&rx_lock);
res = safe_read();
}
return res;
} }
/** /**
@ -81,6 +36,7 @@ int getchar(void)
*/ */
int putchar(int c) int putchar(int c)
{ {
uart_write_blocking(STDIO, (char)c); char _c = c;
uart_stdio_write(&_c, 1);
return 1; return 1;
} }