Overview of Ada 2022
6.2 Exact size access to parts of composite atomic objects
Exact size access
to parts of composite atomic objects (AI12-0128-1)
specifies that memory accesses to subcomponents of an atomic composite
object must read or write the entire object (see RM
C.6).
For example:
type Status is
record
Ready : Boolean;
Length : Integer range 0 .. 15;
end record;
for Status use
record
Ready at 0 range 0 .. 0;
Length at 0 range 1 .. 5;
end record;
Status_Register : Status
with Address => ...,
Size => 32,
Atomic => True;
if Status_Register.Ready then -- Reads entire register
null;
end if;
Status_Register.Length := 10; -- Prereads entire register, then writes entire register.
This is useful for controlling accesses to memory
mapped device registers, which often require reads or writes to be to
the entire register.
© 2021, 2022 Jeff Cousins