From a55921394c6060f49a4ed2bab51847fd153147b8 Mon Sep 17 00:00:00 2001 From: Matthew Blue Date: Sat, 17 Mar 2018 16:21:26 -0400 Subject: [PATCH] cpu/atmega1284p: Initial ATmega1284P support --- cpu/atmega1284p/Makefile | 6 +++ cpu/atmega1284p/Makefile.features | 1 + cpu/atmega1284p/Makefile.include | 8 +++ cpu/atmega1284p/cpu.c | 32 ++++++++++++ cpu/atmega1284p/doc.txt | 10 ++++ cpu/atmega1284p/include/cpu_conf.h | 52 +++++++++++++++++++ cpu/atmega1284p/include/periph_cpu.h | 60 ++++++++++++++++++++++ cpu/atmega1284p/startup.c | 74 ++++++++++++++++++++++++++++ 8 files changed, 243 insertions(+) create mode 100644 cpu/atmega1284p/Makefile create mode 100644 cpu/atmega1284p/Makefile.features create mode 100644 cpu/atmega1284p/Makefile.include create mode 100644 cpu/atmega1284p/cpu.c create mode 100644 cpu/atmega1284p/doc.txt create mode 100644 cpu/atmega1284p/include/cpu_conf.h create mode 100644 cpu/atmega1284p/include/periph_cpu.h create mode 100644 cpu/atmega1284p/startup.c diff --git a/cpu/atmega1284p/Makefile b/cpu/atmega1284p/Makefile new file mode 100644 index 0000000000..81f110b68d --- /dev/null +++ b/cpu/atmega1284p/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/atmega1284p/Makefile.features b/cpu/atmega1284p/Makefile.features new file mode 100644 index 0000000000..008260685b --- /dev/null +++ b/cpu/atmega1284p/Makefile.features @@ -0,0 +1 @@ +-include $(RIOTCPU)/atmega_common/Makefile.features diff --git a/cpu/atmega1284p/Makefile.include b/cpu/atmega1284p/Makefile.include new file mode 100644 index 0000000000..b46d4e871c --- /dev/null +++ b/cpu/atmega1284p/Makefile.include @@ -0,0 +1,8 @@ +# 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/atmega1284p/cpu.c b/cpu/atmega1284p/cpu.c new file mode 100644 index 0000000000..1597edb175 --- /dev/null +++ b/cpu/atmega1284p/cpu.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 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 cpu_atmega1284p + * @{ + * + * @file + * @brief Implementation of the CPU initialization + * + * @author Hinnerk van Bruinehsen + * @author Matthew Blue + * @} + */ + +#include "cpu.h" +#include "periph/init.h" + +/** + * @brief Initialize the CPU, set IRQ priorities + */ +void cpu_init(void) +{ + /* trigger static peripheral initialization */ + periph_init(); +} diff --git a/cpu/atmega1284p/doc.txt b/cpu/atmega1284p/doc.txt new file mode 100644 index 0000000000..04e97dc15d --- /dev/null +++ b/cpu/atmega1284p/doc.txt @@ -0,0 +1,10 @@ +/** + * @defgroup cpu_atmega1284p Atmel ATmega1284p + * @ingroup cpu + * @brief Implementation of Atmel's ATmega1284p MCU + */ + +/** + * @defgroup cpu_atmega1284p_definitions Atmel ATmega1284p Definitions + * @ingroup cpu_atmega1284p + */ diff --git a/cpu/atmega1284p/include/cpu_conf.h b/cpu/atmega1284p/include/cpu_conf.h new file mode 100644 index 0000000000..e87b7d2a01 --- /dev/null +++ b/cpu/atmega1284p/include/cpu_conf.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 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 cpu_atmega1284p + * @{ + * + * @file + * @brief Implementation specific CPU configuration options + * + * @author Hauke Petersen + * @author Hinnerk van Bruinehsen + * @author Matthew Blue + */ + +#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 successfully 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) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* CPU_CONF_H */ +/** @} */ diff --git a/cpu/atmega1284p/include/periph_cpu.h b/cpu/atmega1284p/include/periph_cpu.h new file mode 100644 index 0000000000..c7f4341912 --- /dev/null +++ b/cpu/atmega1284p/include/periph_cpu.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 HAW Hamburg + * 2016 Freie Universität Berlin + * 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 cpu_atmega1284p + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author René Herthel + * @author Hauke Petersen + * @author Matthew Blue + */ + +#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_A = 0, /**< port A */ + PORT_B = 1, /**< port B */ + PORT_C = 2, /**< port C */ + PORT_D = 3 /**< port D */ +}; + +/** + * @name Defines for the I2C interface + * @{ + */ +#define I2C_PORT_REG PORTC +#define I2C_PIN_MASK (1 << PORTC0) | (1 << PORTC1) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H */ +/** @} */ diff --git a/cpu/atmega1284p/startup.c b/cpu/atmega1284p/startup.c new file mode 100644 index 0000000000..7c4d8a56d7 --- /dev/null +++ b/cpu/atmega1284p/startup.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 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 cpu_atmega1284p + * @{ + * + * @file + * @brief Startup code and interrupt vector definition + * + * @author Hinnerk van Bruinehsen + * @author Matthew Blue + * + * @} + */ + +#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(); +}