2.2.3 Multibyte Registers in Module Structures

Some registers are used in conjunction with other registers to represent 16- or 32-bit values. For example, the ADC result (RES), the Window Comparator Low Threshold WINLT, and the Window Comparator High Threshold WINTH are 16-bit registers for the ATmega4809 device, declared using the _WORDREGISTER macro. The macro is presented in the listing below, along with the _DWORDREGISTER macro used to declare 32-bit registers. These macros are already defined in the header file.

The _WORDREGISTER macro is used to extend the name of a register to access its lower byte and its higher byte, by adding the L or the H suffix. The _DWORDREGISTER macro is also providing access to all bytes of a multibyte register, by adding a number suffix. Both _WORDREGISTER and _DWORDREGISTER definitions are presented in the code below.

#ifdef _WORDREGISTER
#undef _WORDREGISTER
#endif
#define _WORDREGISTER(regname) \
    __extension__ union \
    { \
        register16_t regname; \
        struct \
        { \
            register8_t regname ## L; \
            register8_t regname ## H; \
        }; \
    }
#ifdef _DWORDREGISTER
#undef _DWORDREGISTER
#endif
#define _DWORDREGISTER(regname)  \
    __extension__ union \
    { \
        register32_t regname; \
        struct \
        { \
            register8_t regname ## 0; \
            register8_t regname ## 1; \
            register8_t regname ## 2; \
            register8_t regname ## 3; \
        }; \
    }