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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fd6dd,c78177ec2e61f4ac X-Google-Attributes: gidfd6dd,public X-Google-Thread: 103376,c78177ec2e61f4ac X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: ada and robots Date: 1997/06/29 Message-ID: #1/1 X-Deja-AN: 253487792 References: <338CDA96.53EA@halcyon.com> <338F5D7D.6C03@tiac.net> <338F9D05.5EB3@bix.com> <5mqpj3$bc5$1@goanna.cs.rmit.edu.au> <33930245.12A1@sprintmail.com> <5mv984$7kn@news.emi.com> <33A5D644.37A3@epix.net> <33A69E46.3230@gsfc.nasa.gov> <33AAC183.34C0@xtra.co.nz> Organization: Estormza Software Newsgroups: comp.robotics.misc,comp.lang.ada Date: 1997-06-29T00:00:00+00:00 List-Id: In article <33AAC183.34C0@xtra.co.nz>, DesignTools@xtra.co.nz wrote: I'm not a Modula programmer; perhaps you can walk me through some of your code examples. >This code uses the BITSET feature of Modula-2, to greate a PACKED >BOOLEAN >ARRAY of 24 Data bits, into 3 BYTES. This can be done in Ada. type Bit_Array is array (Positive range 0 .. 23) of Boolean; for Bit_Array'Size use 24; for Bit_Array'Component_Size use 1; or in this case you could just pragma Pack (Bit_Array); Ada guarantees that for an array for which the component size is 1 (and type Boolean is guaranteed to be size 1), that array components are aligned on contiguous bits. > CASE BitTimeL OF > | OneMIN..OneMAX : > INCL(RxCODE[RxCtr >> 3],RxCtr); > | ZeroMIN..ZeroMAX : (* default is a Zero *) > ELSE (* bad value, so reset *) > TF0 := TRUE; (* catch Reset, next pass *) > RxCtr := 0; > END; > INC(RxCtr); Can you explain what's going on here? INCL means add an item to a set, right? If so, you just set the corresponding bit of the bit array to True. Of course, we could declare a full-blown set abstract data type, implemented as a bit array, but when you're twiddling bits anyway, one doesn't usually bother. >This code illustrates two methods of loading, one 'collects' BOOLEANs >and >is highly readable, the other uses BINARY format. > IE := {EA,ET0,ES}; > IE := 2#1001_0010; (* EA.EC.ET2.ES.ET1.EX1.ET0.EX0 *) type Bit_Array_Range is (EA, EC, ET2, ES, ET1, EX1, ETO, EXO); type Bit_Array is array (Bit_Array_Range) of Boolean; pragma Pack (Bit_Array); To do the first, you can use aggregate assignment: IE : Bit_Array := (EA, ETO, ES => True, others => False); To do the second, you have to use unchecked conversion: function To_Bit_Array is new Unchecked_Conversion ( Source => Interfaces.Unsigned_8, Target => Bit_Array); IE : Bit_Array := To_Bit_Array (2#1001_0010#); Oh well, an extra line of code, to do the instantiation. >This code is from a DUAL 6 BIT Picket fence D to A converter. >Total code, for Dual DAC is 95 bytes. >It allows appx 33KHz clock rates, and can run as a background DAC. >More, or less, BITS / Channels are easy to add / remove. >Such DACs are highly linear, use just 1 PIN per DAC, and are ideal for >integration to control voltage outputs. > DACa := DAC_A.5; (* Uses BYTE BITADDRESSABLE syntax *) If you mean get at an individual bit, that can be done if the type is already declared as a bit array, or else using unchecked_conversion to a bit array. DAC_A (5) or To_Bit_Array(DAC_A)(5) You may need an extra pair of parens here; I don't have my Ada 95 compiler handy. >This code flips the BIT order in a BYTE, for COMMS protocol usage. >TYPE hT = ARRAY [0..15] OF BYTE; > (* 0 1 2 3 4 5 6 7 8 9 A B C D E F >*) >CONST MirrorTable = >hT(0H,08H,04H,0CH,02H,0AH,6,0EH,1,9,5,0DH,3,0BH,7,0FH); > >PROCEDURE MirrorF(Par : SHORTCARD REGISTER_2) : SHORTCARD; (* 16 >bytes,14uS *) >BEGIN > RETURN(ROTATE(MirrorTable[Par AND 0FH],4) OR MirrorTable[Par >> 4]); >END MirrorF; type hT is array (0 .. 15) of Unsigned_8; -- we may have to declare the array index subtype as a modular type -- ie type hT is array (Unsigned_8) of Unsigned_8; -- but I've never done that, and I don't have my compiler handy... Mirror_Table : constant hT := (16#0#, 16#8#, ...); function Mirror_F (Par : Unsigned_8) return Unsigned_8 is begin return Rotate_Right (Mirror_Table (Par and 16#0F#), 4) or Mirror_Table (Shift_Right (Par, 4)); end; or something like that. If my knowledge of Modula were better (I only have Wirth's book, which I haven't even read), there might be a slicker Ada way to do this, instead of as a straight translation. The point is, however, that Ada is no less expressive than Modula with respect to its low-level facilities. Nor do I suppose its code generation is any less efficient, if the types in package Interfaces are used. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271