comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Best representation for spares
Date: Sun, 16 Feb 2014 18:33:35 +0200
Date: 2014-02-16T18:33:35+02:00	[thread overview]
Message-ID: <bmc7iuF7lbcU1@mid.individual.net> (raw)
In-Reply-To: <da3c94d8-b7eb-4390-a75e-291b9b3abe77@googlegroups.com>

On 14-02-16 15:40 , Rego, P. wrote:
> On Sunday, February 16, 2014 7:02:41 AM UTC-3, Niklas Holsti wrote:
>> Here you are "overlaying" a record object on a specific storage
>> location, presumably a memory-mapped I/O control register. This is OK,
>> but it has consequences...
> But is there a diffferent way to memory-map the registers?

You can use System.Address_To_Access_Conversions to create a reference
(pointer, access) to the memory address, and then use that pointer:

    package Conversions is new System.Address_To_Access_Conversions (
       Object => Mem_Mapped_Reg_T);

    Ptr : Conversions.Object_Pointer :=
       Conversions.To_Pointer (System'To_Address (16#.....#));

    Reg : Mem_Mapped_Reg_T;

    Reg := Ptr.all;
    ...
    Ptr.all := Reg;

>> If the Spare bits are documented as "reserved", there should
>> not be any need to initialize just them...
> 
> There are some points in datasheet which are a little confusing,
> it says the spare is "reserved", but also says "write zero" in
> some cases (not all).

The bits are typically "reserved" because some later version of the HW
may define some meaning for them, for example to activate some advanced
HW functions that are not available now.

Usually, in order to write anything to a MMIO register, the program has
to write the *entire* register at once, using a word-sized memory-store
instruction. Writing only one bit, or only some other part of the
register, is not usually supported by the HW (except on some small
microcontrollers with bit-addressed memory). This means that you cannot
avoid writing the reserved bits too. The datasheet is saying that you
should write zeroes to the reserved bits, and then nothing bad will
happen even in the future -- no new surprising effects will happen even
if the program is executed in some new version of the HW where the
reserved bits have been given some new functions.

It does not mean (usually) that you *must* initialize these bits to
zero; it means that writing zero is safe, while writing something else
may not be.

> I did not get. Is is better to use
> Auxiliary_Peripherals_Register_Map: 
>    Auxiliary_Peripherals_Register_Map_Type 
>       := (others => <>);
> or just initialize in system initialization?

I would initialize only in the system init, using an assignment
statement. Using either an overlay, or a pointer from
Address_To_Access_Conversions. The pointer method has the advantage that
you can then default-initialize Spares, and it will work:

   Reg_Init : Memory_Mapped_Reg_T;
   ...
   Reg_Init.X := ...;
   Reg_Init.Y := ...;

   Ptr.all := Reg_Init;

Reg_Init.Spares can be default initialized (e.g. to zero), and those
zeroes will be written to Ptr.all. But I would probably write use an
aggregate expression, and not a variable:

   Ptr.all := (X => ..., Y => ..., Spares => ...);

and not bother with default initializations.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

  parent reply	other threads:[~2014-02-16 16:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14  1:07 Best representation for spares Rego, P.
2014-02-14  9:19 ` Simon Wright
2014-02-15 16:06   ` Rego, P.
2014-02-15 17:49     ` Jeffrey Carter
2014-02-15 20:21       ` Rego, P.
2014-02-15 19:55     ` Niklas Holsti
2014-02-15 20:25       ` Rego, P.
2014-02-15 21:35         ` Rego, P.
2014-02-16 10:02           ` Niklas Holsti
2014-02-16 13:40             ` Rego, P.
2014-02-16 16:26               ` Rego, P.
2014-02-16 18:50                 ` Niklas Holsti
2014-02-16 16:33               ` Niklas Holsti [this message]
2014-02-16 12:10           ` Simon Wright
2014-02-16 13:43             ` Rego, P.
2014-02-16 14:25               ` Robert A Duff
2014-02-16 16:21                 ` Rego, P.
2014-02-15 21:41         ` Jeffrey Carter
2014-02-15 22:37           ` Rego, P.
2014-02-15 22:41             ` Rego, P.
2014-02-16  0:39             ` Jeffrey Carter
2014-02-16 12:06         ` Simon Wright
2014-02-16 13:45           ` Rego, P.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox