1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-16 01:53:51 +01:00

atmega2560: remove uart0, adapt to uart_stdio

This commit is contained in:
Kaspar Schleiser 2015-06-09 13:09:28 +02:00
parent 076e9db374
commit 73e15bdde1
2 changed files with 11 additions and 62 deletions

View File

@ -23,25 +23,7 @@
#include "board.h"
#include "cpu.h"
#include "periph/uart.h"
#ifndef MODULE_UART0
#include "ringbuffer.h"
#include "mutex.h"
#endif
#ifdef MODULE_UART0
#include "board_uart0.h"
#endif
/**
* @brief use mutex for waiting on incoming UART chars
*/
#ifndef MODULE_UART0
static mutex_t uart_rx_mutex;
static char rx_buf_mem[STDIO_RX_BUFSIZE];
static ringbuffer_t rx_buf;
#endif
#include "uart_stdio.h"
void led_init(void);
void SystemInit(void);
@ -51,30 +33,6 @@ static int uart_getchar(FILE *stream);
static FILE uart_stdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
static FILE uart_stdin = FDEV_SETUP_STREAM(NULL, uart_getchar, _FDEV_SETUP_READ);
/**
* @brief Receive a new character from the UART and put it into the receive
* buffer
*
* @param[in] data the newly received byte
*/
void rx_cb(void *arg, char data)
{
LED_TOGGLE;
#ifndef MODULE_UART0
ringbuffer_add_one(&rx_buf, data);
mutex_unlock(&uart_rx_mutex);
#elif MODULE_UART0
if (uart0_handler_pid) {
uart0_handle_incoming(data);
uart0_notify_thread();
}
#endif
}
void board_init(void)
{
/* initialize stdio via USART_0 */
@ -111,11 +69,7 @@ void led_init(void)
void SystemInit(void)
{
/* initialize UART_0 for use as stdout */
#ifndef MODULE_UART0
mutex_init(&uart_rx_mutex);
ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_RX_BUFSIZE);
#endif
uart_init(STDIO, STDIO_BAUDRATE, (uart_rx_cb_t) rx_cb, NULL, NULL);
uart_stdio_init();
stdout = &uart_stdout;
stdin = &uart_stdin;
@ -126,23 +80,13 @@ void SystemInit(void)
static int uart_putchar(char c, FILE *stream)
{
uart_write_blocking(UART_0, c);
uart_stdio_write(&c, 1);
return 0;
}
int uart_getchar(FILE *stream)
{
#ifndef MODULE_UART0
if (rx_buf.avail == 0) {
mutex_lock(&uart_rx_mutex);
}
return ringbuffer_get_one(&rx_buf);
#else
LED_TOGGLE;
char temp;
temp = (char) uart0_readc();
return temp;
#endif
char c;
uart_stdio_read(&c, 1);
return (int)c;
}

View File

@ -3,11 +3,16 @@ export CFLAGS += -DCOREIF_NG=1
# tell the build system that the CPU depends on the atmega common files
USEMODULE += atmega_common
# use hwtimer compatibility module
USEMODULE += hwtimer_compat
# export the peripheral drivers to be linked into the final binary
export USEMODULE += periph
# the atmel port uses uart_stdio
export USEMODULE += uart_stdio
# define path to atmega common module, which is needed for this CPU
export ATMEGA_COMMON = $(RIOTCPU)/atmega_common/