ocarina-backends-air_conf-air_configuration.adb 13.8 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--               OCARINA.BACKENDS.AIR_CONF.AIR_CONFIGURATION                --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--                   Copyright (C) 2018-2019 ESA & ISAE.                    --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. Ocarina is distributed in the hope that it will be useful, but     --
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
--                                                                          --
------------------------------------------------------------------------------

yoogx's avatar
yoogx committed
32
with Utils;         use Utils;
33
34
35
with Ocarina.Namet; use Ocarina.Namet;

with Ocarina.ME_AADL;
yoogx's avatar
yoogx committed
36

37
with Ocarina.ME_AADL.AADL_Instances.Entities;
yoogx's avatar
yoogx committed
38
39
40
41
42
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;

with Ocarina.Backends.Properties;
with Ocarina.Backends.Properties.ARINC653;
43
44
45
46

with Ocarina.Backends.Utils;
with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
yoogx's avatar
yoogx committed
47
with Ocarina.Backends.XML_Values;
48
with Ocarina.Backends.C_Common.Mapping;
49
50
51
52
53
54
55

package body Ocarina.Backends.AIR_Conf.AIR_Configuration is

   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;

yoogx's avatar
yoogx committed
56
57
   use Ocarina.Backends.Properties;
   use Ocarina.Backends.Properties.ARINC653;
58
59
   use Ocarina.Backends.Utils;
   use Ocarina.Backends.XML_Tree.Nutils;
60
   use Ocarina.Backends.C_Common.Mapping;
61

yoogx's avatar
yoogx committed
62
63
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
64
   package XTN renames Ocarina.Backends.XML_Tree.Nodes;
yoogx's avatar
yoogx committed
65
66
   package XTU renames Ocarina.Backends.XML_Tree.Nutils;
   package XV renames Ocarina.Backends.XML_Values;
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

   procedure Visit_Architecture_Instance (E : Node_Id);
   procedure Visit_Component_Instance (E : Node_Id);
   procedure Visit_System_Instance (E : Node_Id);
   procedure Visit_Processor_Instance (E : Node_Id);
   procedure Visit_Subcomponents_Of is new Visit_Subcomponents_Of_G (Visit);

   -----------
   -- Visit --
   -----------

   procedure Visit (E : Node_Id) is
   begin
      case Kind (E) is
         when K_Architecture_Instance =>
            Visit_Architecture_Instance (E);

         when K_Component_Instance =>
            Visit_Component_Instance (E);

         when others =>
            null;
      end case;
   end Visit;

   ---------------------------------
   -- Visit_Architecture_Instance --
   ---------------------------------

   procedure Visit_Architecture_Instance (E : Node_Id) is
   begin
      Visit (Root_System (E));
   end Visit_Architecture_Instance;

   ------------------------------
   -- Visit_Component_Instance --
   ------------------------------

   procedure Visit_Component_Instance (E : Node_Id) is
      Category : constant Component_Category := Get_Category_Of_Component (E);
   begin
      case Category is
         when CC_System =>
            Visit_System_Instance (E);

         when CC_Processor =>
            Visit_Processor_Instance (E);

         when others =>
            null;
      end case;
   end Visit_Component_Instance;

yoogx's avatar
yoogx committed
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
   --------------------------
   -- Map_Connection_Table --
   --------------------------

   procedure Map_Connection_Table (E : Node_Id)
     with Pre => (Get_Category_Of_Component (E) = CC_System);

   procedure Map_Connection_Table (E : Node_Id) is
      Channel_Identifier : Unsigned_Long_Long := 0;
      C                     : Node_Id;
      P                     : Node_Id;
      Q                     : Node_Id;
      Source_Port_Name      : Name_Id;
      Destination_Port_Name : Name_Id;
      Destination_Partition : Node_Id;
      Source_Partition      : Node_Id;
      Connection_Table_Node : Node_Id;
      Channel_Node          : Node_Id;
      Source_Node           : Node_Id;
      Destination_Node      : Node_Id;
      Standard_Partition_Node : Node_Id;

   begin
      if not AINU.Is_Empty (Connections (E)) then

         Append_Node_To_List
           (Make_XML_Comment (Get_String_Name ("Connection Table")),
            XTN.Subitems (Current_XML_Node));

         Connection_Table_Node := Make_XML_Node ("Connection_Table");

         C := First_Node (Connections (E));
         while Present (C) loop

            if Kind (C) = K_Connection_Instance then
               Source_Port_Name :=
