summaryrefslogtreecommitdiffstats
path: root/cpukit/include/adainclude/rtems-object.adb
blob: 7be02ecd4c73971a62ac567846302f20a69ce42c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
--
--  RTEMS / Body
--
--  DESCRIPTION:
--
--  This package provides the interface to the RTEMS API.
--
--
--  DEPENDENCIES:
--
--
--
--  COPYRIGHT (c) 1997-2011.
--  On-Line Applications Research Corporation (OAR).
--
--  The license and distribution terms for this file may in
--  the file LICENSE in this distribution or at
--  http://www.rtems.org/license/LICENSE.
--

with Interfaces;           use Interfaces;
with Interfaces.C.Strings; use Interfaces.C.Strings;

package body RTEMS.Object is

   --
   --  Object Services
   --

   function Build_Name
     (C1   : in Character;
      C2   : in Character;
      C3   : in Character;
      C4   : in Character)
      return RTEMS.Name
   is
      C1_Value : RTEMS.Unsigned32;
      C2_Value : RTEMS.Unsigned32;
      C3_Value : RTEMS.Unsigned32;
      C4_Value : RTEMS.Unsigned32;
   begin

      C1_Value := Character'Pos (C1);
      C2_Value := Character'Pos (C2);
      C3_Value := Character'Pos (C3);
      C4_Value := Character'Pos (C4);

      return Interfaces.Shift_Left (C1_Value, 24) or
             Interfaces.Shift_Left (C2_Value, 16) or
             Interfaces.Shift_Left (C3_Value, 8) or
             C4_Value;

   end Build_Name;

   procedure Get_Classic_Name
     (ID     : in RTEMS.ID;
      Name   : out RTEMS.Name;
      Result : out RTEMS.Status_Codes)
   is
      function Get_Classic_Name_Base
        (ID   : RTEMS.ID;
         Name : access RTEMS.Name)
         return RTEMS.Status_Codes;
      pragma Import
        (C,
         Get_Classic_Name_Base,
         "rtems_object_get_classic_name");
      Tmp_Name : aliased RTEMS.Name;
   begin
      Result := Get_Classic_Name_Base (ID, Tmp_Name'Access);
      Name   := Tmp_Name;
   end Get_Classic_Name;

   procedure Get_Name
     (ID     : in RTEMS.ID;
      Name   : out String;
      Result : out RTEMS.Address)
   is
      function Get_Name_Base
        (ID     : RTEMS.ID;
         Length : RTEMS.Unsigned32;
         Name   : RTEMS.Address)
         return   RTEMS.Address;
      pragma Import (C, Get_Name_Base, "rtems_object_get_name");
   begin
      Name   := (others => ASCII.NUL);
      Result :=
         Get_Name_Base (ID, Name'Length, Name (Name'First)'Address);
   end Get_Name;

   procedure Set_Name
     (ID     : in RTEMS.ID;
      Name   : in String;
      Result : out RTEMS.Status_Codes)
   is
      function Set_Name_Base
        (ID   : RTEMS.ID;
         Name : chars_ptr)
         return RTEMS.Status_Codes;
      pragma Import (C, Set_Name_Base, "rtems_object_set_name");
      NameAsCString : constant chars_ptr := New_String (Name);
   begin
      Result := Set_Name_Base (ID, NameAsCString);
   end Set_Name;

   procedure Id_Get_API
     (ID  : in RTEMS.ID;
      API : out RTEMS.Unsigned32)
   is
      function Id_Get_API_Base
        (ID   : RTEMS.ID)
         return RTEMS.Unsigned32;
      pragma Import (C, Id_Get_API_Base, "rtems_object_id_get_api");
   begin
      API := Id_Get_API_Base (ID);
   end Id_Get_API;

   procedure Id_Get_Class
     (ID        : in RTEMS.ID;
      The_Class : out RTEMS.Unsigned32)
   is
      function Id_Get_Class_Base
        (ID   : RTEMS.ID)
         return RTEMS.Unsigned32;
      pragma Import
        (C,
         Id_Get_Class_Base,
         "rtems_object_id_get_class");
   begin
      The_Class := Id_Get_Class_Base (ID);
   end Id_Get_Class;

   procedure Id_Get_Node
     (ID   : in RTEMS.ID;
      Node : out RTEMS.Unsigned32)
   is
      function Id_Get_Node_Base
        (ID   : RTEMS.ID)
         return RTEMS.Unsigned32;
      pragma Import (C, Id_Get_Node_Base, "rtems_object_id_get_node");
   begin
      Node := Id_Get_Node_Base (ID);
   end Id_Get_Node;

   procedure Id_Get_Index
     (ID    : in RTEMS.ID;
      Index : out RTEMS.Unsigned32)
   is
      function Id_Get_Index_Base
        (ID   : RTEMS.ID)
         return RTEMS.Unsigned32;
      pragma Import
        (C,
         Id_Get_Index_Base,
         "rtems_object_id_get_index");
   begin
      Index := Id_Get_Index_Base (ID);
   end Id_Get_Index;

   function Build_Id
     (The_API   : in RTEMS.Unsigned32;
      The_Class : in RTEMS.Unsigned32;
      The_Node  : in RTEMS.Unsigned32;
      The_Index : in RTEMS.Unsigned32)
      return      RTEMS.ID
   is
      function Build_Id_Base
        (The_API   : RTEMS.Unsigned32;
         The_Class : RTEMS.Unsigned32;
         The_Node  : RTEMS.Unsigned32;
         The_Index : RTEMS.Unsigned32)
         return      RTEMS.ID;
      pragma Import (C, Build_Id_Base, "rtems_build_id");
   begin
      return Build_Id_Base (The_API, The_Class, The_Node, The_Index);
   end Build_Id;

   function Id_API_Minimum return  RTEMS.Unsigned32 is
      function Id_API_Minimum_Base return  RTEMS.Unsigned32;
      pragma Import
        (C,
         Id_API_Minimum_Base,
         "rtems_object_id_api_minimum");
   begin
      return Id_API_Minimum_Base;
   end Id_API_Minimum;

   function Id_API_Maximum return  RTEMS.Unsigned32 is
      function Id_API_Maximum_Base return  RTEMS.Unsigned32;
      pragma Import
        (C,
         Id_API_Maximum_Base,
         "rtems_object_id_api_maximum");
   begin
      return Id_API_Maximum_Base;
   end Id_API_Maximum;

   procedure API_Minimum_Class
     (API     : in RTEMS.Unsigned32;
      Minimum : out RTEMS.Unsigned32)
   is
      function API_Minimum_Class_Base
        (API  : RTEMS.Unsigned32)
         return RTEMS.Unsigned32;
      pragma Import
        (C,
         API_Minimum_Class_Base,
         "rtems_object_api_minimum_class");
   begin
      Minimum := API_Minimum_Class_Base (API);
   end API_Minimum_Class;

   procedure API_Maximum_Class
     (API     : in RTEMS.Unsigned32;
      Maximum : out RTEMS.Unsigned32)
   is
      function API_Maximum_Class_Base
        (API  : RTEMS.Unsigned32)
         return RTEMS.Unsigned32;
      pragma Import
        (C,
         API_Maximum_Class_Base,
         "rtems_object_api_maximum_class");
   begin
      Maximum := API_Maximum_Class_Base (API);
   end API_Maximum_Class;

   -- Translate S from a C-style char* into an Ada String.
   -- If S is Null_Ptr, return "", don't raise an exception.
   -- Copied from Lovelace Tutorial
   function Value_Without_Exception (S : chars_ptr) return String is
   begin
      if S = Null_Ptr then
         return "";
      else
         return Value (S);
      end if;
   end Value_Without_Exception;
   pragma Inline (Value_Without_Exception);

   procedure Get_API_Name
     (API  : in RTEMS.Unsigned32;
      Name : out String)
   is
      function Get_API_Name_Base
        (API  : RTEMS.Unsigned32)
         return chars_ptr;
      pragma Import
        (C,
         Get_API_Name_Base,
         "rtems_object_get_api_name");
      Result  : constant chars_ptr := Get_API_Name_Base (API);
      APIName : constant String    := Value_Without_Exception (Result);
   begin
      Name := APIName;
   end Get_API_Name;

   procedure Get_API_Class_Name
     (The_API   : in RTEMS.Unsigned32;
      The_Class : in RTEMS.Unsigned32;
      Name      : out String)
   is
      function Get_API_Class_Name_Base
        (API   : RTEMS.Unsigned32;
         Class : RTEMS.Unsigned32)
         return  chars_ptr;
      pragma Import
        (C,
         Get_API_Class_Name_Base,
         "rtems_object_get_api_class_name");
      Result    : constant chars_ptr :=
         Get_API_Class_Name_Base (The_API, The_Class);
      ClassName : constant String    := Value_Without_Exception (Result);
   begin
      Name := ClassName;
   end Get_API_Class_Name;

   procedure Get_Class_Information
     (The_API   : in RTEMS.Unsigned32;
      The_Class : in RTEMS.Unsigned32;
      Info      : out API_Class_Information;
      Result    : out RTEMS.Status_Codes)
   is
      function Get_Class_Information_Base
        (The_API   : RTEMS.Unsigned32;
         The_Class : RTEMS.Unsigned32;
         Info      : access API_Class_Information)
         return      RTEMS.Status_Codes;
      pragma Import
        (C,
         Get_Class_Information_Base,
         "rtems_object_get_class_information");
      TmpInfo : aliased API_Class_Information;
   begin
      Result :=
         Get_Class_Information_Base
           (The_API,
            The_Class,
            TmpInfo'Access);
      Info   := TmpInfo;
   end Get_Class_Information;

end RTEMS.Object;