File: /home/oboss/Users/gec/sources/Basic_Services/Low_Level_Stuff/basic_types.ads

1     --% Compilation Unit: Basic_Types
2     --
3     --% Category: Package Declaration
4     --
5     --% Release:  $Name:  $
6     --
7     --% Version:  $Revision: 2.3 $
8     --
9     --% Author:   $Author: gec $
10     --
11     --% Revision Log:
12     --    $Log: basic_types.ads,v $
13     --    Revision 2.3  2003/11/13 14:57:33  gec
14     --    Merged ECSS Migration branch to main trunk.
15     --
16     --    Revision 2.2.2.1  2003/11/10 10:01:58  gec
17     --    Eliminated pseudo-implementation of IEEE reals.
18     --
19     --    Revision 2.2  2003/10/21 12:27:40  gec
20     --    Eliminated comments referring to Alsys compiler.
21     --
22     --    Revision 2.1  2003/10/21 08:44:43  gec
23     --    Merged STADY_Recommendations branch onto trunk.
24     --    Contains numerous updates resulting from STADY fault descriptions.
25     --
26     --    Revision 2.0.2.1  2003/10/20 10:14:48  gec
27     --    Introduced common Bit_Size_To_Byte_Size operation in Basic_Types.
28     --    Eliminated redundant version in External_PUS_State and
29     --+    Source_Data_Stream.
30     --
31     --    Response to STADY fault description fault 69.
32     --
33     --    Revision 2.0  2003/04/04 08:50:04  gec
34     --    Initial release of source files serving as baseline for OBOSS-III
35     --+    project.
36     --
37     --    Revision 1.1.1.1  2003/04/04 08:13:02  gec
38     --    Imported using TkCVS
39     --
40     --
41     --
42     --% Project: OBOSS
43     --
44     --% Copyright (C) 2003 by Terma A/S
45     --  Proprietary and intellectual rights of Terma A/S, Denmark,
46     --  are involved in the subject-matter of this material and
47     --  all manufacturing, reproduction, use, disclosure, and
48     --  sales rights pertaining to such subject-matter are
49     --  expressly reserved. This material is submitted for a
50     --  specific purpose as agreed, and the recipient by
51     --  accepting this material agrees that this material will
52     --  not be used, copied, or reproduced in whole or in part
53     --  nor its contents revealed in any manner or to any person,
54     --  except to meet the purpose for which it was submitted and
55     --  subject to the terms of the agreement.
56     --
57     --% Target Dependencies:
58     --    None
59     --% Compiler Dependencies:
60     --    None
61     
62     --~-----------------------------------------------------------------------------
63     
64     package Basic_Types is
65     
66        --% Library Package:
67        --    Collection of basic type declarations and associated operations.
68        --    Used for definiton of other types throughout the system.
69        --    Encapsulates compiler and platform specific representations.
70        --
71        --% Active Tasks:
72        -->   None
73        --% Passive Tasks:
74        -->   None
75     
76        -- Exception indicating that result of a subtraction of two on-board times
77        --+    cannot be represented as a relative time
78        Time_Span_Too_Large : exception;
79     
80        -- Exception indicating that a relative on-board time is too large to be
81        --+    represented as a duration
82        Relative_Time_Too_Large : exception;
83     
84        -- Raised when applying binary operations to on-board times with un-equal
85        --+    time representation specs
86        Incompatible_Time_Representations : exception;
87     
88        -- Exception indicating that a CUC time could not be made to conform with
89        --+    its Time_Rep_Spec
90        CUC_Time_Not_Conforming : exception;
91     
92        ---------------------------------------------------
93        -- Definition of number of bits used for representation
94        Nibble_Size : constant := 4;
95        Byte_Size   : constant := 8;
96        Word_Size   : constant := 2 * Byte_Size;
97        Triple_Size : constant := 3 * Byte_Size;
98        DWord_Size  : constant := 2 * Word_Size;
99     
100        ---------------------------------------------------
101        -- Definition of bit strings
102     
103        -- Bit strings are the lowest level representation
104        -- Indexes allow for empty bit strings
105     
106        type Bit_String_Index is new Natural;
107     
108        type Bit is range 0 .. 1;
109        for Bit'Size use 1;
110     
111        type Bit_String is array (Bit_String_Index range <>) of Bit;
112        pragma Pack (Bit_String);
113     
114        -- Type designating object sizes in bits
115     
116        type Bit_Size is new Natural;
117     
118        --% Subprogram:
119        --    Transforms a size in bits into a size expressed as a number of bytes.
120        --    Truncates to successor integer.
121        --% Parameter Constraints:
122        -->   None
123        --% Exceptions Raised:
124        -->   None
125     
126        function Bit_Size_To_Byte_Size
127              (Size_In_Bits :        Bit_Size)
128              return Natural;
129     
130        ---------------------------------------------------
131        -- Definition of unsigned integer types
132     
133        type Long_Integer is new Standard.Integer;           -- Port to 32 bit
134                                            --+    architecture
135     
136        type Nibble is range 0 .. 2**Nibble_Size - 1;
137        for Nibble'Size use Nibble_Size;
138     
139        type Byte is range 0 .. 2**Byte_Size - 1;
140        for Byte'Size use Byte_Size;
141     
142        type Word is range 0 .. 2**Word_Size - 1;
143        for Word'Size use Word_Size;
144     
145        type Triple is range 0 .. 2**Triple_Size - 1;
146        for Triple'Size use Triple_Size;
147     
148        type DWord is
149           record
150              Most_Sig_Word, Least_Sig_Word : Word;
151           end record;
152     
153        for DWord use
154           record
155              Most_Sig_Word  at 0 range 0 .. Word_Size - 1;
156              Least_Sig_Word at 0 range Word_Size .. 2 * Word_Size - 1;
157           end record;
158        for DWord'Size use DWord_Size;
159     
160        ---------------------------------------------------
161        -- Operations on DWord
162     
163        --% Subprogram:
164        --    Ordering relations on double words.
165        --% Parameter Constraints:
166        -->   None
167        --% Exceptions Raised:
168        -->   None
169        function "<"
170              (Dw_1, Dw_2 :        DWord)
171              return Boolean;
172        function ">"
173              (Dw_1, Dw_2 :        DWord)
174              return Boolean;
175     
176        ---------------------------------------------------
177        -- Definition of signed integer types
178     
179        type Signed_Byte is range -2**(Byte_Size - 1) .. 2**(Byte_Size - 1) - 1;
180        for Signed_Byte'Size use Byte_Size;
181     
182        type Signed_Word is range -2**(Word_Size - 1) .. 2**(Word_Size - 1) - 1;
183        for Signed_Word'Size use Word_Size;
184     
185        type Signed_Triple is range
186              -2**(Triple_Size - 1) .. 2**(Triple_Size - 1) - 1;
187        for Signed_Triple'Size use Triple_Size;
188     
189        subtype Signed_DWord is Long_Integer;
190     
191        ---------------------------------------------------
192        -- Definition of reals according to AONIX ERC32 cross-compiler
193     
194        type Single_Precision_Real is new Float;
195        type Double_Precision_Real is new Long_Float;
196     
197        ---------------------------------------------------
198        -- Collection of canonical types used for internal representation of PUS
199        --+    parameter values.
200     
201        subtype Bool             is Boolean;
202        subtype Enumerated       is Long_Integer;
203        subtype Unsigned_Integer is Long_Integer range 0 .. Long_Integer'Last;
204        subtype Signed_Integer   is Long_Integer;
205     
206        subtype Octet is Byte;
207     
208        subtype Char is Character;
209     
210        ---------------------------------------------------
211        -- Implementation of IEEE single precision float and double precision float.
212        --+
213        -- On GNAT/ORK Platform, IEEE floats are directly supported
214     
215        -- Single precision IEEE real
216        type IEEE_Single_Precision_Float is new Short_Float; -- GNAT/ORK Specific
217     
218        -- Double precision IEEE real
219        type IEEE_Double_Precision_Float is new Long_Float; -- GNAT/ORK Specific
220     
221     
222        ---------------------------------------------------
223        -- Definition of list of bytes.
224     
225        type Byte_Array is array (Natural range <>) of Byte;
226        pragma Pack (Byte_Array);
227     
228        ---------------------------------------------------
229        -- Definition of on board time and on board relative time
230     
231        On_Board_Coarse_Time_Byte_Size : constant := 4;
232        subtype On_Board_Coarse_Time is
233              Byte_Array (1 .. On_Board_Coarse_Time_Byte_Size);
234     
235        On_Board_Fine_Time_Byte_Size : constant := 3;
236        subtype On_Board_Fine_Time is
237              Byte_Array (1 .. On_Board_Fine_Time_Byte_Size);
238     
239        -- Absolute on-board time
240        -- Coarse time unit = second
241        -- Fine time unit = 256 ** -3
242     
243        On_Board_Time_Delta : constant := 256.0**(-On_Board_Fine_Time_Byte_Size);
244     
245        -- An On Board time T corresponds to the following in seconds:
246        --    T.Coarse_Time + T.Fine_Time * 256 ** (-3)
247     
248        type Time_Component_Rep_Spec is range 0 .. 2**2 - 1;
249     
250        type Time_Rep_Spec is
251           record
252              Coarse_Time_Rep : Time_Component_Rep_Spec; --coarse time byte size - 1
253                                                  --+
254              Fine_Time_Rep   : Time_Component_Rep_Spec; --fine time byte size
255           end record;
256     
257        type On_Board_Time is
258           record
259              P_Field     : Time_Rep_Spec;
260              Coarse_Time : On_Board_Coarse_Time;
261              Fine_Time   : On_Board_Fine_Time;
262           end record;
263     
264        -- Relative on-board time
265        -- Implemented using on board time.
266        -- Special interpretation for values with Coarse_Time > 16#8000_0000#
267        -- These represents 2's complement of negative values
268     
269        subtype Relative_On_Board_Time is On_Board_Time;
270     
271        ---------------------------------------------------
272        -- Operations on On Board Time
273     
274        --% Subprogram:
275        --    Transformations from Long Integers to on-board coarse time and
276        --+    on-board fine time
277        --% Parameter Constraints:
278        -->   None
279        --% Exceptions Raised:
280        -->   None
281        function Make_On_Board_Coarse_Time
282              (I :        Long_Integer)
283              return On_Board_Coarse_Time;
284        function Make_On_Board_Fine_Time
285              (I :        Long_Integer)
286              return On_Board_Fine_Time;
287     
288        --% Subprogram:
289        --    Transformation of a general CUC time to one satisfying its time
290        --+    representation specification
291        --% Parameter Constraints:
292        -->   None
293        --% Exceptions Raised:
294        -->   CUC_Time_Not_Conforming - CUC_Time is too large to be represented
295        --+    according to its P_Field
296        function Make_CUC_Representation_Conform
297              (CUC_Time :        On_Board_Time)
298              return On_Board_Time;
299     
300        --% Subprogram:
301        --    Transformation from Duration to on-board fine time.
302        --    Added to interface to GNAT Real_Time package.
303        --% Parameter Constraints:
304        -->   D - Shall be positive
305        --% Exceptions Raised:
306        -->   None
307        function Duration_To_Fine_Time
308              (D :        Duration)
309              return On_Board_Fine_Time;
310     
311        --% Subprogram:
312        --    Temporal ordering relation on absolute times
313        --    T1 < T2 iff T1 designates an earlier time than T2
314        --% Parameter Constraints:
315        -->   None
316        --% Exceptions Raised:
317        -->   None
318        function "<"
319              (T1, T2 : in     On_Board_Time)
320              return Boolean;
321     
322        --% Subprogram:
323        --    Relative time from T1 to T2
324        --% Parameter Constraints:
325        -->   T1 and T2 - Both operands must have the same representation (i.e.
326        --+    identical p-fields).
327        --% Exceptions Raised:
328        -->   Incompatible_Time_Representations - RT and T have differing time
329        --+    representation (P-fields).
330        -->   Time_Span_Too_Large - Resulting relative time is too large to be
331        --+    represented according to the P-field in T1 and T2.
332        function "-"
333              (T2, T1 : in     On_Board_Time)
334              return Relative_On_Board_Time;
335     
336        --% Subprogram:
337        --    Absolute time after interval RT with reference to absolute time T.
338        --    Resulting time will have same time representation (p-field) as T.
339        --% Parameter Constraints:
340        -->   T and RT - Both operands must have the same representation (i.e.
341        --+    identical p-fields).
342        --% Exceptions Raised:
343        -->   Incompatible_Time_Representations - RT and T have differing time
344        --+    representation (P-fields).
345        -->   Time_Span_Too_Large - Resulting absolute time is too large to be
346        --+    represented according to the P-field in T.
347        function "+"
348              (T  :        On_Board_Time;
349               Rt :        Relative_On_Board_Time)
350              return On_Board_Time;
351     
352        --% Subprogram:
353        --    Transformation from relative on-board times to Ada durations.
354        --% Parameter Constraints:
355        -->   None
356        --% Exceptions Raised:
357        -->   Relative_Time_Too_Large - T is too large to be represented as
358        --+    Standard.Duration.
359        function To_Duration
360              (T : in     Relative_On_Board_Time)
361              return Standard.Duration;
362     
363        --% Subprogram:
364        --    Transformation from Ada durations to relative on-board times.
365        --% Parameter Constraints:
366        -->   None
367        --% Exceptions Raised:
368        -->   None
369        function Make_Relative_On_Board_Time
370              (T_Rep :        Time_Rep_Spec;
371               D     :        Duration)
372              return Relative_On_Board_Time;
373     
374     end Basic_Types;
375     
376     --~-----------------------------------------------------------------------------
377