From 2fd05483ee23bd503ad5855b8ef18f48b57271cb Mon Sep 17 00:00:00 2001 From: BlackMark Date: Thu, 15 Aug 2019 17:48:41 +0200 Subject: [PATCH] Replaced workaround with provided macro --- hardware0.hpp | 20 +++++++------------- hardware1.hpp | 20 +++++++------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/hardware0.hpp b/hardware0.hpp index abc9fcf..4c13d84 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -22,24 +22,18 @@ The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are no constexpr auto *foo = ptr; Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site -For this to work we need to temporarily disable the _SFR_MEM8 macro so that the register macro just gives the address +For this the sfr_defs.h provides a macro which returns the address of a register */ -#undef _SFR_MEM8 -#define _SFR_MEM8 - struct Registers0 { - static constexpr uintptr_t IO_REG_ADDR = UDR0; - static constexpr uintptr_t CTRL_STAT_REG_A_ADDR = UCSR0A; - static constexpr uintptr_t CTRL_STAT_REG_B_ADDR = UCSR0B; - static constexpr uintptr_t CTRL_STAT_REG_C_ADDR = UCSR0C; - static constexpr uintptr_t BAUD_REG_L_ADDR = UBRR0L; - static constexpr uintptr_t BAUD_REG_H_ADDR = UBRR0H; + static constexpr uintptr_t IO_REG_ADDR = _SFR_ADDR(UDR0); + static constexpr uintptr_t CTRL_STAT_REG_A_ADDR = _SFR_ADDR(UCSR0A); + static constexpr uintptr_t CTRL_STAT_REG_B_ADDR = _SFR_ADDR(UCSR0B); + static constexpr uintptr_t CTRL_STAT_REG_C_ADDR = _SFR_ADDR(UCSR0C); + static constexpr uintptr_t BAUD_REG_L_ADDR = _SFR_ADDR(UBRR0L); + static constexpr uintptr_t BAUD_REG_H_ADDR = _SFR_ADDR(UBRR0H); }; -#undef _SFR_MEM8 -#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr) - enum class ControlFlagsA0 { MULTI_PROC_COMM_MODE = MPCM0, SPEED_2X = U2X0, diff --git a/hardware1.hpp b/hardware1.hpp index a8af41b..901012a 100644 --- a/hardware1.hpp +++ b/hardware1.hpp @@ -22,24 +22,18 @@ The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are no constexpr auto *foo = ptr; Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site -For this to work we need to temporarily disable the _SFR_MEM8 macro so that the register macro just gives the address +For this the sfr_defs.h provides a macro which returns the address of a register */ -#undef _SFR_MEM8 -#define _SFR_MEM8 - struct Registers1 { - static constexpr uintptr_t IO_REG_ADDR = UDR1; - static constexpr uintptr_t CTRL_STAT_REG_A_ADDR = UCSR1A; - static constexpr uintptr_t CTRL_STAT_REG_B_ADDR = UCSR1B; - static constexpr uintptr_t CTRL_STAT_REG_C_ADDR = UCSR1C; - static constexpr uintptr_t BAUD_REG_L_ADDR = UBRR1L; - static constexpr uintptr_t BAUD_REG_H_ADDR = UBRR1H; + static constexpr uintptr_t IO_REG_ADDR = _SFR_ADDR(UDR1); + static constexpr uintptr_t CTRL_STAT_REG_A_ADDR = _SFR_ADDR(UCSR1A); + static constexpr uintptr_t CTRL_STAT_REG_B_ADDR = _SFR_ADDR(UCSR1B); + static constexpr uintptr_t CTRL_STAT_REG_C_ADDR = _SFR_ADDR(UCSR1C); + static constexpr uintptr_t BAUD_REG_L_ADDR = _SFR_ADDR(UBRR1L); + static constexpr uintptr_t BAUD_REG_H_ADDR = _SFR_ADDR(UBRR1H); }; -#undef _SFR_MEM8 -#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr) - enum class ControlFlagsA1 { MULTI_PROC_COMM_MODE = MPCM1, SPEED_2X = U2X1,