1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #8837 from kaspar030/refactor_atmega_stdio

cpu/atmega: refactor stdio init code
This commit is contained in:
Francisco Acosta 2018-04-03 15:56:33 +03:00 committed by GitHub
commit 69f4d632e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 201 additions and 302 deletions

View File

@ -1,3 +1,5 @@
MODULE = boards_common_arduino-atmega
DIRS = $(RIOTBOARD)/common/atmega
include $(RIOTBASE)/Makefile.base

View File

@ -1,3 +1,5 @@
USEMODULE += boards_common_atmega
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif

View File

@ -1,84 +0,0 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 Laurent Navet <laurent.navet@gmail.com>
*
* 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 boards_common_arduino-atmega
* @{
*
* @file
* @brief Common implementations for Arduino Atmega boards
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Laurent Navet <laurent.navet@gmail.com>
*
* @}
*/
#include <stdio.h>
#include <avr/io.h>
#include "board.h"
#include "cpu.h"
#include "uart_stdio.h"
#include "periph/gpio.h"
void led_init(void);
void SystemInit(void);
static int uart_putchar(char c, FILE *stream);
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);
void board_init(void)
{
/* initialize stdio via USART_0 */
SystemInit();
/* initialize the CPU */
cpu_init();
/* initialize the board LED */
gpio_init(LED0_PIN, GPIO_OUT);
LED0_OFF;
irq_enable();
}
/**
* @brief Initialize the System, initialize IO via UART_0
*/
void SystemInit(void)
{
/* initialize UART_0 for use as stdout */
uart_stdio_init();
stdout = &uart_stdout;
stdin = &uart_stdin;
/* Flush stdout */
puts("\f");
}
static int uart_putchar(char c, FILE *stream)
{
(void) stream;
uart_stdio_write(&c, 1);
return 0;
}
int uart_getchar(FILE *stream)
{
(void) stream;
char c;
uart_stdio_read(&c, 1);
return (int)c;
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2015-18 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 Laurent Navet <laurent.navet@gmail.com>
*
* 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 boards_common_arduino-atmega
* @{
*
* @file
* @brief Common led initialization for Arduino Atmega boards
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Laurent Navet <laurent.navet@gmail.com>
*
* @}
*/
#include "board.h"
#include "cpu.h"
#include "periph/gpio.h"
void led_init(void)
{
/* initialize the on-board LED */
gpio_init(LED0_PIN, GPIO_OUT);
LED0_OFF;
}

View File

@ -0,0 +1,3 @@
MODULE = boards_common_atmega
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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 boards_common_atmega
* @{
*
* @file
* @brief Common implementations for Atmega boards
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include "board.h"
#include "cpu.h"
#include "irq.h"
#include "periph/gpio.h"
void led_init(void);
void board_init(void)
{
atmega_stdio_init();
cpu_init();
led_init();
irq_enable();
}

View File

@ -1,3 +1,5 @@
MODULE = board
DIRS = $(RIOTBOARD)/common/atmega
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1 @@
USEMODULE += boards_common_atmega

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 RWTH Aachen, Josua Arndt
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 RWTH Aachen, Josua Arndt
*
* 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
@ -11,70 +12,22 @@
* @{
*
* @file
* @brief Board specific implementations for the Jiminy Mega 256rfr2 board
* developed by the IAS of the RWTH Aachen University
* @brief Board specific LED initialization
*
* @author Josua Arndt <jarndt@ias.rwth-aachen.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include "board.h"
#include <stdio.h>
#include <avr/io.h>
#include "cpu.h"
#include "uart_stdio.h"
void SystemInit(void);
static int uart_putchar(char c, FILE *stream);
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);
void board_init(void)
void led_init(void)
{
/* initialize stdio via USART_0 */
SystemInit();
/* initialize the CPU */
cpu_init();
/* initialize the board LED (connected to pin PB7) */
/* Ports Pins as Output */
LED_PORT_DDR |= LED2_MASK | LED1_MASK | LED0_MASK;
/* All Pins Low so LEDs are off */
LED_PORT &= ~(LED2_MASK | LED1_MASK | LED0_MASK);
irq_enable();
}
/*Initialize the System, initialize IO via UART_0*/
void SystemInit(void)
{
/* initialize UART_0 for use as stdout */
uart_stdio_init();
stdout = &uart_stdout;
stdin = &uart_stdin;
/* Flush stdout */
puts("\f");
}
static int uart_putchar(char c, FILE *stream)
{
(void) stream;
uart_stdio_write(&c, 1);
return 0;
}
int uart_getchar(FILE *stream)
{
(void) stream;
char c;
uart_stdio_read(&c, 1);
return (int)c;
}

View File

@ -1,3 +1,5 @@
MODULE = board
DIRS = $(RIOTBOARD)/common/atmega
include $(RIOTBASE)/Makefile.base

View File

@ -1,3 +1,5 @@
USEMODULE += boards_common_atmega
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_adc
USEMODULE += saul_gpio

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 Laurent Navet <laurent.navet@gmail.com>
* 2018 Matthew Blue <matthew.blue.neuro@gmail.com>
*
* 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 boards_mega-xplained
* @{
*
* @file
* @brief Board specific implementation for the Mega Xplained
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Laurent Navet <laurent.navet@gmail.com>
* @author Matthew Blue <matthew.blu.neuro@gmail.com>
*
* @}
*/
#include <stdio.h>
#include <avr/io.h>
#include "board.h"
#include "cpu.h"
#include "uart_stdio.h"
#include "periph/gpio.h"
void SystemInit(void);
static int uart_putchar(char c, FILE *stream);
static int uart_getchar(FILE *stream);
static void led_init(void);
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);
void board_init(void)
{
/* initialize stdio via USART_1 */
SystemInit();
/* initialize the CPU */
cpu_init();
/* initialize the LEDs */
led_init();
irq_enable();
}
/**
* @brief Initialize the System, initialize IO via UART_1
*/
void SystemInit(void)
{
/* initialize UART_1 for use as stdout */
uart_stdio_init();
stdout = &uart_stdout;
stdin = &uart_stdin;
/* Flush stdout */
puts("\f");
}
static int uart_putchar(char c, FILE *stream)
{
(void) stream;
uart_stdio_write(&c, 1);
return 0;
}
int uart_getchar(FILE *stream)
{
(void) stream;
char c;
uart_stdio_read(&c, 1);
return (int)c;
}
/**
* @brief Initialize the on-board LEDs
*/
void led_init(void)
{
/* LED0,2 currently unsupported due to lack of GPIO_OD support */
LED1_ENABLE_PORT;
LED1_OFF;
LED3_ENABLE_PORT;
LED3_OFF;
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2015-18 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 Laurent Navet <laurent.navet@gmail.com>
* 2018 Matthew Blue <matthew.blue.neuro@gmail.com>
*
* 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 boards_mega-xplained
* @{
*
* @file
* @brief Board specific implementation for the Mega Xplained
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Laurent Navet <laurent.navet@gmail.com>
* @author Matthew Blue <matthew.blu.neuro@gmail.com>
*
* @}
*/
#include "board.h"
void led_init(void)
{
/* LED0,2 currently unsupported due to lack of GPIO_OD support */
LED1_ENABLE_PORT;
LED1_OFF;
LED3_ENABLE_PORT;
LED3_OFF;
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2015-18 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 INRIA, Francisco Acosta
*
* This file is subject to the terms and conditions of the GNU Lesser
@ -13,7 +13,7 @@
* @{
*
* @file
* @brief Board specific implementations for the Waspmote PRO v1.2 board
* @brief Board specific initializations
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
@ -22,48 +22,8 @@
* @}
*/
#include <stdio.h>
#include <avr/io.h>
#include "board.h"
#include "cpu.h"
#include "uart_stdio.h"
void led_init(void);
void SystemInit(void);
static int uart_putchar(char c, FILE *stream);
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);
void board_init(void)
{
/* initialize UART_1 on AUX1 */
SET_MUX_AUX1_MODULE;
#ifdef XBEE_UART
#if XBEE_UART == 0
/* initialize UART0 on SOCKET0 (XBee) */
SET_MUX_SOCKET0;
#else
/* Initialize UART0 on USB */
SET_MUX_USB_MODULE;
#endif
#endif
/* initialize stdio via UART_STDIO_DEV */
SystemInit();
/* initialize the CPU */
cpu_init();
/* initialize the boards LEDs */
led_init();
irq_enable();
}
/**
* @brief Initialize the boards on-board LEDs (green and red)
@ -83,32 +43,23 @@ void led_init(void)
LED_RED_ON;
}
/**
* @brief Initialize the System, initialize IO via UART_0
*/
void SystemInit(void)
void board_init(void)
{
/* initialize UART_0 for use as stdout */
uart_stdio_init();
/* initialize UART_1 on AUX1 */
SET_MUX_AUX1_MODULE;
stdout = &uart_stdout;
stdin = &uart_stdin;
#ifdef XBEE_UART
#if XBEE_UART == 0
/* initialize UART0 on SOCKET0 (XBee) */
SET_MUX_SOCKET0;
#else
/* Initialize UART0 on USB */
SET_MUX_USB_MODULE;
#endif
#endif
/* Flush stdout */
puts("\f");
}
static int uart_putchar(char c, FILE *stream)
{
(void) stream;
uart_stdio_write(&c, 1);
return 0;
}
int uart_getchar(FILE *stream)
{
(void) stream;
char c;
uart_stdio_read(&c, 1);
return (int)c;
atmega_stdio_init();
cpu_init();
led_init();
irq_enable();
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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.
*/
/**
* @{
*
* @file
* @brief Implements common atmega libc stdio initialization
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stdio.h>
#include <avr/io.h>
#include "uart_stdio.h"
static int _uart_putchar(char c, FILE *stream);
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);
static int _uart_putchar(char c, FILE *stream)
{
(void) stream;
uart_stdio_write(&c, 1);
return 0;
}
static int _uart_getchar(FILE *stream)
{
(void) stream;
char c;
uart_stdio_read(&c, 1);
return (int)c;
}
void atmega_stdio_init(void)
{
uart_stdio_init();
stdout = &_uart_stdout;
stdin = &_uart_stdin;
/* Flush stdout */
puts("\f");
}

View File

@ -97,6 +97,11 @@ static inline void cpu_print_last_instruction(void)
printf("Stack Pointer: 0x%04x\n", ptr);
}
/**
* @brief Initializes avrlibc stdio
*/
void atmega_stdio_init(void);
#ifdef __cplusplus
}
#endif