I'm supposed to write multiple fields in a register. The vendor "API" is a struct mapped to a memory address. The struct looks something like this:
typedef struct
{
unsigned Reg_A : 28;
unsigned Reg_B : 1;
unsigned Reg_C : 3;
}RegisterFooFields;
typedef union
{
unsigned U;
RegisterFooFields B;
}RegisterFoo;
I'm supposed to write all of A, B, and C atomically, as one constrains the other. Does C guarantee that to happen if I assign to RegisterFoo.B?
RegsiterFooFields fields = {.A = 123, .B = 0, .C = 0b10};
RegisterFooAddress->B = fields; /* Is this an atomic write (mov) operation? */
My environment is C99, 32-bit.
EDIT:
RegisterFooAddress is declared volatile.
EDIT 2:
What I'm afraid for is the compiler generating a series of assignments for each field, masked appropriately, resulting in a transient register state where (e.g.) Reg_A has been updated but Reg_B and Reg_C have not, leading to the hardware possibly reading the transient state.
Reading the generated assembly is not feasible in case of aggressive optimization, possibly inlining the code.