Skip to content
Snippets Groups Projects
Commit 7b3d1a72 authored by Thomas Eichinger's avatar Thomas Eichinger
Browse files

Merge pull request #3924 from kaspar030/msp430fxyz_use_uart_stdio

cpu: make msp430fxyz use uart stdio
parents 5cf4bd66 d9414fda
Branches
No related tags found
No related merge requests found
......@@ -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();
}
......@@ -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);
......
......@@ -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();
}
......@@ -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);
......
......@@ -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
/*
* 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 */
/** @} */
......@@ -18,61 +18,16 @@
* @}
*/
#include "irq.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);
}
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment