comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Best representation for spares
Date: Sat, 15 Feb 2014 21:55:30 +0200
Date: 2014-02-15T21:55:30+02:00	[thread overview]
Message-ID: <bm9v1cFnkbaU1@mid.individual.net> (raw)
In-Reply-To: <8383f5d6-3f66-415b-ab3f-8801fa377a6b@googlegroups.com>

On 14-02-15 18:06 , Rego, P. wrote:
> On Friday, February 14, 2014 7:19:20 AM UTC-2, Simon Wright wrote:
>> I'd much prefer to fill this space. And, on the whole, better with zeros
>> (unless, of course, 'unused' means 'don't even write to this bit').
>> Something like
>>    type Zero_Bit is range 0 .. 0;
>>    type Zero_Bits is array (Positive range <>) of Zero_Bit;
>>    for Zero_Bits'Component_Size use 1;
>>    type Auxiliary_Interrupt_Status_Type is
>>       record
>>          Mini_Uart_IRQ : Boolean;
>>          SPI_1_IRQ     : Boolean;
>>          SPI_2_IRQ     : Boolean;
>>          Spare         : Zero_Bits (3 .. 31);
>>       end record;
>>    pragma Pack (Auxiliary_Interrupt_Status_Type);
>>    for Auxiliary_Interrupt_Status_Type'Size use 32;
> 
> Great, I will use this.

I wouldn't, not if the program will read the record from the HW. See below.

> Even more that the datasheet says 'Reserved, write zero,

"Write zero" implies, to me, that you definitely must declare record
components for these bits, if you are going to write the record to the
HW, and you must set the bits to zero before writing to HW.

If you instead leave a gap in the record you have no way to control what
values the bits in the gap have (except through Unchecked_Conversion,
which would be a dirty trick).

> read as don't care'.

That implies, to me, that the bits read from the HW are not necessarily
zero. If you declare these bits using the Zero_Bits type, and then read
the record from the HW, you can get an "invalid" value -- any '1' bits
will violate the constraint on Zero_Bit. This creates an inconsistency
in the state of your program, which is IMO risky.

I would declare these "reserved" bits with a type that can take any
value that the HW can produce.

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


  parent reply	other threads:[~2014-02-15 19:55 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 [this message]
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
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