From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9dec3ff1604723d9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: Bitordering? was Re: Bitmanipulation in Ada Date: Mon, 23 Aug 2004 23:39:47 +0100 Message-ID: References: <412665C4.E52A7590@alfred-hilscher.de> <412A3BAE.CE8EC07B@alfred-hilscher.de> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de jStcVrU3qXP57IoMHeFsCAFyYpykzHLiM1+NaxrVGrRn8mgCU= User-Agent: Opera M2/7.54 (Win32, build 3865) Xref: g2news1.google.com comp.lang.ada:2944 Date: 2004-08-23T23:39:47+01:00 List-Id: On Mon, 23 Aug 2004 20:47:10 +0200, Alfred Hilscher wrote: >> Does this help you? > > Yes it does. Although it is not what I expected. > ... > Is this correct? In essence, yes. > Ok, it is a bit more to write, but this should not matter. Exactly. The Ada ethic is that the clarity of the code matters more than its conciseness. I'd suggest you declare the record type like this: with System; ... type Status_Flags is record Buffer_Empty, Overrun, Parity_Error, Frame_Error, Timed_Out, Break_Detected, Receiving, Idle: Boolean; end record; for Status_Flags'Size use 8; for Status_Flags'Bit_Order use System.Low_Order_First; for Status_Flags use record Buffer_Empty at 0 range 7..7; Overrun at 0 range 6..6; Parity_Error at 0 range 5..5; Frame_Error at 0 range 4..4; Timed_Out at 0 range 3..3; Break_Detected at 0 range 2..2; Receiving at 0 range 1..1; Idle at 0 range 0..0; end record; Note that I have numbered the bits here so that the LSB is 0 and the MSB is 7. If it would be more convenient for you to have it the other way round, change System.Low_Order_First to System.High_Order_First. Please check that the right flags are associated with the right bits! You could write a clarifying function such as: function Shows_Error (Flags: in Status_Flags) return Boolean is begin return Flags.Buffer_Empty or Flags.Overrun or Flags.Parity_Error or Flags.Frame_Error or Flags.Timed_Out or Flags.Break_Detected; end; You might declare a memory-mapped port like this: Status: Status_Flags; for Status'Address use 16#0004#; pragma Volatile(Status); You could handle status values using an 'if' structure such as: if Shows_Error(Status) then if Status.Buffer_Empty then ... elsif Status.Overrun then ... elsif Status.Parity_Error then ... elsif Status.Frame_Error then ... elsif Status.Timed_Out then ... elsif Status.Break_Detected then ... end if; else if Status.Receiving then ... elsif Status.Idle then ... else ... end if; end if; Note that these nested 'if' statements do not necessarily have the structure that meets the required logic of your program (you will have to work that out yourself). It is merely an illustration. HTH -- Nick Roberts