156
157
158
159
160
                 Map_C_Enumerator_Name
                 (AIN.Item
                    (AIN.Next_Node
                       (AIN.First_Node (AIN.Path (AIN.Source (C))))),
                  Fully_Qualify_Parent => True);
yoogx's avatar
yoogx committed
161
162

               Destination_Port_Name :=
163
164
165
166
167
168
                 Map_C_Enumerator_Name
                 (AIN.Item
                    (AIN.Next_Node
                       (AIN.First_Node
                          (AIN.Path (AIN.Destination (C))))),
                  Fully_Qualify_Parent => True);
yoogx's avatar
yoogx committed
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

               Source_Partition :=
                 AIN.Corresponding_Instance
                   (AIN.Item (AIN.First_Node (AIN.Path (AIN.Source (C)))));

               Destination_Partition :=
                 AIN.Corresponding_Instance
                   (AIN.Item
                      (AIN.First_Node (AIN.Path (AIN.Destination (C)))));

               --  Channel node

               Channel_Node := Make_XML_Node ("Channel");
               Append_Node_To_List
                 (Channel_Node,
                  XTN.Subitems (Connection_Table_Node));

               --  Channel identifier

               Set_Str_To_Name_Buffer ("ChannelIdentifier");
               P := Make_Defining_Identifier (Name_Find);
               Set_Str_To_Name_Buffer ("");
               Add_ULL_To_Name_Buffer (Channel_Identifier, 10);
               Q := Make_Defining_Identifier (Remove_Char (Name_Find, ' '));

               Append_Node_To_List (Make_Assignement (P, Q),
                                    XTN.Items (Channel_Node));
               Channel_Identifier := Channel_Identifier + 1;

               --  Channel name

               XTU.Add_Attribute ("ChannelName",
                                  Get_Name_String
                                    (To_Lower
                                       (Display_Name
                                          (Identifier (C)))), Channel_Node);

               --  Mapping of the source

               Source_Node := Make_XML_Node ("Source");
               Append_Node_To_List (Source_Node, XTN.Subitems (Channel_Node));

               Standard_Partition_Node := Make_XML_Node ("Standard_Partition");
               Append_Node_To_List (Standard_Partition_Node,
                                    XTN.Subitems (Source_Node));

               Set_Str_To_Name_Buffer ("PartitionIdentifier");
               P := Make_Defining_Identifier (Name_Find);
               Q :=
                 Make_Literal
                   (XV.New_Numeric_Value
                      (Get_Partition_Identifier
                         (Get_Bound_Processor (Source_Partition)),
                       0,
                       10));
               Append_Node_To_List
                 (Make_Assignement (P, Q),
                  XTN.Items (Standard_Partition_Node));

               Set_Str_To_Name_Buffer ("PartitionName");
               P := Make_Defining_Identifier (Name_Find);
               Get_Name_String
                 (To_Lower
                    (Display_Name
                       (Identifier
                          (Parent_Subcomponent (Source_Partition)))));
               Q := Make_Defining_Identifier (Name_Find);
               Append_Node_To_List
                 (Make_Assignement (P, Q),
                  XTN.Items (Standard_Partition_Node));

               Set_Str_To_Name_Buffer ("PortName");
               P := Make_Defining_Identifier (Name_Find);
               Get_Name_String (Source_Port_Name);
               Q := Make_Defining_Identifier (Name_Find);
               Append_Node_To_List
                 (Make_Assignement (P, Q),
                  XTN.Items (Standard_Partition_Node));

               --  Mapping of the destination

               Destination_Node := Make_XML_Node ("Destination");
               Append_Node_To_List
                 (Destination_Node,
                  XTN.Subitems (Channel_Node));

               Standard_Partition_Node := Make_XML_Node ("Standard_Partition");
               Append_Node_To_List (Standard_Partition_Node,
                                    XTN.Subitems (Destination_Node));

               Set_Str_To_Name_Buffer ("PartitionIdentifier");
               P := Make_Defining_Identifier (Name_Find);
               Q :=
                 Make_Literal
                   (XV.New_Numeric_Value
                      (Get_Partition_Identifier
                         (Get_Bound_Processor
                         (Destination_Partition)),
                       0,
                       10));
               Append_Node_To_List
                 (Make_Assignement (P, Q),
                  XTN.Items (Standard_Partition_Node));

               Set_Str_To_Name_Buffer ("PartitionName");
               P := Make_Defining_Identifier (Name_Find);
               Get_Name_String
                 (To_Lower
                    (Display_Name
                       (Identifier
                          (Parent_Subcomponent (Destination_Partition)))));
               Q := Make_Defining_Identifier (Name_Find);
               Append_Node_To_List
                 (Make_Assignement (P, Q),
                  XTN.Items (Standard_Partition_Node));

               Set_Str_To_Name_Buffer ("PortName");
               P := Make_Defining_Identifier (Name_Find);
               Get_Name_String (Destination_Port_Name);
               Q := Make_Defining_Identifier (Name_Find);
               Append_Node_To_List
                 (Make_Assignement (P, Q),
                  XTN.Items (Standard_Partition_Node));
            end if;

            C := Next_Node (C);
         end loop;

         Append_Node_To_List (Connection_Table_Node,
                              XTN.Subitems (Current_XML_Node));
      end if;
   end Map_Connection_Table;

