blob: c184cd7f0b23fa93807ae21821e8e9d86cc01c1f [file] [log] [blame]
Zakir Meer9f251f52018-06-17 16:21:31 +02001package templates
2
3import com.inchron.realtime.root.model.GenericSystem
4import com.inchron.realtime.root.model.Model
5import com.inchron.realtime.root.model.SchedulerStrategy
6import org.eclipse.app4mc.amalthea.model.Amalthea
7import org.eclipse.app4mc.amalthea.model.FixedPriorityPreemptive
8import org.eclipse.app4mc.amalthea.model.HwStructure
9import org.eclipse.app4mc.amalthea.model.MappingModel
10import org.eclipse.app4mc.amalthea.model.OSEK
11import org.eclipse.app4mc.amalthea.model.SchedulerAssociation
12import org.eclipse.app4mc.amalthea.model.Semaphore
13import org.eclipse.app4mc.amalthea.model.StructureType
14import org.eclipse.app4mc.amalthea.model.TaskScheduler
15import templates.utils.AmltCacheModel
16
17/**
18 * This class is responsible for the transformation of AMALTHEA OS Model into corresponding INCHRON mdoel elements and accordingly invoke other transformations
19 */
20public class OSTransformer extends AbstractAmaltheaInchronTransformer {
21
22 /**
23 * Creating Inchron GenericSystem from HwStructure of type MicroController in Amalthea
24 */
25 def create inchronModelFactory.createGenericSystem createGenericSystem(HwStructure microController) {
26 it.name = "System_" + microController.name
27 }
28
29 /**
30 * Populating Inchron GenericSystem contents based on the Amalthea model data
31 */
32 public def void fillGenericSystem(GenericSystem genericSystem, Amalthea amalthea, Model inchronModel) {
33
34 val AmltCacheModel cacheModel=customObjsStore.getInstance(AmltCacheModel)
35
36 /*-Creating RtosConfig element and associating it to the GenericSystem */
37
38 var inchronRtosConfig = inchronModelFactory.createRtosConfig
39
40 genericSystem.rtosConfig = inchronRtosConfig
41
42 /*-Fetching contents of Amalthea OS model */
43 if (amalthea.osModel != null) {
44
45 /*-Fetching all Amalthea Semaphore elements and creating corresponding Inchron elements */
46
47 for (Semaphore amltSemaphore : amalthea.osModel.semaphores) {
48
49 val inchronSemaphore = createSemaphore(amltSemaphore)
50
51 /*-Caching Inchron Semaphore object */
52
53 cacheModel.cacheInchronSemaphore(inchronSemaphore)
54
55 /*- Adding Semaphore to RtosConfig object*/
56
57 genericSystem.rtosConfig.semaphores.add(inchronSemaphore)
58 }
59 }
60
61 /*-Fetching Amalthea Tasks objects from SwModel and invoking the StimuliTransformer to build corresponding Inchron objects */
62
63 if(amalthea.swModel!=null){
64
65 stimuliTransformerInstance.createInchronActivationConnections(amalthea.swModel.tasks ,inchronModel )
66
67 }
68
69
70 // heuristic for Inchron
71
72 /*-Creating Dummy Inchron Scheduler */
73
74 val dummyISRScheduler = inchronModelFactory.createScheduler
75
76 /*-Adding Dummy scheduler to RtosConfig element of Inchron */
77
78 genericSystem.rtosConfig.schedulables.add(dummyISRScheduler)
79
80 val MappingModel amltMappingModel = amalthea.mappingModel
81
82 if (amltMappingModel != null) {
83
84 /*-Building cache for TaskScheduler <---> and SchedulerAssociation's */
85
86 cacheModel.buildTaskSchedulerAndSchedulerAssociationMap(amltMappingModel)
87
88 /*-Building cache for TaskScheduler <---> and TaskAllocation's */
89
90 cacheModel.buildTaskSchedulerAndTaskAllocationMap(amltMappingModel)
91
92 /*- Collecting all the root TaskScheduler's */
93
94 val rootTaskSchedulers = amltMappingModel?.schedulerAllocation?.map [ amltSchedulerAllocation |
95
96 if (amltSchedulerAllocation.scheduler instanceof TaskScheduler) {
97 return (amltSchedulerAllocation.scheduler as TaskScheduler).rootScheduler
98 }
99
100 ].toSet.filter[it != null]
101
102 /*-Case 1: Fetching all the Amalthea SchedulerAllocation objects from Amalthea */
103
104 amltMappingModel?.schedulerAllocation?.forEach [ amltSchAllocation |
105
106 /*- Considering only if the associated scheduler is TaskScheduler */
107
108 if (amltSchAllocation.scheduler instanceof TaskScheduler) {
109
110 /*- getting Root scheduler */
111 var rootScheduler = getRootScheduler(amltSchAllocation.scheduler as TaskScheduler)
112
113 /*- gettting the ProcessingUnit from the responsibility of SchedulerAllocation*/
114
115 if (amltSchAllocation?.responsibility.size > 0) {
116
117 /*- Based on the Amalthea model, eContainer of ProcessingUnit is HwStructure of type MicroController */
118
119 var amltMicroController = amltSchAllocation?.responsibility?.get(0)?.eContainer
120
121 if ((amltMicroController != null) && (amltMicroController instanceof HwStructure) && (amltMicroController as HwStructure).structureType==StructureType.MICROCONTROLLER ){
122
123 /*- Based on the extend behaviour, if create method is invoked - with the same parameters again and again -> it does caching and returns back the already created object from cache */
124
125 var inchronCpu = HWTransformerInstance.createCpu(amltMicroController as HwStructure)
126
127 if (inchronCpu != null) {
128
129 if(inchronCpu.eContainer==null){
130 inchronModel.cpus.add(inchronCpu)
131 }
132
133 }
134
135 /*-Adding the root scheduler to dummy ISR Scheduler */
136
137 dummyISRScheduler.schedulables.add(OSTransformerInstance.createRootScheduler(rootScheduler))
138 }
139
140 } else {
141 logger.info(amltSchAllocation + " " + amltSchAllocation.scheduler)
142 }
143
144 }
145 ]
146
147 /*-Case 2: Fetching all the Amalthea ISRAllocation objects from Amalthea */
148
149 amltMappingModel?.isrAllocation?.forEach [ amltISRAllocation |
150
151 var amltISR = amltISRAllocation.isr
152
153 /*-Fetching InterruptController from ISRAllocation element */
154
155 var amltInterruptController = amltISRAllocation.controller
156
157 if (amltInterruptController != null) {
158
159 var AmltCacheModel amltCacheModel = customObjsStore.getInstance(AmltCacheModel)
160
161 //TODO: Clarify this .. why to get SchedulerAllocation again when ISRAllocation is already present
162 var amltSchedulerAllocation = amltCacheModel.taskScheduler_SchedulerAllocationMap.get(
163 amltInterruptController)
164
165 if (amltSchedulerAllocation != null) {
166
167 if (amltSchedulerAllocation.executingPU != null) {
168
169 /*-get executing Core from SchedulerAllocation */
170 var amltExecutingCore = amltSchedulerAllocation.executingPU
171
172 if(amltExecutingCore!=null){
173 val amltMicroController= amltExecutingCore.eContainer
174
175 // RootISRScheduler should be unique for each MicroController
176 val inchronRootISRScheduler = OSTransformerInstance.createRootISRScheduler(
177 amltMicroController as HwStructure)
178
179 /*-creating inchron Cpu element from the MicroController element in Amalthea model*/
180 var inchronCpu = HWTransformerInstance.createCpu(
181 amltExecutingCore.eContainer as HwStructure)
182
183 /*-Below check is made, if Inchron CPU object is already associated to Inchron model !! If not associating it explicitly */
184 if(inchronCpu.eContainer==null){
185 inchronModel.cpus.add(inchronCpu)
186 }
187
188 // TODO: clarify if Inchron root ISRScheduler can be added in HyperVisorConfig - vmSchedulers list
189 dummyISRScheduler.schedulables.add(inchronRootISRScheduler)
190
191 var inchronCpuCore = HWTransformerInstance.createCpuCore(
192 amltExecutingCore)
193
194 /*-Below check is made, if Inchron CpuCore object is already associated to Inchron Cpu !! If not associating it explicitly */
195
196 if(inchronCpuCore.eContainer==null){
197 inchronCpu.cores.add(inchronCpuCore)
198 }
199
200 /*- Creating a Process from ISR */
201 var inchronProcess = SWTransformerInstance.createProcess(amltISR)
202
203 // setting the priority from amlt ISRAllocation
204 inchronProcess.priority = amltISRAllocation.priority
205
206 /*-Associating CpuCore to Process */
207 inchronProcess.cpuCores.add(inchronCpuCore)
208
209 // adding all the amlt ISR's as Processes to root ISR scheduler
210 inchronRootISRScheduler.schedulables.add(inchronProcess)
211 }
212
213 }
214
215 }
216 }
217 ]
218
219 }
220
221
222
223 }
224
225
226/**
227 * This method is used to create a Inchron Semaphore object from Amalthea Semaphore
228 */
229 public def create inchronModelFactory.createSemaphore createSemaphore(Semaphore amltSemaphore) {
230 it.initialValue = amltSemaphore.initialValue;
231 it.maxValue = amltSemaphore.maxValue;
232 it.name = amltSemaphore.name;
233 }
234
235 /**
236 * This method is used to return the root TaskScheduler object
237 */
238 def TaskScheduler getRootScheduler(TaskScheduler sch) {
239
240 if (sch.parentScheduler == null) {
241 return sch
242 }
243 return getRootScheduler(sch.parentScheduler)
244 }
245
246/**
247 * This method is used to create a Root ISR Scheduler object from Amalthea HwStructure (of type MicroController)
248 */
249 public def create inchronModelFactory.createScheduler createRootISRScheduler(HwStructure amltMicroController) {
250 it.name = "Root-ISR" + "_" + amltMicroController.name
251 }
252
253/**
254 * This method is used to create Inchron Root Scheduler object from Amalthea TaskScheduler
255 * <br>
256 * Additional things performed in this method are :
257 * <br>1. creation of child Schedulers for corresponding childAssociations to Amalthea Scheduler
258 * <br>2. Processing through TaskAllocations of a Amalthea scheduler and creating Inchron Process element
259 * <br>3. Processing through SchedulerAssociations of a Amalthea scheduler and creating Inchron CpuCore elements.. and associating them to the the Scheduler object
260 *
261 */
262
263 public def create inchronModelFactory.createScheduler createRootScheduler(TaskScheduler amltTaskScheduler) {
264
265 it.name = amltTaskScheduler.name
266
267 var amltSchedulingAlgorithm = amltTaskScheduler.schedulingAlgorithm
268
269 if (amltSchedulingAlgorithm instanceof FixedPriorityPreemptive) {
270 it.strategy = SchedulerStrategy.FIXED_PRIORITY
271 }
272 if (amltSchedulingAlgorithm instanceof OSEK) {
273 it.strategy = SchedulerStrategy.OSEK
274 }
275
276 /* ============ building Inchron child Scheduler elements ======================== */
277
278 amltTaskScheduler.childAssociations.forEach [ amltChildSchedulerAssociation |
279
280 if (amltChildSchedulerAssociation.child instanceof TaskScheduler) {
281 var amltSchedulingParameters = amltChildSchedulerAssociation.schedulingParameters
282
283 var amltSubSchedulerPrio = 0
284
285 if (amltSchedulingParameters != null) {
286 amltSubSchedulerPrio = amltSchedulingParameters.priority
287 }
288 schedulables.add(
289 createScheduler(amltChildSchedulerAssociation.child as TaskScheduler, amltSubSchedulerPrio))
290
291 }
292
293 ]
294
295 /* ============ building Inchron Process elements and associating to the Scheduler object ======================== */
296
297 var AmltCacheModel amltCacheModel = customObjsStore.getInstance(AmltCacheModel)
298
299 //fetching all TaskAllocations associated to a specific TaskScheduler
300 var taskAllocations = amltCacheModel.taskScheduler_TaskAllocationMap.get(amltTaskScheduler)
301
302 if (taskAllocations != null) {
303 taskAllocations.forEach [ amltTaskAllocation |
304
305 var process = SWTransformerInstance.createProcess(amltTaskAllocation.task)
306 // adding a created process inside the schedulables list of inchron scheduler
307 it.schedulables.add(process)
308
309 if (amltTaskAllocation?.schedulingParameters != null) {
310 process.priority = amltTaskAllocation?.schedulingParameters?.priority
311
312 }
313 ]
314 }
315 /* ============ building Inchron CpuCore elements and associating to the Scheduler object ======================== */
316
317 var amltSchedulerAllocation = amltCacheModel.getTaskScheduler_SchedulerAllocationMap.get(amltTaskScheduler)
318
319 if (amltSchedulerAllocation != null) {
320
321 amltSchedulerAllocation.responsibility.forEach [ amltcore |
322 // associating CpuCore to HyperVisorSystemSchedulable
323 it.cpuCores.add(HWTransformerInstance.createCpuCore(amltcore))
324 ]
325 }
326
327 }
328
329 @Deprecated
330 public def create inchronModelFactory.createScheduler createSubScheduler(
331 SchedulerAssociation amltSchedulerAssociation) {
332
333 // TODO: create virtual system (use ARSystem instead of OSEK System), create coreMappings, schedulingParameters
334 var amltChildScheduler = amltSchedulerAssociation.child
335
336 // get the appropriate SchedulerAssociation to identify on which Core this scheduler is mapped
337 var AmltCacheModel cacheModel = customObjsStore.getInstance(AmltCacheModel)
338
339 var amltChildSchedulerAllocation = cacheModel.getTaskScheduler_SchedulerAllocationMap.get(amltChildScheduler)
340
341 if (amltChildSchedulerAllocation != null) {
342
343 name = amltChildSchedulerAllocation.scheduler?.name
344
345 amltChildSchedulerAllocation.responsibility.forEach [ amltcore |
346 // associating CpuCore to HyperVisorSystemSchedulable
347 it.cpuCores.add(HWTransformerInstance.createCpuCore(amltcore))
348 ]
349 }
350
351 }
352
353/**
354 * This method is used to create Inchron Scheduler object from Amalthea TaskScheduler
355 * <br>
356 * Additional things performed in this method are :
357 * <br>1. creation of child Schedulers for corresponding childAssociations to Amalthea Scheduler
358 * <br>2. Processing through TaskAllocations of a Amalthea scheduler and creating Inchron Process element
359 * <br>3. Processing through SchedulerAssociations of a Amalthea scheduler and creating Inchron CpuCore elements.. and associating them to the the Scheduler object
360 *
361 */
362 public def create inchronModelFactory.createScheduler createScheduler(TaskScheduler amltTaskScheduler,
363 int priority) {
364 it.name = amltTaskScheduler.name
365
366 it.priority = priority
367
368 var amltSchedulingAlgorithm = amltTaskScheduler.schedulingAlgorithm
369
370 //TODO: Mostly the same for the root -- point for harmonization?
371
372 if (amltSchedulingAlgorithm instanceof FixedPriorityPreemptive) {
373 it.strategy = SchedulerStrategy.FIXED_PRIORITY
374 }
375 if (amltSchedulingAlgorithm instanceof OSEK) {
376 it.strategy = SchedulerStrategy.OSEK
377 }
378
379 /* ============ building Inchron child Scheduler elements ======================== */
380
381 // TODO: add if conditions for all the sub classes of TaskSchedulingAlgorithm
382 amltTaskScheduler.childAssociations.forEach [ amltChildAssociation |
383
384 if (amltChildAssociation.child instanceof TaskScheduler) {
385 var amltSchedulingParameters = amltChildAssociation.schedulingParameters
386
387 var amltSubSchedulerPrio = 0
388
389 if (amltSchedulingParameters != null) {
390 amltSubSchedulerPrio = amltSchedulingParameters.priority
391 }
392 it.schedulables.add(createScheduler(amltChildAssociation.child as TaskScheduler, amltSubSchedulerPrio))
393
394 }
395
396 ]
397
398
399 /* ============ building Inchron Process elements and associating to the Scheduler object ======================== */
400
401
402 var AmltCacheModel amltCacheModel = customObjsStore.getInstance(AmltCacheModel)
403
404 // fetching all TaskAllocations associated to a specific TaskScheduler
405 var taskAllocations = amltCacheModel.taskScheduler_TaskAllocationMap.get(amltTaskScheduler)
406
407 if (taskAllocations != null) {
408 taskAllocations.forEach [ amltTaskAllocation |
409
410 var process = SWTransformerInstance.createProcess(amltTaskAllocation.task)
411 // adding a created process inside the schedulables list of inchron scheduler
412 it.schedulables.add(process)
413
414 if (amltTaskAllocation?.schedulingParameters != null) {
415 process.priority = amltTaskAllocation?.schedulingParameters?.priority
416
417 }
418 ]
419 }
420
421 /* ============ building Inchron CpuCore elements and associating to the Scheduler object ======================== */
422
423 var amltChildSchedulerAllocation = amltCacheModel.getTaskScheduler_SchedulerAllocationMap.get(amltTaskScheduler)
424
425 if (amltChildSchedulerAllocation != null) {
426
427 name = amltChildSchedulerAllocation.scheduler?.name
428
429 amltChildSchedulerAllocation.responsibility.forEach [ amltcore |
430 // associating CpuCore to HyperVisorSystemSchedulable
431 it.cpuCores.add(HWTransformerInstance.createCpuCore(amltcore))
432 ]
433 }
434 }
435
436}