From 391cc838816a083952db519ce86af35023048140 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 26 Mar 2018 21:46:12 +0200 Subject: [PATCH 1/6] cpu/atmega_common: provide common stdio initialization --- cpu/atmega_common/atmega_stdio.c | 53 ++++++++++++++++++++++++++++++++ cpu/atmega_common/include/cpu.h | 5 +++ 2 files changed, 58 insertions(+) create mode 100644 cpu/atmega_common/atmega_stdio.c diff --git a/cpu/atmega_common/atmega_stdio.c b/cpu/atmega_common/atmega_stdio.c new file mode 100644 index 0000000000..f069a56b42 --- /dev/null +++ b/cpu/atmega_common/atmega_stdio.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 Kaspar Schleiser + * + * 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 + * + * @} + */ +#include +#include + +#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"); +} diff --git a/cpu/atmega_common/include/cpu.h b/cpu/atmega_common/include/cpu.h index b01b43daa6..dcffda63d1 100644 --- a/cpu/atmega_common/include/cpu.h +++ b/cpu/atmega_common/include/cpu.h @@ -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 From 64791d0c82b12e5c5f628adbd89ddfebdc31a1dd Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 26 Mar 2018 21:48:40 +0200 Subject: [PATCH 2/6] boards/waspmote-pro: make use of common stdio init code --- boards/waspmote-pro/board.c | 85 ++++++++----------------------------- 1 file changed, 18 insertions(+), 67 deletions(-) diff --git a/boards/waspmote-pro/board.c b/boards/waspmote-pro/board.c index f3b02c0164..36b121046d 100644 --- a/boards/waspmote-pro/board.c +++ b/boards/waspmote-pro/board.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen - * 2015 Kaspar Schleiser + * 2015-18 Kaspar Schleiser * 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 * @author Kaspar Schleiser @@ -22,48 +22,8 @@ * @} */ -#include -#include - #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(); } From ae8822ff46526cb60f8beb7409af7797ed6e0856 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 26 Mar 2018 21:50:06 +0200 Subject: [PATCH 3/6] boards/common/atmega: initial commit of atmega shared code --- boards/common/atmega/Makefile | 3 +++ boards/common/atmega/board.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 boards/common/atmega/Makefile create mode 100644 boards/common/atmega/board.c diff --git a/boards/common/atmega/Makefile b/boards/common/atmega/Makefile new file mode 100644 index 0000000000..3acb699f05 --- /dev/null +++ b/boards/common/atmega/Makefile @@ -0,0 +1,3 @@ +MODULE = boards_common_atmega + +include $(RIOTBASE)/Makefile.base diff --git a/boards/common/atmega/board.c b/boards/common/atmega/board.c new file mode 100644 index 0000000000..ef349c737f --- /dev/null +++ b/boards/common/atmega/board.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2018 Kaspar Schleiser + * + * 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 + * + * @} + */ + +#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(); +} From 60a55eb06d7da85cdeaee509706c7a3d47b7e126 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 26 Mar 2018 21:51:15 +0200 Subject: [PATCH 4/6] boards/common/arduino-atmega: use common/atmega shared code --- boards/common/arduino-atmega/Makefile | 2 + boards/common/arduino-atmega/Makefile.dep | 2 + boards/common/arduino-atmega/board.c | 84 ----------------------- boards/common/arduino-atmega/led_init.c | 34 +++++++++ 4 files changed, 38 insertions(+), 84 deletions(-) delete mode 100644 boards/common/arduino-atmega/board.c create mode 100644 boards/common/arduino-atmega/led_init.c diff --git a/boards/common/arduino-atmega/Makefile b/boards/common/arduino-atmega/Makefile index 8cf36dd246..69ed81c430 100644 --- a/boards/common/arduino-atmega/Makefile +++ b/boards/common/arduino-atmega/Makefile @@ -1,3 +1,5 @@ MODULE = boards_common_arduino-atmega +DIRS = $(RIOTBOARD)/common/atmega + include $(RIOTBASE)/Makefile.base diff --git a/boards/common/arduino-atmega/Makefile.dep b/boards/common/arduino-atmega/Makefile.dep index 5472bf8b8d..13ba4563c8 100644 --- a/boards/common/arduino-atmega/Makefile.dep +++ b/boards/common/arduino-atmega/Makefile.dep @@ -1,3 +1,5 @@ +USEMODULE += boards_common_atmega + ifneq (,$(filter saul_default,$(USEMODULE))) USEMODULE += saul_gpio endif diff --git a/boards/common/arduino-atmega/board.c b/boards/common/arduino-atmega/board.c deleted file mode 100644 index 33afa0e9b3..0000000000 --- a/boards/common/arduino-atmega/board.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen - * 2015 Kaspar Schleiser - * 2016 Laurent Navet - * - * 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 - * @author Kaspar Schleiser - * @author Laurent Navet - * - * @} - */ - -#include -#include - -#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; -} diff --git a/boards/common/arduino-atmega/led_init.c b/boards/common/arduino-atmega/led_init.c new file mode 100644 index 0000000000..a74649a13e --- /dev/null +++ b/boards/common/arduino-atmega/led_init.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 2015-18 Kaspar Schleiser + * 2016 Laurent Navet + * + * 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 + * @author Kaspar Schleiser + * @author Laurent Navet + * + * @} + */ + +#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; +} From 9c18e62364f44d7805e88c64d45d8a4c381cf6ce Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 26 Mar 2018 21:51:52 +0200 Subject: [PATCH 5/6] boards/jiminy-mega256rfr2: make use of common/atmega --- boards/jiminy-mega256rfr2/Makefile | 2 + boards/jiminy-mega256rfr2/Makefile.dep | 1 + boards/jiminy-mega256rfr2/board.c | 57 +++----------------------- 3 files changed, 8 insertions(+), 52 deletions(-) create mode 100644 boards/jiminy-mega256rfr2/Makefile.dep diff --git a/boards/jiminy-mega256rfr2/Makefile b/boards/jiminy-mega256rfr2/Makefile index f8fcbb53a0..3134740b39 100644 --- a/boards/jiminy-mega256rfr2/Makefile +++ b/boards/jiminy-mega256rfr2/Makefile @@ -1,3 +1,5 @@ MODULE = board +DIRS = $(RIOTBOARD)/common/atmega + include $(RIOTBASE)/Makefile.base diff --git a/boards/jiminy-mega256rfr2/Makefile.dep b/boards/jiminy-mega256rfr2/Makefile.dep new file mode 100644 index 0000000000..3d1c295b9b --- /dev/null +++ b/boards/jiminy-mega256rfr2/Makefile.dep @@ -0,0 +1 @@ +USEMODULE += boards_common_atmega diff --git a/boards/jiminy-mega256rfr2/board.c b/boards/jiminy-mega256rfr2/board.c index 193385591e..9890a7fec7 100644 --- a/boards/jiminy-mega256rfr2/board.c +++ b/boards/jiminy-mega256rfr2/board.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2016 RWTH Aachen, Josua Arndt + * Copyright (C) 2018 Kaspar Schleiser + * 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 + * @author Kaspar Schleiser * * @} */ #include "board.h" - -#include -#include - #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; } From ff0e76a5a1797ad56d197e77477c727b421166f4 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 27 Mar 2018 10:58:02 +0200 Subject: [PATCH 6/6] boards/mega-xplained: use boards_common_atmega --- boards/mega-xplained/Makefile | 2 + boards/mega-xplained/Makefile.dep | 2 + boards/mega-xplained/board.c | 99 ------------------------------- boards/mega-xplained/led_init.c | 38 ++++++++++++ 4 files changed, 42 insertions(+), 99 deletions(-) delete mode 100644 boards/mega-xplained/board.c create mode 100644 boards/mega-xplained/led_init.c diff --git a/boards/mega-xplained/Makefile b/boards/mega-xplained/Makefile index f8fcbb53a0..3134740b39 100644 --- a/boards/mega-xplained/Makefile +++ b/boards/mega-xplained/Makefile @@ -1,3 +1,5 @@ MODULE = board +DIRS = $(RIOTBOARD)/common/atmega + include $(RIOTBASE)/Makefile.base diff --git a/boards/mega-xplained/Makefile.dep b/boards/mega-xplained/Makefile.dep index 0688b61ce6..81bcc4c147 100644 --- a/boards/mega-xplained/Makefile.dep +++ b/boards/mega-xplained/Makefile.dep @@ -1,3 +1,5 @@ +USEMODULE += boards_common_atmega + ifneq (,$(filter saul_default,$(USEMODULE))) USEMODULE += saul_adc USEMODULE += saul_gpio diff --git a/boards/mega-xplained/board.c b/boards/mega-xplained/board.c deleted file mode 100644 index fe5d2a9ae9..0000000000 --- a/boards/mega-xplained/board.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen - * 2015 Kaspar Schleiser - * 2016 Laurent Navet - * 2018 Matthew Blue - * - * 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 - * @author Kaspar Schleiser - * @author Laurent Navet - * @author Matthew Blue - * - * @} - */ - -#include -#include - -#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; -} diff --git a/boards/mega-xplained/led_init.c b/boards/mega-xplained/led_init.c new file mode 100644 index 0000000000..a45924cc08 --- /dev/null +++ b/boards/mega-xplained/led_init.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 2015-18 Kaspar Schleiser + * 2016 Laurent Navet + * 2018 Matthew Blue + * + * 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 + * @author Kaspar Schleiser + * @author Laurent Navet + * @author Matthew Blue + * + * @} + */ + +#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; +}