302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
   ---------------------------
   -- Visit_System_Instance --
   ---------------------------

   procedure Visit_System_Instance (E : Node_Id) is
      U : Node_Id;
      R : Node_Id;
   begin
      U := XTN.Unit (Backend_Node (Identifier (E)));
      R := XTN.Node (Backend_Node (Identifier (E)));

      Current_XML_Node := XTN.Root_Node (XTN.XML_File (U));

      Push_Entity (U);
      Push_Entity (R);

yoogx's avatar
yoogx committed
318
      Map_Connection_Table (E);
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
      Visit_Subcomponents_Of (E);

      Pop_Entity;
      Pop_Entity;
   end Visit_System_Instance;

   procedure Map_AIR_Configuration_Node (E : Node_Id)
     with Pre => (Get_Category_Of_Component (E) = CC_Processor);

   --------------------------------
   -- Map_AIR_Configuration_Node --
   --------------------------------

   procedure Map_AIR_Configuration_Node (E : Node_Id) is
      AIR_Configuration_Node : Node_Id;
      P : Node_Id;
      Q : Node_Id;
   begin

      Append_Node_To_List
        (Make_XML_Comment (Get_String_Name ("Module configuration")),
         XTN.Subitems (Current_XML_Node));

      --  Create the AIR_Configuration node

      AIR_Configuration_Node := Make_XML_Node ("AIR_Configuration");

      Set_Str_To_Name_Buffer ("TicksPerSecond");
      P := Make_Defining_Identifier (Name_Find);
      Set_Str_To_Name_Buffer ("200"); --  XXX Hardcoded ?
      Q := Make_Defining_Identifier (Name_Find);

      Append_Node_To_List
        (Make_Assignement (P, Q),
         XTN.Items (AIR_Configuration_Node));

      Set_Str_To_Name_Buffer ("RequiredCores");
      P := Make_Defining_Identifier (Name_Find);
357
358
      Q := Make_Literal
        (XV.New_Numeric_Value (Get_Number_Of_Cores (E), 0, 10));
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

      Append_Node_To_List
        (Make_Assignement (P, Q),
         XTN.Items (AIR_Configuration_Node));

      Append_Node_To_List
        (AIR_Configuration_Node,
         XTN.Subitems (Current_XML_Node));

   end Map_AIR_Configuration_Node;

   ------------------------------
   -- Visit_Processor_Instance --
   ------------------------------

   procedure Visit_Processor_Instance (E : Node_Id) is
   begin
      Map_Air_Configuration_Node (E);
      Visit_Subcomponents_Of (E);
   end Visit_Processor_Instance;

end Ocarina.Backends.AIR_Conf.AIR_Configuration;