comp.lang.ada
 help / color / mirror / Atom feed
From: "Rego, P." <pvrego@gmail.com>
Subject: Re: Best representation for spares
Date: Sun, 16 Feb 2014 05:40:11 -0800 (PST)
Date: 2014-02-16T05:40:11-08:00	[thread overview]
Message-ID: <da3c94d8-b7eb-4390-a75e-291b9b3abe77@googlegroups.com> (raw)
In-Reply-To: <bmbglvF2nlgU1@mid.individual.net>

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?

> The compiler is warning you that the initialization of the Spare
> component will take place during the elaboration of the declaration of
> Auxiliary_Peripherals_Register_Map, which is usually not what one wants
> to happen with memory-mapped I/O registers. Usually, such registers are
> initialized by explicit assignment statements later on, in the system
> initialization procedure.

Yes, I was thinking about it. I think it's better to not initialize the spares in the type definition and include this in the system initialization. You are right.

> > But in this case I do not want to suppress initialization.
> Why not? If the Spare bits are documented as "reserved", there should
> not be any need to initialize just them, and your record type (the one
> that is declared in the quote) does not default-initialize any other
> components, which means that the default initialization gives them some
> garbage values. Or leaves them unchanged, if it can write only to the
> Spare bits (unlikely, and partial-word access to mmio registers is
> usually not desirable anyway -- look into using the Atomic aspect for
> such objects).

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).

> > What to do to eliminate this warning?
> You can suppy an explicit initialization in the object declaration, even
> one using the default initial values for all components:
> Auxiliary_Peripherals_Register_Map:
>    Auxiliary_Peripherals_Register_Map_Type
>       := (others => <>);
> --    ^^^^^^^^^^^^^^^^^^
> --    Explicit initialization using default initial values.
Ok Fine.

> for Auxiliary_Peripherals_Register_Map'Address use
>    System'To_Address (16#7E21_5000#);
> However, this assigns *unknown* values to the components without default
> initial values, that is, the xxx_IRQ components. You probably want to
> initialize these components to False, to avoid spurious invocation of
> the interrupt handlers.
> I would not put any default initializations in record types that I
> intend to overlay onto mmio registers.

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?
(or both?)

> That is a default initialization. As the RM says, if the object is
> imported, the default initialization is not done, just as if you had
> declared the component without it, as
>    Spare : Zero_Bits (3 .. 31);
> Moreover, the RM section you quote makes it illegal to give an explicit
> initialization (as in my example above) for an imported object. Thus, to
> "initialize" an imported object, you must use an ordinary assignment
> statement. The declaration of an imported object cannot initialize it.

Ok.

--
Regards,
Rego.


  reply	other threads:[~2014-02-16 13:40 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. [this message]
2014-02-16 16:26               ` Rego, P.
2014-02-16 18:50                 ` Niklas Holsti
2014-02-16 16:33               ` Niklas Holsti
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