diff --git a/boards/arduino-leonardo/board.c b/boards/arduino-leonardo/board.c index 32403ecaf2..9825132215 100644 --- a/boards/arduino-leonardo/board.c +++ b/boards/arduino-leonardo/board.c @@ -35,7 +35,7 @@ void board_init(void) PRR1 |= 1<DR = data[i]; } @@ -194,22 +194,22 @@ void uart_poweroff(uart_t uart) static inline void _rx_isr_handler(int num) { - atmega_enter_isr(); + avr8_enter_isr(); isr_ctx[num].rx_cb(isr_ctx[num].arg, dev[num]->DR); - atmega_exit_isr(); + avr8_exit_isr(); } static inline void _tx_isr_handler(int num) { - atmega_enter_isr(); + avr8_enter_isr(); /* entire frame in the Transmit Shift Register has been shifted out and there are no new data currently present in the transmit buffer */ - atmega_state &= ~ATMEGA_STATE_FLAG_UART_TX(num); + avr8_state &= ~AVR8_STATE_FLAG_UART_TX(num); - atmega_exit_isr(); + avr8_exit_isr(); } diff --git a/cpu/avr8_common/avr8_cpu.c b/cpu/avr8_common/avr8_cpu.c index 592d9658e0..bdcfb12ec1 100644 --- a/cpu/avr8_common/avr8_cpu.c +++ b/cpu/avr8_common/avr8_cpu.c @@ -2,6 +2,7 @@ * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen * 2017 RWTH Aachen, Josua Arndt * 2018 Matthew Blue + * 2021 Gerson Fernando Budke * * 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 @@ -9,7 +10,7 @@ */ /** - * @ingroup cpu_atmega_common + * @ingroup cpu_avr8_common * @{ * * @file @@ -20,7 +21,8 @@ * @author Josua Arndt * @author Matthew Blue * @author Francisco Acosta - + * @author Gerson Fernando Budke + * * @} */ @@ -58,7 +60,8 @@ */ uint8_t mcusr_mirror __attribute__((section(".noinit"))); uint8_t soft_rst __attribute__((section(".noinit"))); -uint8_t atmega_state = 0; +uint8_t avr8_state = 0; + void get_mcusr(void) __attribute__((naked, section(".init0"), used)); void get_mcusr(void) @@ -78,14 +81,14 @@ void get_mcusr(void) void cpu_init(void) { - atmega_reset_cause(); + avr8_reset_cause(); wdt_reset(); /* should not be nececessary as done in bootloader */ wdt_disable(); /* but when used without bootloader this is needed */ /* Initialize stdio before periph_init() to allow use of DEBUG() there */ #ifdef MODULE_AVR_LIBC_EXTRA - atmega_stdio_init(); + avr8_stdio_init(); #endif /* Initialize peripherals for which modules are included in the makefile.*/ /* spi_init */ diff --git a/cpu/avr8_common/avr_libc_extra/avr8_stdio.c b/cpu/avr8_common/avr_libc_extra/avr8_stdio.c index d37158b0ad..274688d3e9 100644 --- a/cpu/avr8_common/avr_libc_extra/avr8_stdio.c +++ b/cpu/avr8_common/avr_libc_extra/avr8_stdio.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2018 Kaspar Schleiser + * 2021 Gerson Fernando Budke * * 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 @@ -10,9 +11,10 @@ * @{ * * @file - * @brief Implements common atmega libc stdio initialization + * @brief Implements common avr8 libc stdio initialization * * @author Kaspar Schleiser + * @author Gerson Fernando Budke * * @} */ @@ -41,7 +43,7 @@ static int _uart_getchar(FILE *stream) return (int)c; } -void atmega_stdio_init(void) +void avr8_stdio_init(void) { stdio_init(); diff --git a/cpu/avr8_common/include/architecture_arch.h b/cpu/avr8_common/include/architecture_arch.h index 701fa68df1..a4e7733fb5 100644 --- a/cpu/avr8_common/include/architecture_arch.h +++ b/cpu/avr8_common/include/architecture_arch.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg + * 2021 Gerson Fernando Budke * * 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 @@ -7,13 +8,14 @@ */ /** - * @ingroup cpu_atmega_common + * @ingroup cpu_avr8_common * @{ * * @file * @brief Architecture details * * @author Marian Buschsieweke + * @author Gerson Fernando Budke * */ diff --git a/cpu/avr8_common/include/atomic_utils_arch.h b/cpu/avr8_common/include/atomic_utils_arch.h index 6c8ab36a41..3d3212801a 100644 --- a/cpu/avr8_common/include/atomic_utils_arch.h +++ b/cpu/avr8_common/include/atomic_utils_arch.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg + * 2021 Gerson Fernando Budke * * 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 @@ -7,13 +8,14 @@ */ /** - * @ingroup cpu_atmega_common + * @ingroup cpu_avr8_common * * @{ * * @file * @brief Implementation of fast atomic utility functions * @author Marian Buschsieweke + * @author Gerson Fernando Budke */ #ifndef ATOMIC_UTILS_ARCH_H diff --git a/cpu/avr8_common/include/cpu.h b/cpu/avr8_common/include/cpu.h index 7f6214d421..42cfd34354 100644 --- a/cpu/avr8_common/include/cpu.h +++ b/cpu/avr8_common/include/cpu.h @@ -2,6 +2,7 @@ * Copyright (C) 2015 Kaspar Schleiser * 2014 Freie Universität Berlin, Hinnerk van Bruinehsen * 2018 RWTH Aachen, Josua Arndt + * 2021 Gerson Fernando Budke * * 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 @@ -9,12 +10,12 @@ */ /** - * @ingroup cpu_atmega_common - * @brief Common implementations and headers for ATmega family based micro-controllers + * @ingroup cpu_avr8_common + * @brief Common implementations and headers for AVR-8 family based micro-controllers * @{ * * @file - * @brief Basic definitions for the ATmega common module + * @brief Basic definitions for the AVR-8 common module * * When ever you want to do something hardware related, that is accessing MCUs registers directly, * just include this file. It will then make sure that the MCU specific headers are included. @@ -24,6 +25,7 @@ * @author Hinnerk van Bruinehsen * @author Kaspar Schleiser * @author Josua Arndt + * @author Gerson Fernando Budke * */ @@ -58,10 +60,10 @@ extern "C" * @name Flags for the current state of the ATmega MCU * @{ */ -#define ATMEGA_STATE_FLAG_ISR (0x80U) /**< In ISR */ -#define ATMEGA_STATE_FLAG_UART0_TX (0x01U) /**< TX pending for UART 0 */ -#define ATMEGA_STATE_FLAG_UART1_TX (0x02U) /**< TX pending for UART 1 */ -#define ATMEGA_STATE_FLAG_UART_TX(x) (0x01U << x) /**< TX pending for UART x */ +#define AVR8_STATE_FLAG_ISR (0x80U) /**< In ISR */ +#define AVR8_STATE_FLAG_UART0_TX (0x01U) /**< TX pending for UART 0 */ +#define AVR8_STATE_FLAG_UART1_TX (0x02U) /**< TX pending for UART 1 */ +#define AVR8_STATE_FLAG_UART_TX(x) (0x01U << x) /**< TX pending for UART x */ /** @} */ /** @@ -69,7 +71,7 @@ extern "C" * * @note This variable is updated from IRQ context; access to it should * be wrapped into @ref irq_disable and @ref irq_restore or - * @ref atmega_get_state should be used. + * @ref avr8_get_state should be used. * * Contents: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -86,26 +88,26 @@ extern "C" * | TX1 | This bit is set when on UART1 TX is pending | * | TX0 | This bit is set when on UART0 TX is pending | */ -extern uint8_t atmega_state; +extern uint8_t avr8_state; /** - * @brief Atomically read the state (@ref atmega_state) + * @brief Atomically read the state (@ref avr8_state) * * This function guarantees that the read is not optimized out, not reordered * and done atomically. This does not mean that by the time return value is * processed that it still reflects the value currently stored in - * @ref atmega_state. + * @ref avr8_state. * * Using ASM rather than C11 atomics has less overhead, as not every access to * the state has to be performed atomically: Those done from ISR will not be * interrupted (no support for nested interrupts) and barriers at the begin and * end of the ISRs make sure the access takes place before IRQ context is left. */ -static inline uint8_t atmega_get_state(void) +static inline uint8_t avr8_get_state(void) { uint8_t state; __asm__ volatile( - "lds %[state], atmega_state \n\t" + "lds %[state], avr8_state \n\t" : [state] "=r" (state) : : "memory" @@ -118,13 +120,13 @@ static inline uint8_t atmega_get_state(void) /** * @brief Run this code on entering interrupt routines */ -static inline void atmega_enter_isr(void) +static inline void avr8_enter_isr(void) { /* This flag is only called from IRQ context, and nested IRQs are not * supported as of now. The flag will be unset before the IRQ context is * left, so no need to use memory barriers or atomics here */ - atmega_state |= ATMEGA_STATE_FLAG_ISR; + avr8_state |= AVR8_STATE_FLAG_ISR; } /** @@ -133,16 +135,16 @@ static inline void atmega_enter_isr(void) * @retval !=0 At least on UART device is still sending data out * @retval 0 No UART is currently sending data */ -static inline int atmega_is_uart_tx_pending(void) +static inline int avr8_is_uart_tx_pending(void) { - uint8_t state = atmega_get_state(); - return (state & (ATMEGA_STATE_FLAG_UART0_TX | ATMEGA_STATE_FLAG_UART1_TX)); + uint8_t state = avr8_get_state(); + return (state & (AVR8_STATE_FLAG_UART0_TX | AVR8_STATE_FLAG_UART1_TX)); } /** * @brief Run this code on exiting interrupt routines */ -void atmega_exit_isr(void); +void avr8_exit_isr(void); /** * @brief Initialization of the CPU @@ -172,12 +174,12 @@ static inline void __attribute__((always_inline)) cpu_print_last_instruction(voi /** * @brief Initializes avrlibc stdio */ -void atmega_stdio_init(void); +void avr8_stdio_init(void); /** * @brief Print reset cause */ -void atmega_reset_cause(void); +void avr8_reset_cause(void); #ifdef __cplusplus } diff --git a/cpu/avr8_common/include/irq_arch.h b/cpu/avr8_common/include/irq_arch.h index d4079c1ff1..5287a9c251 100644 --- a/cpu/avr8_common/include/irq_arch.h +++ b/cpu/avr8_common/include/irq_arch.h @@ -2,6 +2,7 @@ * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen * 2018 RWTH Aachen, Josua Arndt * 2020 Otto-von-Guericke-Universität Magdeburg + * 2021 Gerson Fernando Budke * * 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 @@ -9,7 +10,7 @@ */ /** - * @ingroup cpu_atmega_common + * @ingroup cpu_avr8_common * @{ * * @file @@ -19,6 +20,7 @@ * @author Hinnerk van Bruinehsen * @author Josua Arndt * @author Marian Buschsieweke + * @author Gerson Fernando Budke * */ @@ -28,7 +30,6 @@ #include #include #include -#include "irq.h" #include "cpu.h" #ifdef __cplusplus @@ -98,8 +99,8 @@ __attribute__((always_inline)) static inline void irq_restore(unsigned int _stat */ __attribute__((always_inline)) static inline int irq_is_in(void) { - uint8_t state = atmega_get_state(); - return (state & ATMEGA_STATE_FLAG_ISR); + uint8_t state = avr8_get_state(); + return (state & AVR8_STATE_FLAG_ISR); } #ifdef __cplusplus diff --git a/cpu/avr8_common/startup.c b/cpu/avr8_common/startup.c index 0dbb20fbd3..da9f6263d1 100644 --- a/cpu/avr8_common/startup.c +++ b/cpu/avr8_common/startup.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 2021 Gerson Fernando Budke * * 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 @@ -7,7 +8,7 @@ */ /** - * @ingroup cpu_atmega_common + * @ingroup cpu_avr8_common * @{ * * @file @@ -16,6 +17,7 @@ * @author Hinnerk van Bruinehsen * @author Josua Arndt * @author Steffen Robertz + * @author Gerson Fernando Budke * @} */ diff --git a/cpu/avr8_common/thread_arch.c b/cpu/avr8_common/thread_arch.c index 1960b8d22d..9ea1cd66af 100644 --- a/cpu/avr8_common/thread_arch.c +++ b/cpu/avr8_common/thread_arch.c @@ -2,6 +2,7 @@ * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen * 2017 Thomas Perrot * 2018 RWTH Aachen, Josua Arndt + * 2021 Gerson Fernando Budke * * 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 @@ -9,7 +10,7 @@ */ /** - * @ingroup cpu_atmega_common + * @ingroup cpu_avr8_common * @{ * * @file @@ -18,6 +19,7 @@ * @author Hinnerk van Bruinehsen * @author Thomas Perrot * @author Josua Arndt + * @author Gerson Fernando Budke * * @} */ @@ -30,13 +32,13 @@ #include "cpu.h" #include "board.h" -static void atmega_context_save(void); -static void atmega_context_restore(void); -static void atmega_enter_thread_mode(void); +static void avr8_context_save(void); +static void avr8_context_restore(void); +static void avr8_enter_thread_mode(void); /** * @brief Since AVR doesn't support direct manipulation of the program counter we - * model a stack like it would be left by atmega_context_save(). + * model a stack like it would be left by avr8_context_save(). * The resulting layout in memory is the following: * ---------------thread_t (not created by thread_stack_init) ---------- * local variables (a temporary value and the stackpointer) @@ -48,7 +50,7 @@ static void atmega_enter_thread_mode(void); * ----------------------------------------------------------------------- * a 16 Bit pointer to task_func * this is placed exactly at the place where the program counter would be - * stored normally and thus can be returned to when atmega_context_restore() + * stored normally and thus can be returned to when avr8_context_restore() * has been run * (Optional 17 bit (bit is set to zero) for devices with > 128kb FLASH) * ----------------------------------------------------------------------- @@ -61,7 +63,7 @@ static void atmega_enter_thread_mode(void); * r26 - r31 * ----------------------------------------------------------------------- * - * After the invocation of atmega_context_restore() the pointer to task_func is + * After the invocation of avr8_context_restore() the pointer to task_func is * on top of the stack and can be returned to. This way we can actually place * it inside of the program counter of the MCU. * if task_func returns sched_task_exit gets popped into the PC @@ -198,7 +200,7 @@ void thread_stack_print(void) void cpu_switch_context_exit(void) { sched_run(); - atmega_enter_thread_mode(); + avr8_enter_thread_mode(); } #define STACK_POINTER ((char *)AVR_STACK_POINTER_REG) @@ -210,7 +212,7 @@ extern char *__brkval; /** * @brief Set the MCU into Thread-Mode and load the initial task from the stack and run it */ -void NORETURN atmega_enter_thread_mode(void) +void NORETURN avr8_enter_thread_mode(void) { irq_enable(); @@ -226,7 +228,7 @@ void NORETURN atmega_enter_thread_mode(void) __brkval = __malloc_heap_start; } - atmega_context_restore(); + avr8_context_restore(); __asm__ volatile ("ret"); UNREACHABLE(); @@ -235,9 +237,9 @@ void NORETURN atmega_enter_thread_mode(void) void thread_yield_higher(void) { if (irq_is_in() == 0) { - atmega_context_save(); + avr8_context_save(); sched_run(); - atmega_context_restore(); + avr8_context_restore(); __asm__ volatile ("ret"); } else { @@ -245,20 +247,20 @@ void thread_yield_higher(void) } } -void atmega_exit_isr(void) +void avr8_exit_isr(void) { - atmega_state &= ~ATMEGA_STATE_FLAG_ISR; - /* Force access to atmega_state to take place */ + avr8_state &= ~AVR8_STATE_FLAG_ISR; + /* Force access to avr8_state to take place */ __asm__ volatile ("" : : : "memory"); if (sched_context_switch_request) { - atmega_context_save(); + avr8_context_save(); sched_run(); - atmega_context_restore(); + avr8_context_restore(); __asm__ volatile ("reti"); } } -__attribute__((always_inline)) static inline void atmega_context_save(void) +__attribute__((always_inline)) static inline void avr8_context_save(void) { __asm__ volatile ( "push __tmp_reg__ \n\t" @@ -313,7 +315,7 @@ __attribute__((always_inline)) static inline void atmega_context_save(void) "st x+, __tmp_reg__ \n\t"); } -__attribute__((always_inline)) static inline void atmega_context_restore(void) +__attribute__((always_inline)) static inline void avr8_context_restore(void) { __asm__ volatile ( "lds r26, sched_active_thread \n\t" diff --git a/drivers/at86rf2xx/at86rf2xx_netdev.c b/drivers/at86rf2xx/at86rf2xx_netdev.c index 1def1bbc05..fb2d372c6f 100644 --- a/drivers/at86rf2xx/at86rf2xx_netdev.c +++ b/drivers/at86rf2xx/at86rf2xx_netdev.c @@ -870,7 +870,7 @@ ISR(TRX24_TX_START_vect){ */ ISR(TRX24_RX_END_vect, ISR_BLOCK) { - atmega_enter_isr(); + avr8_enter_isr(); uint8_t status = *AT86RF2XX_REG__TRX_STATE & AT86RF2XX_TRX_STATUS_MASK__TRX_STATUS; DEBUG("TRX24_RX_END 0x%x\n", status); @@ -879,7 +879,7 @@ ISR(TRX24_RX_END_vect, ISR_BLOCK) /* Call upper layer to process received data */ netdev_trigger_event_isr(at86rfmega_dev); - atmega_exit_isr(); + avr8_exit_isr(); } /** @@ -892,12 +892,12 @@ ISR(TRX24_RX_END_vect, ISR_BLOCK) */ ISR(TRX24_XAH_AMI_vect, ISR_BLOCK) { - atmega_enter_isr(); + avr8_enter_isr(); DEBUG("TRX24_XAH_AMI\n"); ((at86rf2xx_t *)at86rfmega_dev)->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__AMI; - atmega_exit_isr(); + avr8_exit_isr(); } /** @@ -909,7 +909,7 @@ ISR(TRX24_XAH_AMI_vect, ISR_BLOCK) */ ISR(TRX24_TX_END_vect, ISR_BLOCK) { - atmega_enter_isr(); + avr8_enter_isr(); at86rf2xx_t *dev = (at86rf2xx_t *) at86rfmega_dev; uint8_t status = *AT86RF2XX_REG__TRX_STATE & AT86RF2XX_TRX_STATUS_MASK__TRX_STATUS; @@ -924,7 +924,7 @@ ISR(TRX24_TX_END_vect, ISR_BLOCK) netdev_trigger_event_isr(at86rfmega_dev); } - atmega_exit_isr(); + avr8_exit_isr(); } #endif /* MODULE_AT86RFA1 || MODULE_AT86RFR2 */