diff --git a/boards/arduino-common/Makefile b/boards/arduino-common/Makefile new file mode 100644 index 0000000000..233ad5878b --- /dev/null +++ b/boards/arduino-common/Makefile @@ -0,0 +1,3 @@ +MODULE = arduino-common + +include $(RIOTBASE)/Makefile.base diff --git a/boards/arduino-common/Makefile.features b/boards/arduino-common/Makefile.features new file mode 100644 index 0000000000..8131d940b2 --- /dev/null +++ b/boards/arduino-common/Makefile.features @@ -0,0 +1,10 @@ +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_gpio +FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_timer +FEATURES_PROVIDED += periph_uart + +# Various other features (if any) + +# The board MPU family (used for grouping by the CI system) +FEATURES_MCU_GROUP = avr8 diff --git a/boards/arduino-common/Makefile.include b/boards/arduino-common/Makefile.include new file mode 100644 index 0000000000..3b357838c7 --- /dev/null +++ b/boards/arduino-common/Makefile.include @@ -0,0 +1,44 @@ +# define the cpu used by the arduino uno and duemilanove boards +export CPU = atmega328p + +# define port used to flash the board +OS = $(shell uname) +ifeq ($(OS),Linux) + PORT = $(LINUX_PORT) +else ifeq ($(OS),Darwin) + PORT ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) +else + $(info CAUTION: No flash tool for your host system found!) + # TODO: fix for building under windows +endif + +export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm +export TERMFLAGS = -b 9600 -p $(PORT) +export FLASHER = avrdude +export PORT +export DIST_PATH = $(RIOTBOARD)/$(BOARD)/dist +export DEBUGSERVER_PORT = 4242 +export DEBUGSERVER = $(DIST_PATH)/debug_srv.sh +export DEBUGSERVER_FLAGS = "-g -j usb :$(DEBUGSERVER_PORT)" +export DEBUGGER_FLAGS = "-x $(RIOTBOARD)/$(BOARD)/dist/gdb.conf $(ELFFILE)" +export DEBUGGER = $(DIST_PATH)/debug.sh $(DEBUGSERVER_FLAGS) $(DIST_PATH) $(DEBUGSERVER_PORT) + +# PROGRAMMER defaults to arduino which is the internal flasher via USB. Can be +# overridden for debugging (which requires changes that require to use an ISP) +export PROGRAMMER ?= arduino + +ifeq ($(PROGRAMMER), arduino) + export PROGRAMMER_FLAGS = -P $(PORT) -b $(PROGRAMMER_SPEED) +endif + +# define build specific options +export CFLAGS_CPU = -mmcu=atmega328p $(CFLAGS_FPU) +export CFLAGS_LINK = -ffunction-sections -fdata-sections -fno-builtin -fshort-enums +export CFLAGS_DBG = -ggdb -g3 +export CFLAGS_OPT ?= -Os + +export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) +export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) +export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -static -lgcc -e reset_handler +export OFLAGS += -j .text -j .data -O ihex +export FFLAGS += -p atmega328p -c $(PROGRAMMER) $(PROGRAMMER_FLAGS) -F -D -U flash:w:bin/$(BOARD)/$(PROJECT)$(APPLICATION).hex diff --git a/boards/arduino-common/board.c b/boards/arduino-common/board.c new file mode 100644 index 0000000000..abca37ac28 --- /dev/null +++ b/boards/arduino-common/board.c @@ -0,0 +1,84 @@ +/* + * 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_arduino-common + * @{ + * + * @file + * @brief Board specific implementations for the arduino Uno + * @brief and Duemilanove boards. + * + * @author Hinnerk van Bruinehsen + * @author Kaspar Schleiser + * @author Laurent Navet + * + * @} + */ + +#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 stdio via USART_0 */ + SystemInit(); + + /* initialize the CPU */ + cpu_init(); + + /* initialize the board LED (connected to pin PB5) */ + DDRB |= (1 << DDB5); + PORTB &= ~(1 << 5); + + 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/arduino-common/dist/debug.sh b/boards/arduino-common/dist/debug.sh new file mode 100755 index 0000000000..0b10852f20 --- /dev/null +++ b/boards/arduino-common/dist/debug.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +sleep 2 +setsid -w avarice $1 & +#sleep 2 && $2/avr-gdb-wrapper -ex "target remote localhost:$3" $4 +sleep 3 && avr-gdb -ex "target remote localhost:$3" $4 + +# avarice exits with 1 if the connection is released, therefore we always exit with 0 +exit 0 diff --git a/boards/arduino-common/dist/debug_srv.sh b/boards/arduino-common/dist/debug_srv.sh new file mode 100755 index 0000000000..8e7de053ab --- /dev/null +++ b/boards/arduino-common/dist/debug_srv.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +sleep 2 +avarice $1 + +# avarice exits with 1 if the connection is released, therefore we always exit with 0 +exit 0 diff --git a/boards/arduino-common/dist/gdb.conf b/boards/arduino-common/dist/gdb.conf new file mode 100644 index 0000000000..ca68eb344c --- /dev/null +++ b/boards/arduino-common/dist/gdb.conf @@ -0,0 +1 @@ +set $pc=0x00 diff --git a/boards/arduino-common/include/arduino_board.h b/boards/arduino-common/include/arduino_board.h new file mode 100644 index 0000000000..e589511d36 --- /dev/null +++ b/boards/arduino-common/include/arduino_board.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 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 boards_arduino-common + * @{ + * + * @file + * @brief Board specific configuration for the Arduino API + * + * @author Hauke Petersen + * @author Laurent Navet + */ + +#ifndef ARDUINO_BOARD_H +#define ARDUINO_BOARD_H + +#include "arduino_pinmap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The on-board LED is connected to pin 13 on this board + */ +#define ARDUINO_LED (13) + +/** + * @brief Look-up table for the Arduino's digital pins + */ +static const gpio_t arduino_pinmap[] = { + ARDUINO_PIN_0, + ARDUINO_PIN_1, + ARDUINO_PIN_2, + ARDUINO_PIN_3, + ARDUINO_PIN_4, + ARDUINO_PIN_5, + ARDUINO_PIN_6, + ARDUINO_PIN_7, + ARDUINO_PIN_8, + ARDUINO_PIN_9, + ARDUINO_PIN_10, + ARDUINO_PIN_11, + ARDUINO_PIN_12, + ARDUINO_PIN_13, + ARDUINO_PIN_14, + ARDUINO_PIN_15, + ARDUINO_PIN_16, + ARDUINO_PIN_17, + ARDUINO_PIN_18, + ARDUINO_PIN_19 +}; + +#ifdef __cplusplus +} +#endif + +#endif /* ARDUINO_BOARD_H */ +/** @} */ diff --git a/boards/arduino-common/include/arduino_pinmap.h b/boards/arduino-common/include/arduino_pinmap.h new file mode 100644 index 0000000000..67e4067714 --- /dev/null +++ b/boards/arduino-common/include/arduino_pinmap.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * 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_arduino-common + * @{ + * + * @file + * @brief Mapping from MCU pins to Arduino pins + * + * You can use the defines in this file for simplified interaction with the + * Arduino specific pin numbers. + * + * @author Hauke Petersen + * @author Daniel Nordahl + * @author Laurent Navet + */ + +#ifndef ARDUINO_PINMAP_H +#define ARDUINO_PINMAP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Mapping of MCU pins to Arduino pins + * + * @note ISCP pins are not mapped. + */ + +/* Digital pins */ +#define ARDUINO_PIN_0 GPIO_PIN(PORT_D, 0) +#define ARDUINO_PIN_1 GPIO_PIN(PORT_D, 1) +#define ARDUINO_PIN_2 GPIO_PIN(PORT_D, 2) +#define ARDUINO_PIN_3 GPIO_PIN(PORT_D, 3) +#define ARDUINO_PIN_4 GPIO_PIN(PORT_D, 4) +#define ARDUINO_PIN_5 GPIO_PIN(PORT_D, 5) +#define ARDUINO_PIN_6 GPIO_PIN(PORT_D, 6) +#define ARDUINO_PIN_7 GPIO_PIN(PORT_D, 7) +#define ARDUINO_PIN_8 GPIO_PIN(PORT_B, 0) +#define ARDUINO_PIN_9 GPIO_PIN(PORT_B, 1) +#define ARDUINO_PIN_10 GPIO_PIN(PORT_B, 2) +#define ARDUINO_PIN_11 GPIO_PIN(PORT_B, 3) +#define ARDUINO_PIN_12 GPIO_PIN(PORT_B, 4) +#define ARDUINO_PIN_13 GPIO_PIN(PORT_B, 5) +/* Analog pins */ +#define ARDUINO_PIN_14 GPIO_PIN(PORT_C, 0) +#define ARDUINO_PIN_15 GPIO_PIN(PORT_C, 1) +#define ARDUINO_PIN_16 GPIO_PIN(PORT_C, 2) +#define ARDUINO_PIN_17 GPIO_PIN(PORT_C, 3) +#define ARDUINO_PIN_18 GPIO_PIN(PORT_C, 4) +#define ARDUINO_PIN_19 GPIO_PIN(PORT_C, 5) +/* Analog input */ +#define ARDUINO_PIN_A0 ARDUINO_PIN_14 +#define ARDUINO_PIN_A1 ARDUINO_PIN_15 +#define ARDUINO_PIN_A2 ARDUINO_PIN_16 +#define ARDUINO_PIN_A3 ARDUINO_PIN_17 +#define ARDUINO_PIN_A4 ARDUINO_PIN_18 +#define ARDUINO_PIN_A5 ARDUINO_PIN_19 +/** @ */ + +#ifdef __cplusplus +} +#endif + +#endif /* ARDUINO_PINMAP_H */ +/** @} */ diff --git a/boards/arduino-common/include/board.h b/boards/arduino-common/include/board.h new file mode 100644 index 0000000000..fe84d1d286 --- /dev/null +++ b/boards/arduino-common/include/board.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 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. + */ + +/** + * @defgroup boards_arduino-common Arduino common + * @ingroup boards + * @brief Board specific files for the arduino Uno and + * @brief Duemilanove boards. + * @{ + * + * @file + * @brief Board specific definitions for the arduino Uno and + * @brief Duemilanove boards. + * + * @author Hinnerk van Bruinehsen + * @author Laurent Navet + */ + +#ifndef BOARD_H_ +#define BOARD_H_ + +#include "cpu.h" +#include "arduino_pinmap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief As the CPU is too slow to handle 115200 baud, we set the default + * baudrate to 9600 for this board + * @{ + */ +#define UART_STDIO_BAUDRATE (9600U) +/** @} */ + +/** + * @brief LED pin definitions and handlers + * @{ + */ +#define LED0_PIN GPIO_PIN(1, 5) + +#define LED0_MASK (1 << DDB5) + +#define LED0_ON (PORTB |= LED0_MASK) +#define LED0_OFF (PORTB &= ~LED0_MASK) +#define LED0_TOGGLE (PORTB ^= LED0_MASK) +/** @} */ + +/** + ** Context swap defines + ** Setup to use PJ6 which is pin change interrupt 15 (PCINT15) + ** This emulates a software triggered interrupt + ***/ +#define AVR_CONTEXT_SWAP_INIT do { \ + DDRC |= (1 << PC6); \ + PCICR |= (1 << PCIE1); \ + PCMSK1 |= (1 << PCINT14); \ +} while (0) +#define AVR_CONTEXT_SWAP_INTERRUPT_VECT PCINT1_vect +#define AVR_CONTEXT_SWAP_TRIGGER PORTC ^= (1 << PC6) + + +/** + * @brief xtimer configuration values + * @{ + */ +#define XTIMER_WIDTH (16) +#define XTIMER_SHIFT (2) +#define XTIMER_BACKOFF (40) +/** @} */ + +/** + * @brief Initialize board specific hardware, including clock, LEDs and std-IO + */ +void board_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H_ */ +/** @} */ diff --git a/boards/arduino-common/include/periph_conf.h b/boards/arduino-common/include/periph_conf.h new file mode 100644 index 0000000000..750fb69cdf --- /dev/null +++ b/boards/arduino-common/include/periph_conf.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 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_arduino-common + * @{ + * + * @file + * @brief Peripheral MCU configuration for the arduino Uno and + * @brief Dumilanove boards. + * + * @author Hinnerk van Bruinehsen + * @author Laurent Navet + */ + +#ifndef PERIPH_CONF_H_ +#define PERIPH_CONF_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Clock configuration + * @{ + */ +#define CLOCK_CORECLOCK (16000000L) +/** @} */ + +/** + * @brief Timer configuration + * + * The timer driver only supports the 16-bit timer (Timer1) + * so this is the only one we can use here. + * + * @{ + */ +#define TIMER_NUMOF (2U) + +#define TIMER_0 MEGA_TIMER1 +#define TIMER_0_MASK &TIMSK1 +#define TIMER_0_FLAG &TIFR1 +#define TIMER_0_ISRA TIMER1_COMPA_vect +#define TIMER_0_ISRB TIMER1_COMPB_vect +/** @} */ + +/** + * @brief UART configuration + * + * Uno has only one UART, look in atmega_common + * This is where magic happens + * + * @{ + */ +#define UART_NUMOF (1U) + +#define UART_0 MEGA_UART0 +#define UART_0_ISR USART_RX_vect +/** @} */ + +/** + * @brief SPI configuration + * + * The atmega2560 has only one hardware SPI with fixed pin configuration, so all + * we can do here, is to enable or disable it... + * + * The fixed pins used, are: + * MOSI - PB3 (Arduino pin 11) + * MISO - PB4 (Arduino pin 12) + * SCK - PB5 (Arduino pin 13) + * SS - PB2 (Arduino pin 10) -> this pin is configured as output, but not used + * + * @{ + */ +#define SPI_NUMOF 1 /* set to 0 to disable SPI */ +#define SPI_0_EN 1 /* remove once SPI rework is done */ +#define MEGA_PRR PRR /* Power Reduction Register is PRR */ +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CONF_H_ */ diff --git a/boards/arduino-duemilanove/Makefile b/boards/arduino-duemilanove/Makefile new file mode 100644 index 0000000000..070aba9f1a --- /dev/null +++ b/boards/arduino-duemilanove/Makefile @@ -0,0 +1,5 @@ +MODULE = board + +DIRS = $(RIOTBOARD)/arduino-common + +include $(RIOTBASE)/Makefile.base diff --git a/boards/arduino-duemilanove/Makefile.features b/boards/arduino-duemilanove/Makefile.features new file mode 100644 index 0000000000..da28e25dba --- /dev/null +++ b/boards/arduino-duemilanove/Makefile.features @@ -0,0 +1 @@ +include $(RIOTBOARD)/arduino-common/Makefile.features diff --git a/boards/arduino-duemilanove/Makefile.include b/boards/arduino-duemilanove/Makefile.include new file mode 100644 index 0000000000..e8e3236dbc --- /dev/null +++ b/boards/arduino-duemilanove/Makefile.include @@ -0,0 +1,10 @@ +USEMODULE += arduino-common + +# add arduino-common include path +INCLUDES += -I$(RIOTBOARD)/arduino-common/include + +#export needed for flash rule +export LINUX_PORT = /dev/ttyUSB0 +export PROGRAMMER_SPEED = 57600 + +include $(RIOTBOARD)/arduino-common/Makefile.include diff --git a/boards/arduino-uno/Makefile b/boards/arduino-uno/Makefile new file mode 100644 index 0000000000..070aba9f1a --- /dev/null +++ b/boards/arduino-uno/Makefile @@ -0,0 +1,5 @@ +MODULE = board + +DIRS = $(RIOTBOARD)/arduino-common + +include $(RIOTBASE)/Makefile.base diff --git a/boards/arduino-uno/Makefile.features b/boards/arduino-uno/Makefile.features new file mode 100644 index 0000000000..da28e25dba --- /dev/null +++ b/boards/arduino-uno/Makefile.features @@ -0,0 +1 @@ +include $(RIOTBOARD)/arduino-common/Makefile.features diff --git a/boards/arduino-uno/Makefile.include b/boards/arduino-uno/Makefile.include new file mode 100644 index 0000000000..f2d017c519 --- /dev/null +++ b/boards/arduino-uno/Makefile.include @@ -0,0 +1,10 @@ +USEMODULE += arduino-common + +# add arduino-common include path +INCLUDES += -I$(RIOTBOARD)/arduino-common/include + +# export needed for flash rule +export LINUX_PORT = /dev/ttyACM0 +export PROGRAMMER_SPEED = 115200 + +include $(RIOTBOARD)/arduino-common/Makefile.include diff --git a/cpu/atmega328p/Makefile b/cpu/atmega328p/Makefile new file mode 100644 index 0000000000..81f110b68d --- /dev/null +++ b/cpu/atmega328p/Makefile @@ -0,0 +1,6 @@ +# define the module that is build +MODULE = cpu +# add a list of subdirectories, that should also be build +DIRS = $(ATMEGA_COMMON) + +include $(RIOTBASE)/Makefile.base diff --git a/cpu/atmega328p/Makefile.include b/cpu/atmega328p/Makefile.include new file mode 100644 index 0000000000..a952b7caef --- /dev/null +++ b/cpu/atmega328p/Makefile.include @@ -0,0 +1,11 @@ +# this CPU implementation is using the new core/CPU interface +export CFLAGS += -DCOREIF_NG=1 + +# tell the build system that the CPU depends on the atmega common files +USEMODULE += atmega_common + +# define path to atmega common module, which is needed for this CPU +export ATMEGA_COMMON = $(RIOTCPU)/atmega_common/ + +# CPU depends on the atmega common module, so include it +include $(ATMEGA_COMMON)Makefile.include diff --git a/cpu/atmega328p/cpu.c b/cpu/atmega328p/cpu.c new file mode 100644 index 0000000000..3de168ab4f --- /dev/null +++ b/cpu/atmega328p/cpu.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * + * 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_atmega328p + * @{ + * + * @file + * @brief Implementation of the CPU initialization + * + * @author Hinnerk van Bruinehsen + * @} + */ + +#include "cpu.h" + +/** + * @brief Initialize the CPU, set IRQ priorities + */ +void cpu_init(void) +{ + /* Right now we need to do nothing here */ + ; +} diff --git a/cpu/atmega328p/doc.txt b/cpu/atmega328p/doc.txt new file mode 100644 index 0000000000..87c16cdbe4 --- /dev/null +++ b/cpu/atmega328p/doc.txt @@ -0,0 +1,10 @@ +/** + * @defgroup cpu_atmega328p Atmel ATmega328p + * @ingroup cpu + * @brief Implementation of Atmel's ATmega328p MCU + */ + +/** + * @defgroup cpu_atmega328p_definitions Atmel ATmega328p Definitions + * @ingroup cpu_atmega328p + */ diff --git a/cpu/atmega328p/include/cpu_conf.h b/cpu/atmega328p/include/cpu_conf.h new file mode 100644 index 0000000000..fd6b7a3374 --- /dev/null +++ b/cpu/atmega328p/include/cpu_conf.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * + * 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_atmega328p + * @{ + * + * @file + * @brief Implementation specific CPU configuration options + * + * @author Hauke Petersen + * @author Hinnerk van Bruinehsen + */ + +#ifndef CPU_CONF_H +#define CPU_CONF_H + +#include "atmega_regs_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Kernel configuration + * + * Since printf seems to get memory allocated by the linker/avr-libc the stack + * size tested sucessfully even with pretty small stacks.k + * @{ + */ +#define THREAD_EXTRA_STACKSIZE_PRINTF (128) + +#ifndef THREAD_STACKSIZE_DEFAULT +#define THREAD_STACKSIZE_DEFAULT (256) +#endif + +#define THREAD_STACKSIZE_IDLE (128) +#define ISR_STACKSIZE (0) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* CPU_CONF_H */ +/** @} */ diff --git a/cpu/atmega328p/include/periph_cpu.h b/cpu/atmega328p/include/periph_cpu.h new file mode 100644 index 0000000000..e7f67a2af9 --- /dev/null +++ b/cpu/atmega328p/include/periph_cpu.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 HAW Hamburg + * 2016 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_atmega328p + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author René Herthel + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph_cpu_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define a CPU specific GPIO pin generator macro + */ +#define GPIO_PIN(x, y) ((x << 4) | y) + +/** + * @brief Available ports on the ATmega328p family + */ +enum { + PORT_B = 1, /**< port B */ + PORT_C = 2, /**< port C */ + PORT_D = 3 /**< port D */ +}; + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/atmega328p/lpm_arch.c b/cpu/atmega328p/lpm_arch.c new file mode 100644 index 0000000000..8c8ed7b990 --- /dev/null +++ b/cpu/atmega328p/lpm_arch.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * + * 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_atmega328p + * @{ + * + * @file + * @brief Implementation of the kernels power management interface + * + * @author Hinnerk van Bruinehsen + * + * @} + */ + +#include "arch/lpm_arch.h" + +void lpm_arch_init(void) +{ + /* TODO */ +} + +enum lpm_mode lpm_arch_set(enum lpm_mode target) +{ + (void) target; + /* TODO */ + return 0; +} + +enum lpm_mode lpm_arch_get(void) +{ + /* TODO */ + return 0; +} + +void lpm_arch_awake(void) +{ + /* TODO */ +} + +void lpm_arch_begin_awake(void) +{ + /* TODO */ +} + +void lpm_arch_end_awake(void) +{ + /* TODO */ +} diff --git a/cpu/atmega328p/reboot_arch.c b/cpu/atmega328p/reboot_arch.c new file mode 100644 index 0000000000..802e592632 --- /dev/null +++ b/cpu/atmega328p/reboot_arch.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 Kaspar Schleiser + * 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * + * 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_atmega328p + * @{ + * + * @file + * @brief Implementation of the kernels reboot interface + * + * @author Hinnerk van Bruinehsen + * @author Kaspar Schleiser + * + * @} + */ + +#include + +#include "cpu.h" + +void reboot(void) +{ + /* + * Since the AVR doesn't support a real software reset, we set the Watchdog + * Timer on a 250ms timeout. Consider this a kludge. + */ + wdt_enable(WDTO_250MS); + while(1); +} diff --git a/cpu/atmega328p/startup.c b/cpu/atmega328p/startup.c new file mode 100644 index 0000000000..4601dcc430 --- /dev/null +++ b/cpu/atmega328p/startup.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * + * 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_atmega328p + * @{ + * + * @file + * @brief Startup code and interrupt vector definition + * + * @author Hinnerk van Bruinehsen + * + * @} + */ + +#include +#include +#include + +/* For Catchall-Loop */ +#include "board.h" + + +/** + * @brief functions for initializing the board, std-lib and kernel + */ +extern void board_init(void); +extern void kernel_init(void); +extern void __libc_init_array(void); + +/** + * @brief This pair of functions hook circumvent the call to main + * + * avr-libc normally uses the .init9 section for a call to main. This call + * seems to be not replaceable without hacking inside the library. We + * circumvent the call to main by using section .init7 to call the function + * reset_handler which therefore is the real entry point and section .init8 + * which should never be reached but just in case jumps to exit. + * This way there should be no way to call main directly. + */ +void init7_ovr(void) __attribute__((naked)) __attribute__((section(".init7"))); +void init8_ovr(void) __attribute__((naked)) __attribute__((section(".init8"))); + + +void init7_ovr(void) +{ + __asm__("call reset_handler"); +} + +void init8_ovr(void) +{ + __asm__("jmp exit"); +} +/** + * @brief This function is the entry point after a system reset + * + * After a system reset, the following steps are necessary and carried out: + * 1. initialize the board (sync clock, setup std-IO) + * 2. initialize and start RIOTs kernel + */ +void reset_handler(void) +{ + /* initialize the board and startup the kernel */ + board_init(); + /* startup the kernel */ + kernel_init(); +} diff --git a/sys/pipe/pipe_dynamic.c b/sys/pipe/pipe_dynamic.c index b6165de243..b6ecd2982d 100644 --- a/sys/pipe/pipe_dynamic.c +++ b/sys/pipe/pipe_dynamic.c @@ -25,7 +25,7 @@ * @} */ -#if defined(MCU_ATMEGA2560) || defined(MCU_ATMEGA1281) +#if defined(MCU_ATMEGA2560) || defined(MCU_ATMEGA1281) || defined(MCU_ATMEGA328P) #include #else #include diff --git a/tests/coap/Makefile b/tests/coap/Makefile index d958921835..411bfc6f99 100644 --- a/tests/coap/Makefile +++ b/tests/coap/Makefile @@ -3,7 +3,7 @@ include ../Makefile.tests_common # msp430 and avr have problems with int width and libcoaps usage of :x notation in structs BOARD_BLACKLIST := arduino-mega2560 chronos msb-430 msb-430h telosb wsn430-v1_3b \ - wsn430-v1_4 z1 waspmote-pro + wsn430-v1_4 z1 waspmote-pro arduino-uno arduino-duemilanove BOARD_INSUFFICIENT_MEMORY := chronos msb-430 msb-430h nucleo-f334 \ stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 z1 diff --git a/tests/libfixmath_unittests/Makefile b/tests/libfixmath_unittests/Makefile index 38c3685ebc..4325714e0e 100644 --- a/tests/libfixmath_unittests/Makefile +++ b/tests/libfixmath_unittests/Makefile @@ -1,7 +1,7 @@ APPLICATION = libfixmath_unittests include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-mega2560 waspmote-pro +BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove # arduino-mega2560: builds locally but breaks travis (possibly because of # differences in the toolchain) diff --git a/tests/lwip/Makefile b/tests/lwip/Makefile index c004c6202f..e078b9fcdb 100644 --- a/tests/lwip/Makefile +++ b/tests/lwip/Makefile @@ -4,7 +4,8 @@ BOARD ?= iotlab-m3 RIOTBASE ?= $(CURDIR)/../.. -BOARD_BLACKLIST := arduino-mega2560 msb-430h telosb waspmote-pro z1 +BOARD_BLACKLIST := arduino-mega2560 msb-430h telosb waspmote-pro z1 arduino-uno \ + arduino-duemilanove BOARD_INSUFFICIENT_MEMORY := airfy-beacon arduino-mega2560 msb-430h nrf6310 \ nucleo-f334 pca10005 stm32f0discovery telosb \ weio yunjia-nrf51822 z1 diff --git a/tests/nhdp/Makefile b/tests/nhdp/Makefile index f7418293ba..5cc0db1905 100644 --- a/tests/nhdp/Makefile +++ b/tests/nhdp/Makefile @@ -2,7 +2,8 @@ APPLICATION = nhdp include ../Makefile.tests_common BOARD_BLACKLIST := arduino-mega2560 chronos msb-430 msb-430h telosb \ - wsn430-v1_3b wsn430-v1_4 z1 waspmote-pro + wsn430-v1_3b wsn430-v1_4 z1 waspmote-pro arduino-uno \ + arduino-duemilanove BOARD_INSUFFICIENT_MEMORY := nucleo-f334 stm32f0discovery weio USEMODULE += gnrc_ipv6 diff --git a/tests/pthread/Makefile b/tests/pthread/Makefile index c1abd565a8..2e2c8e2c1c 100644 --- a/tests/pthread/Makefile +++ b/tests/pthread/Makefile @@ -1,8 +1,8 @@ APPLICATION = pthread include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-mega2560 waspmote-pro -# arduino-mega2560: unknown type name: clockid_t +BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove +# arduino mega2560 uno duemilanove : unknown type name: clockid_t USEMODULE += posix USEMODULE += pthread diff --git a/tests/pthread_barrier/Makefile b/tests/pthread_barrier/Makefile index ed332b7a62..25724bd0ce 100644 --- a/tests/pthread_barrier/Makefile +++ b/tests/pthread_barrier/Makefile @@ -2,8 +2,8 @@ APPLICATION = pthread_barrier include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-mega2560 waspmote-pro -# arduino-mega2560: unknown type name: clockid_t +BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove +# arduino mega2560 uno duemilanove: unknown type name: clockid_t # exclude boards with insufficient memory BOARD_INSUFFICIENT_MEMORY := stm32f0discovery diff --git a/tests/pthread_cleanup/Makefile b/tests/pthread_cleanup/Makefile index beb03d294c..dc485fd43c 100644 --- a/tests/pthread_cleanup/Makefile +++ b/tests/pthread_cleanup/Makefile @@ -1,8 +1,8 @@ APPLICATION = pthread_cleanup include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-mega2560 waspmote-pro -# arduino-mega2560: unknown type name: clockid_t +BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove +# arduino mega2560 uno duemilanove : unknown type name: clockid_t USEMODULE += pthread diff --git a/tests/pthread_condition_variable/Makefile b/tests/pthread_condition_variable/Makefile index 902190c834..a21acd800a 100644 --- a/tests/pthread_condition_variable/Makefile +++ b/tests/pthread_condition_variable/Makefile @@ -1,8 +1,8 @@ APPLICATION = condition_variable include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-mega2560 waspmote-pro -# arduino-mega2560: unknown type name: clockid_t +BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove +# arduino mega2560 uno duemilanove: unknown type name: clockid_t BOARD_INSUFFICIENT_MEMORY := stm32f0discovery diff --git a/tests/pthread_cooperation/Makefile b/tests/pthread_cooperation/Makefile index ab53757820..dc249777d3 100644 --- a/tests/pthread_cooperation/Makefile +++ b/tests/pthread_cooperation/Makefile @@ -1,8 +1,8 @@ APPLICATION = pthread_cooperation include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-mega2560 waspmote-pro -# arduino-mega2560: unknown type name: clockid_t +BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove +# arduino mega2560 uno duemilanove: unknown type name: clockid_t USEMODULE += posix USEMODULE += pthread diff --git a/tests/pthread_rwlock/Makefile b/tests/pthread_rwlock/Makefile index e6b7bd20cf..0f6c422e04 100644 --- a/tests/pthread_rwlock/Makefile +++ b/tests/pthread_rwlock/Makefile @@ -1,8 +1,8 @@ APPLICATION = pthread_rwlock include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-mega2560 waspmote-pro -# arduino-mega2560: unknown type name: clockid_t +BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove +# arduino mega2560 uno duemilanove: unknown type name: clockid_t USEMODULE += pthread USEMODULE += xtimer diff --git a/tests/pthread_tls/Makefile b/tests/pthread_tls/Makefile index 8575ea74d4..0fe7b4e5a8 100644 --- a/tests/pthread_tls/Makefile +++ b/tests/pthread_tls/Makefile @@ -1,8 +1,8 @@ APPLICATION = pthread_tls include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-mega2560 waspmote-pro -# arduino-mega2560: unknown type name: clockid_t +BOARD_BLACKLIST := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove +# arduino mega2560 uno duemilanove: unknown type name: clockid_t USEMODULE += posix USEMODULE += pthread diff --git a/tests/unittests/Makefile b/tests/unittests/Makefile index e87ff2aaa8..df12886508 100644 --- a/tests/unittests/Makefile +++ b/tests/unittests/Makefile @@ -6,7 +6,8 @@ BOARD_INSUFFICIENT_MEMORY := airfy-beacon cc2650stk chronos msb-430 msb-430h pca telosb wsn430-v1_3b wsn430-v1_4 z1 nucleo-f103 \ nucleo-f334 yunjia-nrf51822 samr21-xpro \ arduino-mega2560 airfy-beacon nrf51dongle nrf6310 \ - weio waspmote-pro nucleo-f072 + weio waspmote-pro nucleo-f072 arduino-uno \ + arduino-duemilanove USEMODULE += embunit @@ -27,7 +28,7 @@ ARM_CORTEX_M_BOARDS := airfy-beacon arduino-due cc2538dk ek-lm4f120xl f4vi1 fox yunjia-nrf51822 DISABLE_TEST_FOR_ARM_CORTEX_M := tests-relic -AVR_BOARDS := arduino-mega2560 waspmote-pro +AVR_BOARDS := arduino-mega2560 waspmote-pro arduino-uno arduino-duemilanove DISABLE_TEST_FOR_AVR := tests-relic MSP430_BOARDS := chronos msb-430 msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1