From: awdorrin <awdorrin@gmail.com>
Subject: Endianness and Record Specification
Date: Fri, 21 Sep 2012 11:16:43 -0700 (PDT)
Date: 2012-09-21T11:16:43-07:00 [thread overview]
Message-ID: <a0647230-14c8-4ece-8ed6-d23bdf130776@googlegroups.com> (raw)
I have been reading over google searches all day and I feel like I'm missing something here.
Is there a straight forward method to use Standard'Default_Bit_Order to define a specification for a record, that will work on either a Little Endian or Big Endian system?
For instance, I have a 16-bit field that is comprised of 5 bit-fields:
Reserved: 1 bit
Error Flag: 1 bit
Word Count: 6 bits
Bus Id: 1 bit
Message Type: 7 bits
So, 0x0401 is [0000 0100 0000 0001] or [0][0][000100][0][0000001]
Word Count = 4, Message Type = 1
On a Big Endian system the record is defined as:
type TW_REC is record
Message : Integer;
BusId : Integer;
WordCount : Integer;
Error : Integer;
Reserved : Integer;
end record
for TW_REC use record
Reserved at 0 range 0..0;
Error at 0 range 1..1;
WordCount at 0 range 2..7;
BusId at 1 range 0..0;
Message at 1 range 1..7;
end record;
Now, I know I can rewrite this on a Little Endian system to:
for TW_REC'Bit_Order use System.High_Order_First;
for TW_REC use record
Reserved at 1 range 0..0;
Error at 1 range 1..1;
WordCount at 1 range 2..7;
BusId at 0 range 0..0;
Message at 0 range 1..7;
end record;
Taking advantage of the High_Order_First flag to keep the bit ordering the same,
but is there a way to either calculate the byte position, or 'conditionally compile' the right record specification, depending on the system on which it is being compiled?
At first I was thinking I could do:
if Standard'Default_Bit_Order = 1 then
-- defined Little endian rec spec
else
-- define Bit endian rec spec
end if;
But, the compiler doesn't let me do that... :-)
I would think I should be able to somehow use the Default_Bit_Order to define some sort of relative byte position, depending on the system endianness, but I'm drawing a blank and hoping someone might have a quick example they could provide.
Thanks!
-Al
next reply other threads:[~2012-09-21 18:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-21 18:16 awdorrin [this message]
2012-09-21 19:21 ` Endianness and Record Specification awdorrin
2012-09-22 3:07 ` Stephen Leake
2012-09-21 22:18 ` Simon Wright
2012-09-22 7:43 ` Quentin Ochem
2012-10-23 21:08 ` awdorrin
2012-10-24 10:20 ` Stephen Leake
2012-11-02 13:13 ` awdorrin
2012-12-04 17:17 ` Anh Vo
2012-12-04 17:37 ` Niklas Holsti
2012-12-04 18:31 ` Anh Vo
2012-12-04 23:31 ` Randy Brukardt
2012-12-05 0:12 ` Anh Vo
2012-12-05 2:00 ` Jeffrey Carter
2012-12-05 3:40 ` Anh Vo
2012-09-22 9:32 ` Robin Vowels
2012-09-22 9:59 ` Dmitry A. Kazakov
2012-09-24 2:44 ` Robin Vowels
2012-09-24 7:48 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox