From f6df6a6a187764e530afa061e3ea931c0988187b Mon Sep 17 00:00:00 2001 From: BlackMark Date: Thu, 15 Aug 2019 18:49:29 +0200 Subject: [PATCH] Undid accidental regression --- hardware0.hpp | 26 +++++++++++++++++--------- hardware1.hpp | 26 +++++++++++++++++--------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/hardware0.hpp b/hardware0.hpp index ffbdd0d..9260d68 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -19,22 +19,30 @@ namespace detail { #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__) /* -The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are not legal constexpr's +The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are not legal constexpr's: 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 the sfr_defs.h provides a macro which returns the address of a register +Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site. +The _SFR_ADDR macro in sfr_defs.h would give the address, but it does that by taking the address of the dereferenced +pointer and casts it to uint16_t, which is still not a legal constexpr. +The workaround therefore is to disable the pointer cast and dereference macro _MMIO_BYTE temporarily. */ +#pragma push_macro("_MMIO_BYTE") +#undef _MMIO_BYTE +#define _MMIO_BYTE + struct Registers0 { - 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); + 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; }; +#pragma pop_macro("_MMIO_BYTE") + enum class ControlFlagsA0 { MULTI_PROC_COMM_MODE = MPCM0, SPEED_2X = U2X0, diff --git a/hardware1.hpp b/hardware1.hpp index 72233da..42a8c41 100644 --- a/hardware1.hpp +++ b/hardware1.hpp @@ -19,22 +19,30 @@ namespace detail { #if defined(__AVR_ATmega1284P__) /* -The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are not legal constexpr's +The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are not legal constexpr's: 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 the sfr_defs.h provides a macro which returns the address of a register +Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site. +The _SFR_ADDR macro in sfr_defs.h would give the address, but it does that by taking the address of the dereferenced +pointer and casts it to uint16_t, which is still not a legal constexpr. +The workaround therefore is to disable the pointer cast and dereference macro _MMIO_BYTE temporarily. */ +#pragma push_macro("_MMIO_BYTE") +#undef _MMIO_BYTE +#define _MMIO_BYTE + struct Registers1 { - 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); + 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; }; +#pragma pop_macro("_MMIO_BYTE") + enum class ControlFlagsA1 { MULTI_PROC_COMM_MODE = MPCM1, SPEED_2X = U2X1,