comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Representation clauses and side-efects on STM32F411 ravenscar runtime
Date: Sun, 02 Aug 2015 10:40:33 +0100
Date: 2015-08-02T10:40:33+01:00	[thread overview]
Message-ID: <lya8uaowoe.fsf@pushface.org> (raw)
In-Reply-To: 55bddbe2$0$3384$426a74cc@news.free.fr

Frédéric Praca <frederic.praca@free.fr> writes:

> I was expecting the compiler (GNAT GPL 2014 (20140331) from Adacore
> under Linux x64) to handle all and, or and xor operations by itself
> for such kind of representation. Was I wrong ?

I think you should declare Baud_Rate_Register as Volatile in any case.
But there was a discussion here about this recently; Volatile doesn't
guarantee any sort of full word access (or half word; how would the
compiler know?).

AdaCore recently included aspect Volatile_Full_Access[1] which is
supposed to do what you want.

GNAT GPL 2015 recognises this aspect; FSF GCC 5.1.0 doesn't (I haven't
looked into 5.2.0 yet, but AdaCore typically only fix serious bugs in
subreleases).

Failing that, the recommended technique to change one component is to
use a temporary:

declare
   BRR : Baud_Rate_Register := USART2.BRR;
begin
   BRR.DIV_Mantissa := 16#445#;
   USART2.BRR := BRR;
end;

but of course if you're changing all the components your whole record
assignment will do the trick.

In any case, a whole record assignment is better practice, because it
means the compiler won't let you forget to assign a component.

[1] http://www.adacore.com/developers/development-log/NF-74-M715-002-gnat/


  reply	other threads:[~2015-08-02  9:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-02  8:59 Representation clauses and side-efects on STM32F411 ravenscar runtime Frédéric Praca
2015-08-02  9:40 ` Simon Wright [this message]
2015-08-02 10:22   ` Simon Wright
2015-08-02 14:53     ` Frédéric Praca
2015-08-02 14:52   ` Frédéric Praca
2015-08-02 15:19     ` Simon Wright
2015-08-02 19:23 ` Jeffrey R. Carter
2015-08-02 19:54   ` Bob Duff
2015-08-02 20:01     ` Frédéric Praca
2015-08-02 20:13       ` Bob Duff
2015-08-02 20:27         ` Frédéric Praca
2015-08-02 20:31     ` Jeffrey R. Carter
2015-08-03 11:08 ` Simon Clubley
2015-08-15 14:22   ` Frédéric Praca
2015-08-15 15:33     ` Simon Clubley
2015-08-15 17:17       ` Frédéric Praca
replies disabled

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