I have a register definition provided by the microcontroller manufacturer that can be handled as a bit field. The register is defined as follows:
#define SCU_WDTSCON0 (*( SCU_WDTSCON0_type *) 0xf00360f0u)
The bit field definition looks like this:
typedef volatile union {
unsigned U;
int I;
struct {
unsigned ENDINIT :1; // [0:0] End-of-Initialization Control Bit
unsigned LCK :1; // [1:1] Lock Bit to Control Access to WDTxCON0
unsigned HPW0 :2; // [3:2] Hardware Password 0
unsigned HPW1 :4; // [7:4] Hardware Password 1
unsigned PW :8; // [15:8] User-Definable Password Field for Access to WDTxCON0
unsigned REL :16; // [31:16] Reload Value for the WDT
} B;
} SCU_WDTSCON0_type;
Instead of directly writing to the register, I want to use a uint32 buffer variable first, but still be able to edit it in the manner of the register bit field definition. This implementation seems to be working, as the address is just replaced with &buffer_variable:
volatile uint32 buffer_variable;
SCU_WDTSCON0_type register_buffer = (*( SCU_WDTSCON0_type *) &buffer_variable);
Could this lead to undefined behavior?